我的项目结构如下:
root/
CMakeLists.txt
project_a/
CMakeLists.txt
src/
include/
project_b/
CMakeLists.txt
src/
include/
third_party/
googletest
...
project_b依赖于project_a构建的库,而 project_a和project_b都依赖于googletest。
我使用ExternalProject来获取和配置googletest:
# Download and install GoogleTest
ExternalProject_Add(
gtest
URL https://github.com/google/googletest/archive/master.zip
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gtest
# Disable install step
INSTALL_COMMAND ""
)
# Create a libgtest target to be used as a dependency by test programs
add_library(libgtest IMPORTED STATIC GLOBAL)
add_dependencies(libgtest gtest)
# Set libgtest properties
set_target_properties(libgtest PROPERTIES
"IMPORTED_LOCATION" "${binary_dir}/googlemock/gtest/libgtest.a"
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}"
)
我想将project_a作为ExternalProject接口,以便我可以在project_b的CMakeLists.txt中使用find_package()
,但是在配置并运行make之后make步骤失败:
/ usr / bin / ld:找不到-llibgtest
反复尝试没有多少成果,我可以使用一些帮助。谢谢!