cmake

Cmake命令之add_subdirectory介绍

2020-09-18  本文已影响0人  Domibaba


 最后,以一个完整的例子来结束本文(sub目录下的CMakeList.txttest.htest.cpp等文件内容如上文所示,没有变化),父目录下的main.cppCMakeList.txt如下:

# 父目录下的CMakeLists.txt
cmake_minimum_required(VERSION 3.10.2)
project(test)

include_directories(sub)
add_subdirectory(sub output) 

add_executable(test main.cpp)
target_link_libraries(test sub)
# 父目录下的main.cpp
#include "test.h"
#include <iostream>

int main(int argc, char** argv)
{
    std::cout << "In main..." << std::endl;
    test("hello, world!");
    return 0;
}
# 输出
> cmake --build .
Scanning dependencies of target sub
[ 25%] Building CXX object output/CMakeFiles/sub.dir/test.cpp.o
[ 50%] Linking CXX static library libsub.a
[ 50%] Built target sub
Scanning dependencies of target test
[ 75%] Building CXX object CMakeFiles/test.dir/main.cpp.o
[100%] Linking CXX executable test
[100%] Built target test
>./test
In main...
hello, world!

附录:参考资料

  1. https://cmake.org/cmake/help/latest/command/add_subdirectory.html
上一篇 下一篇

猜你喜欢

热点阅读