命令格式
add_subdirectory (source_dir [binary_dir] [EXCLUDE_FROM_ALL])
添加一个子目录并构建该子目录。
如果想同时编译多个CmakeLists.txt 可以使用add_subdirectory
test/CMakeLists.txt
cmake_minimum_required(VERSION 3.7.1)
project(hello)
add_subdirectory(hello1)
add_subdirectory(hello2)
test/hello1/CMakeLists.txt
PROJECT(HELLO1)
add_executable(hello1 main1.c)
test/hello1/main.c1
//main.c1
#include<stdio.h>
int main()
{
printf("Hello World from t1 Main!\n");
return 0;
}
test/hello2/CMakeLists.txt
PROJECT(HELLO2)
add_executable(hello2 main2.c)
test/hello1/main.c2
//main.c2
#include<stdio.h>
int main()
{
printf("Hello World from t2 Main!\n");
return 0;
}
编译test/CMakeLists.txt
cmake test/CMakeLists.txt
make