diff --git a/CMakeLists.txt b/CMakeLists.txt index abfacf0358..27ce24a140 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() @@ -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}" ) diff --git a/cmake/ProcessOptions.cmake b/cmake/ProcessOptions.cmake index da6a37fdfa..a540cfb4b0 100644 --- a/cmake/ProcessOptions.cmake +++ b/cmake/ProcessOptions.cmake @@ -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()