[CMake] Profiling flags and additional CMAKE_BUILD_TYPEs

Brad King brad.king at kitware.com
Thu Apr 7 15:32:30 EDT 2005


Dan Katz wrote:
> I have a project where I usually want to do debug builds or release
> builds but occasionally want to do builds with various sorts of
> profiling turned on.  Considering the long alphabet-soup of additional
> compiler flags I need to feed the compiler to turn profiling on, it
> would be convenient if there were some 'profiling' CMAKE_BUILD_TYPE
> which had the associated CMAKE_C_FLAGS_PROFILING etc. which I could
> then use to encapsulate this info into my CMakeLists.txt.
> 
> Now, I don't expect the system to build in a gazillion arbitrary
> CMAKE_BUILD_TYPEs, but I am wondering if there's some way to create a
> new CMAKE_BUILD_TYPE on the fly which would then cause "the usual
> suspect" CMAKE variables to be available.  Any info on this sort of
> thing (or on other solutions to the problem I describe above) is
> highly appreciated!

You can create a new build type just by specifying its name in 
CMAKE_BUILD_TYPE.  Then CMake automatically constructs the names of the 
variables and uses them if they are set.  An empty build type works, so 
having a new build type will let you add specific flags.  Your CMake 
code can set the variables however it wants.

This will make the variable available in the cache for the user to set:

SET(CMAKE_C_FLAGS_PROFILING "" CACHE STRING "profiling flags")

Then when the build type is set to PROFILING the flags will be used.

-Brad


More information about the CMake mailing list