Futility_Configurations.cmake 14.4 KB
Newer Older
1
2
3
4
5
6
7
8
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
#                          Futility Development Group                          !
#                             All rights reserved.                             !
#                                                                              !
# Futility is a jointly-maintained, open-source project between the University !
# of Michigan and Oak Ridge National Laboratory.  The copyright and license    !
# can be found in LICENSE.txt in the head directory of this repository.        !
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
9
INCLUDE(${Futility_SOURCE_DIR}/cmake/CheckMPIF2008StandardCompiles.cmake)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
IF(${PROJECT_NAME}_VERBOSE_CONFIGURE)
    MESSAGE("Configuring Futility compiler options for:")
    PRINT_VAR(PACKAGE_NAME)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_TESTS)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_DBLREAL)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_DBLINT)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_MPI)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_PETSC)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_SLEPC)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_HDF5)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_MKL)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_PARDISO)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_BLAS)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_OpenMP)
24
25
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_CUDA)
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_Kokkos)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    PRINT_VAR(${PACKAGE_NAME}_ENABLE_PAPI)
    PRINT_VAR(${PROJECT_NAME}_BUILD_STANDARD)
    PRINT_VAR(${PROJECT_NAME}_DISABLE_PURE)
ENDIF()

IF(NOT DEFINED ${PROJECT_NAME}_FPE_TRAP)
   SET(${PROJECT_NAME}_FPE_TRAP FALSE)
ENDIF()
IF(NOT DEFINED ${PROJECT_NAME}_BUILD_STANDARD)
   GLOBAL_SET(${PROJECT_NAME}_BUILD_STANDARD TRUE)
ENDIF()

# Define known configuration types for Futility
SET(CONFIG_TYPES
    DEBUG
    RELEASE
42
    RELWITHDEBINFO
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
   )

# Set Default configuration for Futility
LIST(GET CONFIG_TYPES 0 ${PACKAGE_NAME}_BUILD_TYPE)

# Determine if Project configuration is supported by Futility and override default.
FOREACH(ctyp ${CONFIG_TYPES})
    IF("${CMAKE_BUILD_TYPE}" STREQUAL "${ctyp}")
        SET(${PACKAGE_NAME}_BUILD_TYPE
            ${CMAKE_BUILD_TYPE}
           )
    ENDIF()
ENDFOREACH()

# Determine symbol for command line compiler option
IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
    SET(CSYM "/")
ELSE()
    SET(CSYM "-")
ENDIF()

# Preprocessor definition if Windows
IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} WIN32)
ENDIF()

COLLINSBS email's avatar
COLLINSBS email committed
69
70
71
72
IF(${PROJECT_NAME}_ENABLE_DBC)
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} FUTILITY_DBC)
ENDIF()

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Preprocessor symbol for tests
IF(${PACKAGE_NAME}_ENABLE_TESTS)
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} UNIT_TEST)
ENDIF()

# Preprocessor symbol for colored outputs
IF(${PROJECT_NAME}_COLOR_LINUX)
    MESSAGE("Enabling colored output for linux")
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} COLOR_LINUX)
ENDIF()
IF(${PROJECT_NAME}_COLOR_WIN32)
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} COLOR_WIN32)
ENDIF()

# Other Futility preprocessor symbols
IF(${PACKAGE_NAME}_ENABLE_DBLREAL)
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} DBL)
ENDIF()
IF(${PACKAGE_NAME}_ENABLE_DBLINT)
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} DBLINT)
ENDIF()

# Disable PURE and ELEMENTAL
IF(${PROJECT_NAME}_DISABLE_PURE)
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} PURE=)
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} ELEMENTAL=)
ENDIF()

# Preprocessor symbol for using memory profile
IF(${PROJECT_NAME}_ENABLE_MEMPROF)
103
    SET(${PACKAGE_NAME}_DEFINES ${${PACKAGE_NAME}_DEFINES} FUTILITY_MEMPROF)
104
105
106
107
108
109
110
111
112
ENDIF()

# OpenMP Compiler flag (like a TPL)
IF(${PACKAGE_NAME}_ENABLE_OpenMP AND DEFINED OpenMP_C_FLAGS)
    SET(OpenMP_Fortran_FLAGS ${OpenMP_C_FLAGS})
ENDIF()

# Check if MPI supports Fortran 2003 standard
IF(${PROJECT_NAME}_BUILD_STANDARD)
113
114
115
116
    CHECK_MPI_F2008_STANDARD_COMPILES()
    IF(${PROJECT_NAME}_BUILD_STANDARD AND NOT MPI_F2008_STANDARD_COMPLIANT)
        MESSAGE(STATUS "Disabling F2008 Standard since MPI install is not F2008 compliant")
        GLOBAL_SET(${PROJECT_NAME}_BUILD_STANDARD ${MPI_F2008_STANDARD_COMPLIANT})
117
118
119
    ENDIF()
ELSE()
    IF(${PACKAGE_NAME} STREQUAL "Futility")
120
        MESSAGE(STATUS "Project has disabled F2008 standard compilation")
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    ENDIF()
ENDIF()

# Override the CMAKE default Fortran flags (cause they're stupid)
# Done for each supported compiler
IF(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" OR
   (MSVC_IDE AND "${CMAKE_Fortran_COMPILER}" STREQUAL "ifort"))

    IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
        SET(s ":")

        #Overwrite OpenMP flag (cause Intel is stupi--special)
        IF(DEFINED OpenMP_Fortran_FLAGS)
          SET(OpenMP_Fortran_FLAGS ${CSYM}Qopenmp)
        ENDIF()
    ELSE()
        SET(s " ")
    ENDIF()

    SET(Fortran_FLAGS
        ${CSYM}nologo
        ${CSYM}fpp
        ${CSYM}threads
       )
    IF(${PROJECT_NAME}_BUILD_STANDARD)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
148
            ${CSYM}stand${s}f08
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
           )
    ENDIF()

    IF(${PROJECT_NAME}_FPE_TRAP)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}fpe-all${s}0
           )
    ENDIF()

    IF(${PROJECT_NAME}_SUPPRESS_WARNINGS)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}w
        )
    ENDIF()

    IF(BUILD_SHARED_LIBS AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}fpic
        )
    ENDIF()

    IF(BUILD_SHARED_LIBS AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
        MESSAGE(STATUS "Shared libraries not supported in windows.")
        SET(Fortran_FLAGS ${Fortran_FLAGS} ${CSYM}libs:static)
        SET(BUILD_SHARED_LIBS FALSE)
    ENDIF()


    SET(Fortran_FLAGS_DEBUG
        ${CSYM}debug${s}full
        ${CSYM}debug-parameters${s}all
        ${CSYM}warn${s}all
        ${CSYM}check${s}all
        ${CSYM}traceback
       )
    IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
        SET(Fortran_FLAGS_DEBUG ${Fortran_FLAGS_DEBUG}
            ${CSYM}Od ${CSYM}dbglibs)
    ENDIF()

    SET(Fortran_FLAGS_RELEASE
        ${CSYM}O3
        ${CSYM}Os
       )

197
198
199
200
201
202
203
    SET(Fortran_FLAGS_RELWITHDEBINFO
        ${CSYM}O3
        ${CSYM}Os
        ${CSYM}debug${s}full
        ${CSYM}check${s}all
       )

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    IF(${PACKAGE_NAME}_ENABLE_MKL)
        IF(DEFINED OpenMP_Fortran_FLAGS)
            SET(mkllib parallel)
        ELSEIF(${PACKAGE_NAME}_ENABLE_MPI)
            SET(mkllib cluster)
        ELSE()
            SET(mkllib sequential)
        ENDIF()
        IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
            SET(Fortran_FLAGS ${Fortran_FLAGS} ${CSYM}Qmkl:${mkllib})
        ELSE()
            SET(Fortran_FLAGS ${Fortran_FLAGS} ${CSYM}mkl=${mkllib})
        ENDIF()
        UNSET(mkllib)
    ENDIF()

    IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
        SET(Fortran_FLAGS_RELEASE ${Fortran_FLAGS_RELEASE}
            ${CSYM}QxHost ${CSYM}inline:speed)
223
224
        SET(Fortran_FLAGS_RELWITHDEBINFO ${Fortran_FLAGS_RELWITHDEBINFO}
            ${CSYM}QxHost ${CSYM}inline:speed)
225
226
227
    ELSE()
        SET(Fortran_FLAGS_RELEASE ${Fortran_FLAGS_RELEASE}
            ${CSYM}inline-level=2)
228
229
        SET(Fortran_FLAGS_RELWITHDEBINFO ${Fortran_FLAGS_RELWITHDEBINFO}
            ${CSYM}inline-level=2)
230
231
232
233
234
    ENDIF()
ELSEIF(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
    SET(Fortran_FLAGS
        ${CSYM}cpp
        ${CSYM}fall-intrinsics
COLLINSBS email's avatar
COLLINSBS email committed
235
        ${CSYM}ffree-line-length-none
236
237
238
239
240
241
242
243
244
       )

    SET(C_FLAGS
        ${CSYM}lm
       )

    IF(${PROJECT_NAME}_BUILD_STANDARD)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
245
            ${CSYM}std=f2008
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
           )
    ENDIF()

    IF(${PROJECT_NAME}_FPE_TRAP)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}ffpe-trap=invalid,zero,overflow,underflow,denormal
           )
    ENDIF()

    IF(${PROJECT_NAME}_SUPPRESS_WARNINGS)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}w
           )
    ENDIF()

    IF(BUILD_SHARED_LIBS)
        SET(Fortan_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}fPIC
           )
    ELSE()
        SET(Fotran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}static-libgfortran
        )
    ENDIF()

    IF(${PROJECT_NAME}_GPROF)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}pg
           )
    ENDIF()

    SET(Fortran_FLAGS_DEBUG
283
284
        ${CSYM}Og
        ${CSYM}g
285
        ${CSYM}Wall
286
287
        ${CSYM}Wextra
        ${CSYM}Wno-maybe-uninitialized
288
        ${CSYM}Wno-surprising
289
290
291
292
293
        ${CSYM}fcheck=all
        ${CSYM}fbacktrace
       )

    SET(Fortran_FLAGS_RELEASE
294
        ${CSYM}O3
295
       )
296
297
298

    SET(Fortran_FLAGS_RELWITHDEBINFO
        ${CSYM}O3
299
        ${CSYM}g
300
301
        ${CSYM}fbounds-check
       )
302
303
304
305
306
307
308
309
ELSEIF(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")

    SET(Fortran_FLAGS
        ${CSYM}Mpreprocess
        ${CSYM}Mstandard
        ${CSYM}Mallocatable=03
        ${CSYM}pgf90libs
       )
310
    ## TODO: Figure out what sets 2008 standard for PGI and add same if statement for Futility_BUILD_NOSTANDARD
311
312
313
314
315
316
317
318
319
320
321
322
    SET(Fortran_FLAGS_DEBUG
        ${CSYM}g
        ${CSYM}Mbounds
        ${CSYM}Mdclchk
        ${CSYM}Mchkptr
        ${CSYM}traceback
       )

# RELEASE to be added for this compiler
    SET(Fortran_FLAGS_RELEASE
        ${CSYM}O3
       )
323
324
325
326
327
328

    SET(Fortran_FLAGS_RELWITHDEBINFO
        ${CSYM}O3
        ${CSYM}g
        ${CSYM}Mbounds
       )
329
330
331
332
333
334
335
336
337
338
ELSEIF(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")

    SET(Fortran_FLAGS_DEBUG
        ${CSYM}O0
        ${CSYM}g
       )

    SET(Fortran_FLAGS_RELEASE
        ${CSYM}O2
       )
339
340
341
342
343

    SET(Fortran_FLAGS_RELWITHDEBINFO
        ${CSYM}O2
        ${CSYM}g
       )
344
345
346
347
348
349
350
351
352
353
354
355
356
357
ELSEIF(CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
    SET(Fortran_FLAGS
        ${CSYM}fpp
        #${CSYM}fall-intrinsics
        ${CSYM}free
       )

    SET(C_FLAGS
        ${CSYM}lm
       )

    IF(${PROJECT_NAME}_BUILD_STANDARD)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
358
            ${CSYM}f2008
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
           )
    ENDIF()

    #IF(${PROJECT_NAME}_FPE_TRAP)
    #    SET(Fortran_FLAGS
    #        ${Fortran_FLAGS}
    #        ${CSYM}ffpe-trap=invalid,zero,overflow,underflow,denormal
    #       )
    #ENDIF()

    IF(MPACT_SUPPRESS_WARNINGS)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}w
           )
    ENDIF()

    IF(BUILD_SHARED_LIBS)
        SET(Fortan_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}Bdynamic
            ${CSYM}PIC
           )
    ELSE()
        SET(Fotran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}Bstatic
        )
    ENDIF()

    IF(${PROJECT_NAME}_GPROF)
        SET(Fortran_FLAGS
            ${Fortran_FLAGS}
            ${CSYM}pg
           )
    ENDIF()

    SET(Fortran_FLAGS_DEBUG
        ${CSYM}O0
        #${CSYM}Wall
        #${CSYM}Warn=?
        ${CSYM}C=all
        ${CSYM}g
        ${CSYM}gline
        ${CSYM}mtrace=all
       )

    SET(Fortran_FLAGS_RELEASE
        ${CSYM}O3
       )
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
ELSE()
    MESSAGE(WARNING " Fortran compiler: ${CMAKE_Fortran_COMPILER_ID} not supported!")
ENDIF()


IF(${PROJECT_NAME}_ENABLE_CODECOV)
    MESSAGE(STATUS " -- Configuring code coverage compiler flags...")
    INCLUDE(CodeCoverage_Config)
    CodeCoverage_SetCompilerFlags(${PROJECT_NAME}_ENABLE_CODECOV)
ENDIF()


SET(Fortran_FLAGS ${Fortran_FLAGS} ${OpenMP_Fortran_FLAGS})

# Add define symbols to Fortran_FLAGS and CXX_Flags
FOREACH(def ${${PACKAGE_NAME}_DEFINES})
    SET(Fortran_FLAGS ${Fortran_FLAGS} ${CSYM}D${def})
    SET(CXX_FLAGS ${CXX_FLAGS} ${CSYM}D${def})
    SET(C_FLAGS ${C_FLAGS} ${CSYM}D${def})
ENDFOREACH()
SET(Fortran_FLAGS ${Fortran_FLAGS} ${petsc_include} ${petsc_lib})
SET(CXX_FLAGS ${CXX_FLAGS} ${petsc_include} ${petsc_lib})
#MESSAGE(STATUS "fortran_flags ${Fortran_FLAGS}")

# Append Futility flags to existing CMAKE_Fortran_FLAGS
FOREACH(flag ${Fortran_FLAGS})
    #STRING(REGEX MATCH "${flag}" ispresent "${CMAKE_Fortran_FLAGS}")
    #IF(NOT ispresent)
        SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${flag}")
    #ENDIF()m
ENDFOREACH()

# Append Futility flags to existing CMAKE_CXX_FLAGS
FOREACH(flag ${CXX_FLAGS})
    #STRING(REGEX MATCH "${flag}" ispresent "${CMAKE_CXX_FLAGS}")
    #IF(NOT ispresent)
        SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${flag})
    #ENDIF()m
ENDFOREACH()
# Not sure if this automatically happens to the CMAKE_Fortran_FLAGS somewhere, but the CMAKE ;'s disappear
# but remain for the CXX flags.  Manually removing them here.
STRING(REGEX REPLACE ";" " " CMAKE_CXX_FLAGS_TEMP "${CMAKE_CXX_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_TEMP}")

# Append Futility flags to existing CMAKE_C_FLAGS
FOREACH(flag ${C_FLAGS})
    #STRING(REGEX MATCH "${flag}" ispresent "${CMAKE_C_FLAGS}")
    #IF(NOT ispresent)
        SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${flag})
    #ENDIF()m
ENDFOREACH()
# Not sure if this automatically happens to the CMAKE_Fortran_FLAGS somewhere, but the CMAKE ;'s disappear
# but remain for the C flags.  Manually removing them here.
STRING(REGEX REPLACE ";" " " CMAKE_C_FLAGS_TEMP "${CMAKE_C_FLAGS}")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_TEMP}")

# Append Futility Debug flags to existing CMAKE_Fortran_FLAGS_DEBUG
FOREACH(flag ${Fortran_FLAGS_DEBUG})
    STRING(REGEX MATCH "${flag}" ispresent "${CMAKE_Fortran_FLAGS_DEBUG}")
    IF(NOT ispresent)
        SET(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${flag}")
    ENDIF()
ENDFOREACH()

# Append Futility Release flags to existing CMAKE_Fortran_FLAGS_RELEASE
FOREACH(flag ${Fortran_FLAGS_RELEASE})
    STRING(REGEX MATCH "${flag}" ispresent "${CMAKE_Fortran_FLAGS_RELEASE}")
    IF(NOT ispresent)
        SET(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${flag}")
    ENDIF()
ENDFOREACH()

481
482
483
484
485
486
487
488
# Append Futility Release flags to existing CMAKE_Fortran_FLAGS_RELWITHDEBINFO
FOREACH(flag ${Fortran_FLAGS_RELWITHDEBINFO})
    STRING(REGEX MATCH "${flag}" ispresent "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}")
    IF(NOT ispresent)
        SET(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO} ${flag}")
    ENDIF()
ENDFOREACH()

489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# Clear local variables
UNSET(CONFIG_TYPES)
UNSET(CONFIG_EXIST)
UNSET(CSYM)
UNSET(${PACKAGE_NAME}_DEFINES)
UNSET(OpenMP_Fortran_FLAGS)
UNSET(Fortran_FLAGS)
UNSET(Fortran_FLAGS_STRING)
UNSET(Fortran_FLAGS_DEBUG)
UNSET(Fortran_FLAGS_DEBUG_STRING)
UNSET(Fortran_FLAGS_RELEASE)
UNSET(Fortran_FLAGS_RELEASE_STRING)
UNSET(CXX_FLAGS)
UNSET(CMAKE_CXX_FLAGS_TEMP)
UNSET(flag)
UNSET(def)
UNSET(s)
UNSET(ctyp)