Skip to content

Commit

Permalink
Make Catch2 discovery more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Apr 29, 2024
1 parent 4a45586 commit 3ba09a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ SET_SOURCE_FILES_PROPERTIES( "./source/src/ann/kd_pr_search.cpp" PROPERTIES COMP
#ADD_SHARED_LIBRARY( ${PROJECT_NAME}_ann ${ann_library_sources} )
#INSTALL_SHARED_LIBRARY( ${PROJECT_NAME}_ann DESTINATION lib )

option(USE_EXTERNAL_CATCH2 "Link against an external Catch2 v3 static library, otherwise build it locally" ON)
option(USE_EXTERNAL_CATCH2 "Link against an external Catch2 v3 static library, otherwise build it locally" AUTO)
set(USE_EXTERNAL_CATCH2 AUTO CACHE STRING "Link against an external Catch2 v3 static library, otherwise build it locally")
set_property(CACHE USE_EXTERNAL_CATCH2 PROPERTY STRINGS AUTO ON OFF)

IF( BUILD_TESTING )
ADD_SUBDIRECTORY(source/tests)
Expand Down
15 changes: 13 additions & 2 deletions source/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ ENDMACRO()
ADD_MARLINUTIL_TEST( testmarlinutil )

#--- Unit test setup. Use existing Catch2 or fetch a suitable version and build it
if(USE_EXTERNAL_CATCH2)
FIND_PACKAGE(Catch2 3.0.0 REQUIRED)
if(CMAKE_CXX_STANDARD GREATER_EQUAL 20)
set(CATCH2_MIN_VERSION 3.4)
else()
set(CATCH2_MIN_VERSION 3.1)
endif()
if(USE_EXTERNAL_CATCH2)
if (USE_EXTERNAL_CATCH2 STREQUAL AUTO)
find_package(Catch2 ${CATCH2_MIN_VERSION})
else()
find_package(Catch2 ${CATCH2_MIN_VERSION} REQUIRED)
endif()
endif()

if(NOT Catch2_FOUND)
MESSAGE(STATUS "Fetching local copy of Catch2 library for unit-tests...")
# Build Catch2 with the default flags, to avoid generating warnings when we
# build it
Expand Down

0 comments on commit 3ba09a6

Please sign in to comment.