How to configure ExternalProject during main project configuration?

后端 未结 4 657
粉色の甜心
粉色の甜心 2021-02-05 10:37

The CMake\'s ExternalProject allows to define how to an external project is going to be downloaded, configured, built and installed. All whose steps are going to be performed at

4条回答
  •  春和景丽
    2021-02-05 11:01

    Since CMake 3.14 and up wards, this how you use FetchContent

    FetchContent_Declare(
      googletest
      GIT_REPOSITORY https://github.com/google/googletest.git
      GIT_TAG        release-1.8.0
    )
    
    FetchContent_MakeAvailable(googletest)
    

    Then to build your test test/CMakeLists.txt

    cmake_minimum_required(VERSION 3.15)
    project(${PROJECT_NAME}_test)
    
    # Tests for mu_project
    file(GLOB_RECURSE TEST_SOURCES 
        ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
        ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
    )
    
    add_executable(${PROJECT_NAME}_test ${TEST_SOURCES})
    target_link_libraries(${PROJECT_NAME}_test gtest gmock_main)
    
    # Register the tests
    add_test(NAME ${PROJECT_NAME}_test
             COMMAND ${PROJECT_NAME}_test)
    enable_testing()
    

    You're now good to go

提交回复
热议问题