Skip to content

Commit b14cede

Browse files
committed
Introduced ENZOE_<LANG>_FLIST variables
The purpose of these variables is to act similarly to the standard ``CMAKE_<LANG>_FLAGS`` variables, but only affect the source files directly used by Cello/Enzo-E. (The whole idea is to explicitly avoid is this new set of variables won't affect any external dependencies that is being compiled as a part of this build)
1 parent a31b7b0 commit b14cede

File tree

11 files changed

+261
-23
lines changed

11 files changed

+261
-23
lines changed

CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,34 @@ add_subdirectory(src/External)
309309
# 2. language-specific generator-expressions are not supported on all
310310
# build-generators (this isn't really a problem per-se, but it would be
311311
# nice to be as flexible as possible)
312+
313+
# handle flags within ENZOE_<LANG>_FLIST for each language used be Enzo-E
314+
include("GenericOptionCommand")
315+
get_property(_ENZOE_LANG_LIST GLOBAL PROPERTY ENABLED_LANGUAGES)
316+
317+
foreach(lang IN LISTS _ENZOE_LANG_LIST)
318+
# first, initialize ENZOE_<LANG>_FLIST if it hasn't already been initialized
319+
generic_option(
320+
ENZOE_${lang}_FLIST STRING "\
321+
specifies flags that are passed to the compiler (in all configurations) for \
322+
compiling the ${lang} files that are used in Cello and Enzo-E. There are 3 \
323+
main differences from CMAKE_${lang}_FLAGS: \
324+
(i) these flags won't be passed to any external dependencies that are \
325+
compiled as part of this build \
326+
(ii) these flags will NOT be passed to the linker, and \
327+
(ii) these flags must be specified as a semi-colon delimited list of values."
328+
# if there are any, the default values would be set in machine file
329+
DEFAULT_VALUE "${ENZOE_${lang}_FLIST_INIT}"
330+
FORBID_EXISTING_NONCACHE_VAR # <- discourage bad habits!
331+
)
332+
333+
# now setup cmake to make use of any compiler flags in the list
334+
if(NOT ("${ENZOE_${LANG}_FLIST}" STREQUAL ""))
335+
message("$<$<COMPILE_LANGUAGE:${LANG}>:${ENZOE_${LANG}_FLIST}>")
336+
endif()
337+
endforeach()
338+
339+
# introduce floating-point related compiler options
312340
option(OPTIMIZE_FP "Enables value-unsafe floating-point optimizations (this may already be enabled on some compilers like icc)." OFF)
313341
option(USE_SIMD "Use OpenMP SIMD directives. This may already be enabled on some compilers (like icc)." OFF)
314342
include("FPOptimizationCompileOptions")
@@ -319,6 +347,7 @@ elseif (USE_SIMD)
319347
message(FATAL_ERROR "Can only use `USE_SIMD=ON` when `OPTIMIZE_FP=ON`.")
320348
endif()
321349

350+
# introduce required Fortran Compiler Options
322351
include("RequiredFortranCompileOptions")
323352
get_required_fortran_options(_ENZOE_REQ_FORTRAN_OPTS)
324353
add_compile_options("${_ENZOE_REQ_FORTRAN_OPTS}")

cmake/GenericOptionCommand.cmake

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# See LICENSE_ENZO file for license and copyright information
2+
3+
#.rst:
4+
# GenericOptionCommand
5+
# --------------------
6+
#
7+
# Defines a command, ``generic_option``, that acts like a more general form of
8+
# the built-in ``option`` command.
9+
#
10+
# In slightly more detail, it provides a variable that the user can optionally
11+
# specify::
12+
#
13+
# generic_option(<variable> <type> <help_text>
14+
# DEFAULT_VALUE <default_value>
15+
# [FORBID_EXISTING_NONCACHE_VAR])
16+
#
17+
# Similar to the ``option`` command, the default behavior is to
18+
# - do nothing if ``<variable>`` is already defined (as a normal or cache
19+
# variable).
20+
# - initialize ``<variable>`` as a cache variable of type ``TYPE``
21+
# with the specified ``<default_value>``. If ``DEFAULT_VALUE`` is not
22+
# specified, then the default is ``OFF`` for a ``BOOL`` variable and
23+
# ``""`` in other cases.
24+
#
25+
# When the ``FORBID_EXISTING_NONCACHE_VAR`` option is specified, this command
26+
# will immediately abort cmake with an error if ``<variable>`` is already
27+
# exists as a non-cache variable. NOTE: if it exists as a cache variable and as
28+
# a normal variable that is okay (there isn't any way to identify this case
29+
# anyways)
30+
31+
if(__GenericOptionCommand)
32+
return()
33+
endif()
34+
set(__GenericOptionCommand YES)
35+
36+
37+
function(generic_option variable type help_text)
38+
39+
# on the off-chance that the variable-name matches a value used in this
40+
# function, let's check if it already exists (BEFORE DEFINING ANY VARIABLES)
41+
if (DEFINED "${variable}")
42+
set(is_already_defined TRUE)
43+
else()
44+
set(is_already_defined FALSE)
45+
endif()
46+
47+
# parse args
48+
set(options FORBID_EXISTING_NONCACHE_VAR)
49+
set(oneValueArgs DEFAULT_VALUE)
50+
set(multiValueArgs "")
51+
cmake_parse_arguments(PARSE_ARGV 3 __GENERIC_OPTION "${options}" "${oneValueArgs}"
52+
"${multiValueArgs}" )#${ARGN} )
53+
54+
# some basic error-handling
55+
set(_funcname "generic_option")
56+
if (DEFINED __GENERIC_OPTION_UNPARSED_ARGUMENTS)
57+
message(FATAL_ERROR
58+
"${_funcname} recieved invalid arguments: "
59+
"\"${__GENERIC_OPTION_UNPARSED_ARGUMENTS}\"")
60+
elseif (DEFINED __GENERIC_OPTION_KEYWORDS_MISSING_VALUES)
61+
message(FATAL_ERROR
62+
"${_funcname} received the ${__GENERIC_OPTION_KEYWORDS_MISSING_VALUES} "
63+
"keyword(s) without any associated arguments.")
64+
elseif ("${type}" STREQUAL "INTERNAL")
65+
message(FATAL_ERROR "${_funcname} does not support the INTERNAL type")
66+
elseif ("${type}" MATCHES "^PATH|FILEPATH$")
67+
# these types have some weird handling related to relative-paths
68+
message(FATAL_ERROR
69+
"${_funcname} doesn't currently support the ${type} type")
70+
elseif (NOT "${type}" MATCHES "^BOOL|STRING$")
71+
message(FATAL_ERROR "invalid type passed to ${_funcname}")
72+
endif()
73+
74+
if ("${__GENERIC_OPTION_FORBID_EXISTING_NONCACHE_VAR}" AND
75+
"${is_already_defined}" AND (NOT DEFINED CACHE{${variable}}))
76+
# by trial and error, the output format now seems nicer (not sure why we
77+
# need to escape some line-breaks but not others)
78+
message(FATAL_ERROR "\
79+
The \"${variable}\" variable is expressly forbidden from being defined as a \
80+
regular variable before the appropriate call to ${_funcname}. \
81+
You probably made the mistake of writing some cmake-code with ``set(...)`` \
82+
somewhere to define the variable.
83+
-> if you are a user, you should assign a value to the variable on the
84+
the command-line with the -D<var>=<value> flag or by modifying values
85+
in the CMakeCache.txt file (by modifying it directly OR using some kind
86+
of gui-program)
87+
-> if you are a developer, you are probably trying to assign a default value
88+
to \"${variable}\". In this case, you should prefer to specify the
89+
initial-value to ${_func_name} by using the DEFAULT_VALUE keyword. If you
90+
instead choose to refactor, keep in mind that it's a little tricky to get
91+
this \"right\" (it can be tricky to allow users to override the value)")
92+
endif()
93+
94+
cmake_policy(GET CMP0077 _CMP0077_val)
95+
if ("${_CMP0077_val}" STREQUAL "OLD")
96+
message(FATAL_ERROR "${_func_name} needs NEW behavior of CMP0077")
97+
endif()
98+
99+
if (NOT "${is_already_defined}")
100+
if (DEFINED __GENERIC_OPTION_DEFAULT_VALUE)
101+
set("${variable}" "${__GENERIC_OPTION_DEFAULT_VALUE}" CACHE "${type}"
102+
"${help_text}")
103+
elseif("${type}" STREQUAL "BOOL")
104+
set("${variable}" "OFF" CACHE BOOL "${help_text}")
105+
else()
106+
set("${variable}" "" CACHE "${type}" "${help_text}")
107+
endif()
108+
endif()
109+
110+
endfunction()
111+

config/darwin_clang.cmake

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,19 @@ if(NOT __processedUserDefaults)
4545
# instruction set of the machine used to compile the code.
4646
set(CONFIG_ARCH_FLAGS "-march=native")
4747

48-
# add flag to unroll loops (this flag would also be enabled anyways when
49-
# OPTIMIZE_FP=TRUE)
50-
set(CMAKE_C_FLAGS "-funroll-loops" CACHE STRING "Default C flags")
51-
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Default C++ flags")
48+
# if you choose to add other flags, you should generally prefer to use:
49+
# ENZOE_C_FLIST_INIT, ENZOE_CXX_FLIST_INIT, ENZOE_Fortran_FLIST_INIT
50+
# rather than CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and CMAKE_Fortran_FLAGS
51+
# -> These alternatives will affect Cello/Enzo-E, but won't influence any
52+
# dependencies compiled in the same-build
53+
# -> plus, the alternatives let users easily overwrite them
5254

53-
# Setting package paths (e.g., Grackle) - (meant for personal machine files)
55+
# in this case, we add a flag to unroll loops
56+
# (aside: this flag would be enabled anyways when OPTIMIZE_FP=TRUE)
57+
set(ENZOE_C_FLIST_INIT "-Wall;-funroll-loops")
58+
set(ENZOE_CXX_FLIST_INIT "${ENZOE_C_FLIST_INIT}")
59+
60+
# Set package paths (e.g., Grackle) - Only do this in personal machine files
5461

5562
# Mark done
5663
set(__processedUserDefaults ON)

config/expanse_icc.cmake

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,24 @@ if(NOT __processedUserDefaults)
1717
# compiler are handled internally (if those flags don't work, please update
1818
# the relevant internal logic rather than specifying them here)
1919

20-
# add optional flags to C and C++ compilers that provide useful warnings
21-
set(CMAKE_C_FLAGS "-Wall" CACHE STRING "Default C flags")
22-
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Default C++ flags")
23-
2420
# these flag(s) are currently only used when using openmp-simd optimizations
2521
# (to specify available/prefered instruction sets).
2622
# This particular value tells the compiler to optimize the code for the
2723
# instruction set of the machine used to compile the code.
2824
set(CONFIG_ARCH_FLAGS "-xHost")
2925

30-
# Setting package paths (e.g., Grackle)
26+
# if you choose to add other flags, you should generally prefer to use:
27+
# ENZOE_C_FLIST_INIT, ENZOE_CXX_FLIST_INIT, ENZOE_Fortran_FLIST_INIT
28+
# rather than CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and CMAKE_Fortran_FLAGS
29+
# -> These alternatives will affect Cello/Enzo-E, but won't influence any
30+
# dependencies compiled in the same-build
31+
# -> plus, the alternatives let users easily overwrite them
32+
33+
# add optional flags to C and C++ compilers that provide useful warnings
34+
set(ENZOE_C_FLIST_INIT "-Wall")
35+
set(ENZOE_CXX_FLIST_INIT "${ENZOE_C_FLIST_INIT}")
36+
37+
# Set package paths (e.g., Grackle) - Only do this in personal machine files
3138

3239
# Mark done
3340
set(__processedUserDefaults ON)

config/frontera_icc.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ if(NOT __processedUserDefaults)
2323
# Lake (CLX) Compute Nodes
2424
set(CONFIG_ARCH_FLAGS "-xCORE-AVX512")
2525

26-
# Setting package paths (e.g., Grackle)
26+
# if you choose to add other flags, you should generally prefer to use:
27+
# ENZOE_C_FLIST_INIT, ENZOE_CXX_FLIST_INIT, ENZOE_Fortran_FLIST_INIT
28+
# rather than CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and CMAKE_Fortran_FLAGS
29+
# -> These alternatives will affect Cello/Enzo-E, but won't influence any
30+
# dependencies compiled in the same-build
31+
# -> plus, the alternatives let users easily overwrite them
32+
33+
# Set package paths (e.g., Grackle) - Only do this in personal machine files
2734

2835
# Mark done
2936
set(__processedUserDefaults ON)

config/hlrn_gcc.cmake

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,22 @@ if(NOT __processedUserDefaults)
1919
# the relevant internal logic rather than specifying them here)
2020

2121
# add optional flags to C and C++ compilers that provide useful warnings
22-
#set(CMAKE_C_FLAGS "-Wall" CACHE STRING "Default C flags")
23-
#set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Default C++ flags")
22+
#set(ENZOE_C_FLIST "-Wall" CACHE STRING "Default C flags")
23+
#set(ENZOE_CXX_FLIST "${ENZOE_C_FLIST}" CACHE STRING "Default C++ flags")
2424

2525
# these flag(s) are currently only used when using openmp-simd optimizations
2626
# (to specify available/prefered instruction sets).
2727
# This particular value tells the compiler to optimize the code for the
2828
# instruction set of the machine used to compile the code.
2929
set(CONFIG_ARCH_FLAGS "-march=skylake-avx512")
3030

31+
# if you choose to add other flags, you should generally prefer to use:
32+
# ENZOE_C_FLIST_INIT, ENZOE_CXX_FLIST_INIT, ENZOE_Fortran_FLIST_INIT
33+
# rather than CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and CMAKE_Fortran_FLAGS
34+
# -> These alternatives will affect Cello/Enzo-E, but won't influence any
35+
# dependencies compiled in the same-build
36+
# -> plus, the alternatives let users easily overwrite them
37+
3138
# Mark done
3239
set(__processedUserDefaults ON)
3340

config/linux_gcc.cmake

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ if(NOT __processedUserDefaults)
2323
# instruction set of the machine used to compile the code.
2424
set(CONFIG_ARCH_FLAGS "-march=native")
2525

26+
# if you choose to add other flags, you should generally prefer to use:
27+
# ENZOE_C_FLIST_INIT, ENZOE_CXX_FLIST_INIT, ENZOE_Fortran_FLIST_INIT
28+
# rather than CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and CMAKE_Fortran_FLAGS
29+
# -> These alternatives will affect Cello/Enzo-E, but won't influence any
30+
# dependencies compiled in the same-build
31+
# -> plus, the alternatives let users easily overwrite them
32+
2633
# add optional flags to C and C++ compilers that provide useful warnings
2734
# (also add flag to unroll loops - this flag would also be enabled anyways
2835
# when OPTIMIZE_FP=TRUE)
29-
set(CMAKE_C_FLAGS "-Wall -funroll-loops" CACHE STRING "Default C flags")
30-
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Default C++ flags")
36+
set(ENZOE_C_FLIST_INIT "-Wall;-funroll-loops")
37+
set(ENZOE_CXX_FLIST_INIT "${ENZOE_C_FLIST}")
3138

32-
# Setting package paths (e.g., Grackle) - (meant for personal machine files)
39+
# Set package paths (e.g., Grackle) - Only do this in personal machine files
3340

3441
# Mark done
3542
set(__processedUserDefaults ON)

config/linux_icc.cmake

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@ if(NOT __processedUserDefaults)
1919
# compiler are handled internally (if those flags don't work, please update
2020
# the relevant internal logic rather than specifying them here)
2121

22-
# add optional flags to C and C++ compilers that provide useful warnings
23-
set(CMAKE_C_FLAGS "-Wall" CACHE STRING "Default C flags")
24-
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Default C++ flags")
25-
2622
# these flag(s) are currently only used when using openmp-simd optimizations
2723
# (to specify available/prefered instruction sets).
2824
# This particular value tells the compiler to optimize the code for the
2925
# instruction set of the machine used to compile the code.
3026
set(CONFIG_ARCH_FLAGS "-xHost")
3127

32-
# Setting package paths (e.g., Grackle)
28+
# if you choose to add other flags, you should generally prefer to use:
29+
# ENZOE_C_FLIST_INIT, ENZOE_CXX_FLIST_INIT, ENZOE_Fortran_FLIST_INIT
30+
# rather than CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and CMAKE_Fortran_FLAGS
31+
# -> These alternatives will affect Cello/Enzo-E, but won't influence any
32+
# dependencies compiled in the same-build
33+
# -> plus, the alternatives let users easily overwrite them
34+
35+
# add optional flags to C and C++ compilers that provide useful warnings
36+
set(ENZOE_C_FLIST_INIT "-Wall")
37+
set(ENZOE_CXX_FLIST_INIT "${ENZOE_C_FLIST_INIT}")
38+
39+
# Set package paths (e.g., Grackle) - Only do this in personal machine files
3340

3441
# Mark done
3542
set(__processedUserDefaults ON)

config/msu_hpcc_gcc.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ if(NOT __processedUserDefaults)
1717
# compiler are handled internally (if those flags don't work, please update
1818
# the relevant internal logic rather than specifying them here)
1919

20-
# Setting package paths (e.g., Grackle)
20+
# in principle we should set flags to specify hardware architecture (so that
21+
# they can be used with openmp-simd optimizations
22+
# set(CONFIG_ARCH_FLAGS ...)
23+
24+
# if you choose to add other flags, you should generally prefer to use:
25+
# ENZOE_C_FLIST_INIT, ENZOE_CXX_FLIST_INIT, ENZOE_Fortran_FLIST_INIT
26+
# rather than CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and CMAKE_Fortran_FLAGS
27+
# -> These alternatives will affect Cello/Enzo-E, but won't influence any
28+
# dependencies compiled in the same-build
29+
# -> plus, the alternatives let users easily overwrite them
30+
31+
# Set package paths (e.g., Grackle) - Only do this in personal machine files
2132

2233
# Mark done
2334
set(__processedUserDefaults ON)

config/pleiades_icc.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ if(NOT __processedUserDefaults)
1717
# compiler are handled internally (if those flags don't work, please update
1818
# the relevant internal logic rather than specifying them here)
1919

20-
# Setting package paths (e.g., Grackle)
20+
# in principle we should set flags to specify hardware architecture (so that
21+
# they can be used with openmp-simd optimizations
22+
# set(CONFIG_ARCH_FLAGS ...)
23+
24+
# if you choose to add other flags, you should generally prefer to use:
25+
# ENZOE_C_FLIST_INIT, ENZOE_CXX_FLIST_INIT, ENZOE_Fortran_FLIST_INIT
26+
# rather than CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and CMAKE_Fortran_FLAGS
27+
# -> These alternatives will affect Cello/Enzo-E, but won't influence any
28+
# dependencies compiled in the same-build
29+
# -> plus, the alternatives let users easily overwrite them
30+
31+
# Set package paths (e.g., Grackle) - Only do this in personal machine files
2132

2233
# Setting test environment
2334
set(PARALLEL_LAUNCHER "mpiexec" CACHE STRING "Use mpiexec for launching parallel tests")

0 commit comments

Comments
 (0)