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
7 changes: 5 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 @@ -155,6 +153,11 @@ nest_process_target_bits_split()
nest_process_version_suffix()
nest_process_userdoc()
nest_process_devdoc()
# IMPORTANT: Please try to keep these two function calls to be the last functions to call in this Process step.
# Adding wrong keywords to the "-Dwith-optmize" flag might cause wrong errors, and therefore to avoid that
# the step for processing the optmization phase and the debug phase must be the last steps.
jougs marked this conversation as resolved.
Show resolved Hide resolved
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}" )
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