Question

I use cmake to build, test and install my project. My way is a little crude: I use a scripts like this to get an out-of-source build:

DIR=debug_build &&
rm -fr ./${DIR} &&
mkdir -p ${DIR} &&
cd ${DIR} &&
cmake -D CMAKE_BUILD_TYPE=Debug $@ .. &&
make 

I guess I could at least put it into makefile, but isnt it strange to use Makefile to run cmake to generate new Makefiles and run another make?

What is the proper way to do it? Does cmake have an option to avoid calling "cd"?

Recently it became even more complicated as I factoread out a library that I would like to compile, test and distribute separately. I want to avoid duplication of all the stuff I have in my top CMakeLists.txt.

How to do it properly with cmake?

Was it helpful?

Solution

No, CMake does not have any such option. I usually like to have a wrapper Makefile to control CMake-invocations.

The main issue here is that the Makefile-generator doesn't support specifying the configuration when running make, as the Visual Studio generator does. I think there is a feature request filed for this, but it would be very invasive procedure to fix.

OTHER TIPS

This seems to be the most common form of handling this. I've typically seen (and used) batch scripts (either shell scripting on unix, or just batch files on Windows) to handle this, so running ./build will create the build folder, CD there, run cmake, build, then go back to the original folder.

One could also use CMake GUI which will create the build folder automatically if it doesn't exist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top