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
C++ 使用cmake的编译组_C++_Cmake - Fatal编程技术网

C++ 使用cmake的编译组

C++ 使用cmake的编译组,c++,cmake,C++,Cmake,我有一个项目,其中编译会产生许多可执行文件。我使用cmake生成makefile。然后,当我说make时,它们都被编译了。我知道我可以使用make target1编译所需的目标。但是我想把我所有的目标分成几个组,并能够使用,比如说使group_A来编译目标的子集。如何做到这一点 该项目是用C++编写的,在Linux和OSX下开发。< P>查看Cug文档中的 AddiuSuxObjult< > AddioRelabor < /代码>。可以将组添加为自定义目标,并将要生成的目标作为组的依赖项

我有一个项目,其中编译会产生许多可执行文件。我使用cmake生成makefile。然后,当我说
make
时,它们都被编译了。我知道我可以使用
make target1
编译所需的目标。但是我想把我所有的目标分成几个组,并能够使用,比如说
使group_A
来编译目标的子集。如何做到这一点


该项目是用C++编写的,在Linux和OSX下开发。

< P>查看Cug文档中的<代码> AddiuSuxObjult< <代码> > <代码> AddioRelabor < /代码>。可以将组添加为自定义目标,并将要生成的目标作为组的依赖项

编辑(在@m.s.的评论之后)

你能行

add_custom_target(<group-name> DEPENDS <target1> <target2> ...)

您现在可以使用
make hello12
来构建
hello1
hello2

您甚至不需要
add\u dependencies
,只需使用:
add\u custom\u target(group1取决于target1 target2)
#include <stdio.h>

int main() {
    printf("Hello World 1\n");
    return 0;
}
#include <stdio.h>

int main() {
    printf("Hello World 2\n");
    return 0;
}
#include <stdio.h>

int main() {
    printf("Hello World 3\n");
    return 0;
}
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(groups_demo)

add_executable(hello1 hello1.cpp)
add_executable(hello2 hello2.cpp)
add_executable(hello3 hello3.cpp)

add_custom_target(hello12 DEPENDS hello1 hello2)
add_custom_target(hello23 DEPENDS hello3 hello2)
add_custom_target(hello13 DEPENDS hello1 hello3)