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