GoogleTest作为CMake中的ExternalProject的安装问题

时间:2019-01-08 16:20:47

标签: cmake

我选择使用CMake通过the tutorial by Craig Scott在本地下载和构建GoogleTest(这要归功于Craig Scott的博客文章)。

一切正常,但是我对安装过程有疑问。

我想安装一个可执行目标(暂时):

# Install test executables
    install(TARGETS scTestBuild DESTINATION bin)

当我在Linux上构建时:

cmake -DCMAKE_INSTALL_PREFIX=$HOME/Downloads ..
make 
make install

该配置还会安装GoogleTest包含和lib64内容:

ls ~/Downloads/
bin  include  lib64

可以通过某种方式避免这种情况吗?

我刚开始使用CMake,正在将项目移植到它,这是我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.13)

project(soupcutter VERSION 1.0
                   DESCRIPTION "Intersection of geometrical soups (sets of geometrical objects)."
                   LANGUAGES CXX)

# GoogleTest integration by Craig Scott 
# https://crascit.com/2015/07/25/cmake-gtest/

    # 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
    add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
                     "${CMAKE_BINARY_DIR}/googletest-build")

    # The gtest/gmock targets carry header search path
    # dependencies automatically when using CMake 2.8.11 or
    # later. Otherwise we have to add them here ourselves.
    if(CMAKE_VERSION VERSION_LESS 2.8.11)
        include_directories("${gtest_SOURCE_DIR}/include"
                            "${gmock_SOURCE_DIR}/include")
    endif()

# Configure the INTERFACE library 
    add_library(soupcutter INTERFACE) 
    target_include_directories(soupcutter INTERFACE 
        include/ 
        include/core/
        include/io/
        include/io/vtk/
        include/algorithm/
        include/model/
        include/testing/
    )

# Build test executables 
    add_executable(scTestBuild app/test/scTestBuild/scTestBuild.cpp) 
    target_link_libraries(scTestBuild soupcutter gtest)

# Install test executables
    install(TARGETS scTestBuild DESTINATION bin)

0 个答案:

没有答案