更改CMake生成的文件的输出目录

时间:2014-11-27 11:24:47

标签: cmake

我的项目有这样的结构:

root
|- src/
|- bin/
|- include/
|- CMakeFiles/
|- CMakeLists.txt

当我运行cmake命令时,它会生成一些文件:CMakeCache.txtcmake_install.cmake有一种方法可以在CMakeFiles中自动发送它,或者之后删除它吗?

我只想使用cmake(不是cmake -G"Unix Makefiles" && rm -f CMakeCache.txt cmake_install.cmake之类的命令行组合)

2 个答案:

答案 0 :(得分:7)

最好使用out-of-source构建树。

创建新目录build

root
|- src/
|- bin/
|- include/
|- CMakeFiles/
|- CMakeLists.txt
build

并在cmake目录中运行build

cd build
cmake ../root

所有CMake生成的文件和构建工件都将位于构建树中,不会污染源目录。

建议使用CMake:http://www.cmake.org/Wiki/CMake_FAQ#Out-of-source_build_trees

答案 1 :(得分:2)

我找到了一种方法,不是购买CMake而是使用makefile

if(UNIX)
    add_custom_target (distclean @echo cleaning for source distribution)

    add_custom_command(
        COMMENT "distribution clean"
        COMMAND make
        ARGS -C ${CMAKE_CURRENT_BINARY_DIR} clean
        COMMAND find
        ARGS ${CMAKE_CURRENT_BINARY_DIR} -name "CMakeCache.txt" | xargs rm -rf
        COMMAND find
        ARGS ${CMAKE_CURRENT_BINARY_DIR} -name "CMakeFiles" | xargs rm -rf
        COMMAND find
        ARGS ${CMAKE_CURRENT_BINARY_DIR} -name "Makefile" | xargs rm -rf
        COMMAND find
        ARGS ${CMAKE_CURRENT_BINARY_DIR} -name "*.cmake" | xargs rm -rf
        COMMAND find
        ARGS ${CMAKE_CURRENT_SOURCE_DIR} -name "*.qm" | xargs rm -rf
        COMMAND rm
        ARGS -rf ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt
        TARGET  distclean
    )
endif(UNIX)

然后我只需做make distclean