系统 :
Linux anon-S 3.19.0-31-generic #36~14.04.1-Ubuntu SMP Thu Oct 8 10:21:08 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
CMake版本:
anon@anon-S:~/$ cmake --version
cmake version 3.2.2
主要的CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 11)
add_subdirectory(${PROJECT_SOURCE_DIR}/src)
add_subdirectory(${PROJECT_SOURCE_DIR}/test)
但
anon@anon-S:/home/anon/project/build$ cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: /home/anon/project/
构建文件已被写入:/home/anon/project/
代替/home/anon/project/build/
我在使用cmake 3.4.1的Debian jessie上没有这个问题:
anon@anon-S:/home/anon/project/build$ cmake ..
-- The C compiler identification is GNU 5.2.1
-- The CXX compiler identification is GNU 5.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.11")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/anon/project/build/
为了澄清这里发生的事情:
运行时,cmake <directory>
它执行以下两项操作之一:
<directory>
是源目录(即其中有CMakeLists.txt
),它将在该源上运行CMake并将当前工作目录用作构建目录。<directory>
是构建目录(即其中有一个CMakeCache.txt
),它将在用于创建构建目录的任何源目录上运行CMake。请注意,后一种情况优先于第一种情况。也就是说,如果您执行以下操作:
cd <src_dir>
cmake .
*oops, wrong directory, i didn't mean that*
cd build
cmake ..
您可能希望这将以CMake<src_dir>
作为源和build
构建目录运行。但是由于第一次偶然的CMake运行,<src_dir>
现在也是源代码构建的构建目录!因此,第二次运行将忽略其中的所有内容,build
而src_dir
同时用作源目录和构建目录。
这确实是一个非常棘手的问题,但是幸运的是,一旦您意识到正在发生的事情,就可以很快地解决它:只需CMakeCache.txt
从中删除即可<src_dir>
。
请注意,在新版本的CMake(3.13以上),就可以使用了-S
,并-B
命令行选项来澄清对目录参数的含义:
-S <path-to-source>
要构建的CMake项目的根目录的路径。
-B <path-to-build>
CMake将用作构建目录根目录的目录路径。
如果该目录尚不存在,CMake将创建该目录。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句