[CMake] How to support separate debug and release build directories?
Braden McDaniel
braden at endoframe.com
Fri Jun 21 09:33:23 EDT 2019
On Fri, 2019-06-21 at 14:19 +0100, David Aldrich wrote:
> Thanks for the help I have received in the past few days. I am making
> incremental improvements to my CMake project and have a new
> challenge. I am running CMake 3.13 on Centos 7.6, targeting make.
> My CMake file successfully builds debug or release targets and puts
> the executable in an out-of-source build directory. I have added
> debug and release make targets so I can execute 'make debug' etc.
>
> I now want to support separate target directories: build/debug and
> build/release. I've shown my CMakeLists.txt below. So far I've just
> added an attempt to support build/debug:
>
> if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
> message("debug mode")
> set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/debug)
> endif (CMAKE_BUILD_TYPE EQUAL "DEBUG")
>
> but:
>
> $ cmake3 -DCMAKE_BUILD_TYPE=DEBUG ..
>
> puts the target into build, not build/debug.
The conventional solution to this is to run cmake in the "build/debug"
directory.
> I would also like this to work if I use the make targets e.g. make
> debug.
I think that's outside the scope of the Makefile generator. For that
generator, CMAKE_BUILD_TYPE is a configuration-wide setting. If you
want a different configuration, you need a different build directory
(where "build directory" is wherever you run cmake).
--
Braden McDaniel <braden at endoframe.com>
More information about the CMake
mailing list