[Cmake] Adding a debug switch with CMake

Bill Hoffman bill . hoffman at kitware . com
Wed, 11 Jun 2003 08:47:18 -0400


You could have the custom target change directories to the top of the project then
run cmake from the top, then cd back to the current directory and issue a make.


ADD_CUSTOM_TARGET(debug  "cd ${PROJECT_BINARY_DIR}; ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Debug ${PROJECT_SOURCE_DIR}; cd ${PROJECT_BINARY_DIR}/ThisDir; make")

Then add this command into each directory of your project.   
Then you could just run "make debug" in any directory.   It would
change all the makefiles, but would only run make in the local directory,
so you should get the behavior you want.

-Bill



>ADD_CUSTOM_TARGET(debug  ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Debug ${PROJECT_SOURCE_DIR})
>                                            ^
>
>Having fiddled about with this, my understanding is as follows:
>
>1) I need to set the flags -O0 and -g in variables
>CMAKE_CXX_FLAGS_DEBUG   and   CMAKE_C_FLAGS_DEBUG
>
>
>2) If I do this, and then issue, at the top-level of my  build tree
>
>% make debug
>
>what happens is that Cmake is run again, with the variable
>CMAKE_BUILD_TYPE is set to Debug
>
>Then I have to do
>
>% make
>
>again and the build is then done with the debug switches I
>have set.
>
>
>3)  I can only put this CMake command in my top-level
>CMakeLists.txt and run it from the top-level build directory
>(because it invokes the CMakeLists.txt files from the
>top of the source tree).
>
>E.g. if I ran it from further down the build tree, I'd be
>getting a whole new tree beneath me
>
>
>So in essence, all this does is wrap the setting of
>CMAKE_BUILD_TYPE to Debug into a make command rather
>than the user reconfiguring themselves with the
>cmake command explicitly.  Further it is a global switch.
>
>This is not what I want.  Perhaps I wasn't clear.
>Normally, when I build my system, I can position myself
>anywhere in the output build tree and issue the command
>
>% make
>
>and it will recursively build the system from that
>directory.
>
>I want the equivalent where I can say
>
>
>% make debug
>
>at any location in the output build tree and have the modules
>built with the debug switches.
>
>What we have discussed so far is a Global switch that affects
>all of the Makefiles in the output build tree and furthermore that
>those Makefiles have to be regenerated to get the switch active.
>
>I think this is cumbersome.   As a developer you would
>prefer to maintain (small) optimized modules where possible,
>and only build debug as need be for specified bits.
>
>Perhaps this is not possible with CMake ?
>
>
>regards
>Neil
>
>
>_______________________________________________
>Cmake mailing list
>Cmake at public . kitware . com
>http://public . kitware . com/mailman/listinfo/cmake