I'm using CMake and I want to try and make it so I have a subdirectory for it rather than files scattered through my project or the root of it.
I have a directory layout of project/cmake/CMakeLists.txt
and project/bin
and project/source
, so people can easily remove the CMake stuff if they want to. My only problem is that there probably is a way to do this that I don't know of. Currently it generates a bunch of rubbish including a project/cmake/bin/obtap.dir/home/jookia/Programming/obtap/source
folder.
cmake_minimum_required(VERSION 2.6)
project(obtap)
add_definitions(-g -Wall)
add_executable(.开发者_Python百科./bin/obtap ../source/main.cpp)
It compiles fine, it outputs the right directories. But my problems are this:
Is there a way to remove project/cmake/bin
directory and optionally, is there a way to not have all the CMake stuff and instead just generate a makefile so I have two files, CMakeLists.txt and Makefile?
As specified in the CMake FAQ, the generated Makefiles contains full path to libraries and source code, so there is no easy way to distribute a build tree generated by CMake.
I believe what you want should be the so called out of source build, which can be achieved by generating intermediate files in a separate directory by running cmake in a dedicated directory, for your case, you can try below commands:
mkdir -p project/bld/
cd project/bld/
cmake project/cmake
Now you get all the CMake stuffs generated in the project/bld directory and whenever you want to remove all those things, just run:
rm -fr project/bld/
You can even get several different profiles by setting up different build trees.
One issue may arise if you want to control the generated executable output path such that it's not hidden in the deeply nested cmake intermediate binary tree; the answer is you can set the variable CMAKE_CURRENT_BINARY_DIR to customise the executable output absolute path, or just use cmake -E
and add_custom_command
command to copy the executable out.
精彩评论