[CMake] How to dictate cmake best CFLAGS/...
Daniel
daniel at connect2.com
Sat Apr 26 22:32:03 EDT 2008
Christoph Cullmann wrote:
> we have a strict set of C/CXX/LDFLAGS we want to pass the toolchain per
> default, how can that be accomplished best with cmake? Before, we just used
> nmake with handcrafted files using some environment variables.
At my work, we have the same problem, and we want the compile switches to be in
the build scripts so we can be relatively sure no one with a broken environment
will do a bad build. Here is what we do:
# Somewhere before the first PROJECT() command:
SET(CMAKE_USER_MAKE_RULES_OVERRIDE override.cmake)
# You could also have language specific files:
SET(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX override_cxx.cmake)
SET(CMAKE_USER_MAKE_RULES_OVERRIDE_C override_c.cmake)
# The file you specified will be read before the platform file.
# Then in override.cmake you can set your flags. Note the _INIT
# suffix on the variable names.
SET(CMAKE_CXX_FLAGS_INIT ${cxx_flags})
SET(CMAKE_CXX_FLAGS_DEBUG_INIT ${cxx_flags_debug})
SET(CMAKE_CXX_FLAGS_RELEASE_INIT ${cxx_flags_release})
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT ${cxx_flags_rwd})
--
Daniel
More information about the CMake
mailing list