File: FetchCatch2.cmake

package info (click to toggle)
mongo-cxx-driver 4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 13,832 kB
  • sloc: cpp: 61,365; python: 1,436; sh: 356; xml: 253; perl: 215; makefile: 21
file content (51 lines) | stat: -rw-r--r-- 1,472 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Use FetchContent to obtain Catch2.

include(FetchContent)

function(fetch_catch2)
    set(fetch_args "")
    if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0")
        set(fetch_args "SYSTEM")
    endif()

    FetchContent_Declare(
        EP_Catch2

        GIT_REPOSITORY https://github.com/catchorg/Catch2
        GIT_TAG v3.7.0
        GIT_SHALLOW TRUE
        LOG_DOWNLOAD ON

        ${fetch_args}

        FETCHCONTENT_UPDATES_DISCONNECTED ON
    )

    FetchContent_GetProperties(EP_Catch2)

    if(NOT ep_catch2_POPULATED)
        message(STATUS "Downloading Catch2...")

        # Avoid Catch2 compile warnings from being treated as errors.
        string(REPLACE " -Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
        string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

        # Ensure consistent default calling convention with test executables.
        if(MSVC)
            string(APPEND CMAKE_CXX_FLAGS " /Gv")
        endif()

        FetchContent_MakeAvailable(EP_Catch2)

        # Avoid building unnecessary targets. Use FetchContent_Declare(EXCLUDE_FROM_ALL) in CMake 3.28 and newer.
        set_property(DIRECTORY "${ep_catch2_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL ON)

        # Catch2 config vars.
        set_property(CACHE CATCH_INSTALL_DOCS PROPERTY VALUE OFF)
        set_property(CACHE CATCH_INSTALL_EXTRAS PROPERTY VALUE OFF)

        message (STATUS "Downloading Catch2... done.")
    endif()
endfunction()

fetch_catch2()