Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在CMake中按名称构建目标?_C_Cmake - Fatal编程技术网

如何在CMake中按名称构建目标?

如何在CMake中按名称构建目标?,c,cmake,C,Cmake,我有一个由多个目标组成的cmake项目 MyProject/ /target1 /Some stuff /CMakeLists.txt // here add_executable(target1 main.c) /target2 /target3 ... CMakeLists.txt // root CMakeLists.txt file /build // folder for build files 我希望只构建target1,并将其放入项目中的/build文

我有一个由多个目标组成的cmake项目

MyProject/
/target1
       /Some stuff
       /CMakeLists.txt // here add_executable(target1 main.c)
/target2
/target3
...
CMakeLists.txt // root CMakeLists.txt file
/build // folder for build files
我希望只构建target1,并将其放入项目中的/build文件夹中

我可以建立所有的目标

[MyProject/build]$ cmake ..
[MyProject/build]$ make
如何仅构建target1

我想一定是这样的吧

[MyProject/build]$ cmake ..
[MyProject/build]$ cmake --build . --target target1 -- -j 12

假设您在CMakeLists.txt中设置了一个可执行文件

add_executable( my_exe ${my_exe_sources} )
然后你可以调用
make my_exe-j 2