[CMake] //adding and changing compiler flags - state of the art?

Sören Freudiger muffmolch at gmx.de
Thu Nov 6 13:20:16 EST 2008


Hi
long long time ago I wrote this macro to add CXX flax:

#################################################################
###   ADD_CXX_FLAGS(flags)     				         ###
### flags will be added to CMAKE_CXX_FLAGS                    ###
#################################################################
MACRO(ADD_CXX_FLAGS)
  FOREACH(arg ${ARGN})
    SET(TMP ${arg}) #elsewise the Seperate command doesn't work)
    SEPARATE_ARGUMENTS(TMP)
    FOREACH(option ${TMP})
      STRING(REGEX REPLACE " ${option}" "" CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS}")
      STRING(REGEX REPLACE "${option}" "" CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS}")
      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${option}" CACHE STRING
"common C++ build flags" FORCE)
    ENDFOREACH(option ${TMP})  
  ENDFOREACH(arg ${ARGN})
ENDMACRO(ADD_CXX_FLAGS)

And also similar macros for the different build types.
But meanwhile a lot of things changed in cmake and I like to know how others
are handling the flag stuff.

Depending on the used compiler I have e.g. a gcc43.cmake file with common
compiler flags (and one for intel9/10, mscv8/9_32/64).
We don't have time to use the check compiler flag macro at all.

Thus what's the best way to set the flags (avoiding setting them twice, etc.
pp.)?
Shall I use the set_target_properties macro?

Best
-SirAnn



More information about the CMake mailing list