我想在不同的CMake项目之间共享一个ExternalProject。想象一个如下的结构:
prj1
|- CMakeLists.txt
|- ...
|- CMakeLists.txt
|- ...
|- ext
|- gtest
|- CMakeLists.txt
|- googletest
|_ actual_google_test_files
我想要得到的是告诉
CMakeLists.txt
在ExternalProject中使用
lib/ext/gtest
中的gtest,而不是每次都为每个项目重新构建gtest。
理想情况下,gtest只需在其文件夹中构建一次,项目就可以使用它。我尝试使用像这里解释的那样的ExternalProject (
http://kaizou.org/2014/11/gtest-cmake/
),并在项目中包含
lib/ext/gtest/CMakeLists.txt
,但会为每个用户重新编译gtest。
发布于 2018-01-11 19:07:52
你应该试着把google_test集成成“子项目”而不是预建的,并使用一个“元”CMakeLists.txt……
请阅读 https://crascit.com/2015/07/25/cmake-gtest/
CMakeLists.txt.in:
cmake_minimum_required(VERSION 2.8.2)
project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
CMakeLists.txt:
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download" )
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download" )
# Prevent GoogleTest from overriding our compiler/linker options
# when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This adds
# the following targets: gtest, gtest_main, gmock
# and gmock_main