【发布时间】:2018-10-28 17:01:10
【问题描述】:
我正在尝试将 Google Test 集成到更大项目的子项目中,但我找不到令我满意的解决方案。
我有两个限制:
- Google Test 的源代码已经在项目结构中的某个位置(因此不能使用 URL 从 git 存储库下载它)
- Google Test 的源代码不是我的子项目的子目录(永远不会)
所以当我尝试做这样的事情时:
add_subdirectory( ${GOOGLETEST_PROJECT_LOCATION})
我收到了:
CMake Error at unit_tests/CMakeLists.txt:10 (add_subdirectory):
add_subdirectory not given a binary directory but the given source
directory "${GOOGLETEST_PROJECT_LOCATION}" is not a subdirectory of
"${UNIT_TEST_DIRECTORY}". When
specifying an out-of-tree source a binary directory must be explicitly
specified.
另一方面,ExternalProject_Add 可能是一个解决方案,但当我根本不想下载源代码并使用项目中特定位置的源代码时,我不知道该如何使用它。
项目结构看起来更像这样:
3rdparty
|--googletest
...
subproject
|--module1
|--file1.cpp
|--CMakeLists.txt
|--module2
|--file2.cpp
|--CMakeLists.txt
|--include
|--module1
|--file1.h
|--module2
|--file2.h
|--unit_test
|--module1
|--file1test.cpp
|--module2
|--file2test.cpp
|--CMakeLists.txt
|--CMakeLists.txt
CMakeLists.txt
【问题讨论】:
标签: c++ build cmake googletest