Skip to content

Commit

Permalink
CMake: simplify retrieval of Catch2
Browse files Browse the repository at this point in the history
  • Loading branch information
Morwenn committed Dec 16, 2023
1 parent c670ca7 commit fb93cbe
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions tests/CMakeLists.txt
@@ -1,6 +1,8 @@
# Copyright (c) 2015-2023 Morwenn
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.24.0)

include(cpp-sort-utils)
include(FetchContent)

Expand All @@ -15,28 +17,14 @@ option(CPPSORT_STATIC_TESTS "Whether to turn some tests into static assertions"
########################################
# Find or download Catch2

message(STATUS "Looking for Catch2 3.5.0+")
find_package(Catch2 3.5.0 QUIET)
if (TARGET Catch2::Catch2)
get_target_property(Catch2_INCLUDE_DIRECTORY Catch2::Catch2 INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "Catch2 found: ${Catch2_INCLUDE_DIRECTORY}")
else()
message(STATUS "Catch2 not found")
message(STATUS "Downloading Catch2")
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG v3.5.0
)

FetchContent_GetProperties(catch2)
if (NOT catch2_POPULATED)
FetchContent_Populate(catch2)
add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
include(Catch)
endif()
endif()
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG v3.5.0
FIND_PACKAGE_ARGS 3.5.0
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
include(Catch)

########################################
Expand Down

0 comments on commit fb93cbe

Please sign in to comment.