Skip to content

Commit

Permalink
Merge pull request #2551 from med-ayssar/optimizer_flags
Browse files Browse the repository at this point in the history
Allow more than one optimization flag to be set when running CMake
  • Loading branch information
jougs committed Jan 12, 2023
2 parents 939c885 + c6d9b73 commit 32daadc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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()

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 )
endif ()
endfunction()

Expand Down

0 comments on commit 32daadc

Please sign in to comment.