It seems like we need to create separate folder for each build type (debug/release), run cmake on each, and generate separate makefile for debug/release configuration. Is it possible to create one single makefile using cmake that supports both debug/release configuration at the same time and when we actually run "make" that will create separate folders for the intermediate and final products (like the dlls, exe).
Make (or rather a Makefile) is a buildsystem - it drives the compiler and other build tools to build your code. CMake is a generator of buildsystems. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions.
CMake can generate a native build environment that will compile source code, create libraries, generate wrappers and build executables in arbitrary combinations. CMake supports in-place and out-of-place builds, and can therefore support multiple builds from a single source tree.
compile in Release mode optimized but adding debug symbols, useful for profiling : cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ... or compile with NO optimization and adding debug symbols : cmake -DCMAKE_BUILD_TYPE=Debug ...
MinSizeRel is the same as Release, with its optimization configuration just set to Minimize Size instead of Maximize Speed as illustrated in this link in Visual Studio, for example.
As far as I know, this cannot be achieved using a single set of build scripts. However, what you can do is have two sub-directories of your working area:
build/
build/debug
build/release
Then do:
$ cd build
$
$ cd build/debug
$ cmake -DCMAKE_BUILD_TYPE=Debug ../..
$ make
$
$ cd ../release
$ cmake -DCMAKE_BUILD_TYPE=Release ../..
$ make
If necessary, you can add another build script in the build
directory as such:
#!/bin/sh
cd debug && make && cd ..
cd release && make && cd ..
This can be achieved using the ADD_CUSTOM_TARGET
command. For example, if you want to add both debug and release targets in your makefile, add the following to your CMakeLists.txt file:
ADD_CUSTOM_TARGET(debug
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
COMMENT "Creating the executable in the debug mode.")
ADD_CUSTOM_TARGET(release
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
COMMENT "Creating the executable in the release mode.")
Then, after configuring with cmake, you can run make debug
to make the debug target and run make release
to make the release target in the same directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With