Skip to content

Commit f6abd29

Browse files
authored
Merge pull request #312 from zrax/catch2_v3
Update to Catch2 3.x and allow it to be found from the system (or vcpkg)
2 parents 0822754 + ebb0642 commit f6abd29

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

.github/workflows/linux-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Install dependencies
1010
run: |
1111
sudo apt-get update
12-
sudo apt-get install -y libjpeg-turbo8-dev libpng-dev
12+
sudo apt-get install -y libjpeg-turbo8-dev libpng-dev catch2
1313
- name: Build string_theory
1414
run: |
1515
mkdir -p build_deps && cd build_deps

Tests/CMakeLists.txt

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
1-
include(FetchContent)
2-
FetchContent_Declare(Catch2
3-
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
4-
GIT_TAG v2.13.10
5-
)
6-
FetchContent_MakeAvailable(Catch2)
1+
find_package(Catch2 3.4 QUIET)
2+
if(NOT Catch2_FOUND)
3+
# Force Catch2 to be built as a static lib
4+
set(BUILD_SHARED_LIBS__save ${BUILD_SHARED_LIBS})
5+
set(BUILD_SHARED_LIBS OFF)
6+
7+
include(FetchContent)
8+
FetchContent_Declare(Catch2
9+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
10+
GIT_TAG v3.11.0
11+
)
12+
FetchContent_MakeAvailable(Catch2)
13+
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/contrib")
14+
15+
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS__save})
16+
endif()
717

818
set(test_SOURCES
9-
catch2_main.cpp
1019
Test_Location.cpp
1120
)
1221
add_executable(test_HSPlasma ${test_SOURCES})
13-
target_link_libraries(test_HSPlasma PRIVATE Catch2::Catch2 HSPlasma)
22+
target_link_libraries(test_HSPlasma PRIVATE Catch2::Catch2WithMain HSPlasma)
23+
24+
if(WIN32 AND BUILD_SHARED_LIBS)
25+
# Catch2 needs the HSPlasma DLL available to run <test_executable> --list-tests
26+
add_custom_command(
27+
TARGET test_HSPlasma PRE_BUILD
28+
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_FILE:HSPlasma> $<TARGET_FILE_DIR:test_HSPlasma>
29+
)
30+
endif()
1431

1532
# Integrate with CTest so we can use the built-in test targets
16-
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/contrib")
1733
include(CTest)
1834
include(Catch)
1935
catch_discover_tests(test_HSPlasma)

Tests/Test_Location.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* along with HSPlasma. If not, see <http://www.gnu.org/licenses/>.
1515
*/
1616

17-
#include <catch2/catch.hpp>
17+
#include <catch2/catch_test_macros.hpp>
1818

1919
#include "PRP/KeyedObject/plLocation.h"
2020

Tests/catch2_main.cpp

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)