Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more than one optimization flag to be set when running CMake #2551

Merged
merged 10 commits into from
Jan 12, 2023
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ get_target_triple( NEST_TARGET_TRIPLE NEST_TARGET_ARCH NEST_TARGET_VENDOR NEST_T
nest_process_with_python()
include( GNUInstallDirs )
nest_post_process_with_python()
nest_process_with_optimize()
nest_process_with_debug()
nest_process_with_std()
nest_process_with_intel_compiler_flags()
nest_process_with_warning()
Expand All @@ -156,6 +154,12 @@ nest_process_version_suffix()
nest_process_userdoc()
nest_process_devdoc()

# These two function calls must come last, as to prevent unwanted interactions of the newly set flags
# with detection/compilation operations carried out in earlier functions. The optimize/debug flags set
# using these functions should only apply to the compilation of NEST.
nest_process_with_optimize()
nest_process_with_debug()
terhorstd marked this conversation as resolved.
Show resolved Hide resolved

nest_get_color_flags()
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NEST_C_COLOR_FLAGS}" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NEST_CXX_COLOR_FLAGS}" )
Expand Down
11 changes: 6 additions & 5 deletions cmake/ProcessOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
# add custom warnings and optimizations
function( NEST_PROCESS_WITH_OPTIMIZE )
if ( with-optimize )
if ( with-optimize STREQUAL "ON" )
string(TOUPPER "${with-optimize}" WITHOPTIMIZE)
if ( WITHOPTIMIZE STREQUAL "ON" )
set( with-optimize "-O2" )
endif ()
foreach ( flag ${with-optimize} )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE )
endforeach ()
set(OPTIMIZATION_FLAGS "")
string(JOIN " " OPTIMIZATION_FLAGS ${with-optimize} )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPTIMIZATION_FLAGS}" PARENT_SCOPE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS}" PARENT_SCOPE )
gtrensch marked this conversation as resolved.
Show resolved Hide resolved
endif ()
endfunction()

Expand Down