[Cmake] Adding a debug switch with CMake

Neil Killeen Neil . Killeen at atnf . csiro . au
Wed, 11 Jun 2003 15:00:17 +1000 (EST)


Andy, Bill

On Tue, 10 Jun 2003, Bill Hoffman wrote:

>
> To clarify:
> ADD_CUSTOM_TARGET(debug  ${CMAKE_COMMAND} -DMAKE_BUILD_TYPE:STRING=Debug ${PROJECT_SOURCE_DIR})
>
> There is no need to make an extra option, you can just use
> CMAKE_BUILD_TYPE.

presumably should be

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