From a015950eaa5c4638b458fcaf87ccebea60e5fd76 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 25 Mar 2023 17:29:08 +0000 Subject: [PATCH] Use external Catch2 if available in cmake build (#600) --- CMakeLists.txt | 2 +- RecastDemo/premake5.lua | 4 ++-- Tests/CMakeLists.txt | 13 ++++++++++--- .../catch_amalgamated.hpp => catch2/catch_all.hpp} | 0 .../Contrib/{Catch => catch2}/catch_amalgamated.cpp | 2 +- Tests/Detour/Tests_Detour.cpp | 2 +- Tests/Recast/Tests_Recast.cpp | 2 +- Tests/main.cpp | 2 -- 8 files changed, 16 insertions(+), 11 deletions(-) rename Tests/Contrib/{Catch/catch_amalgamated.hpp => catch2/catch_all.hpp} (100%) rename Tests/Contrib/{Catch => catch2}/catch_amalgamated.cpp (99%) delete mode 100644 Tests/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d6fc216..47bc80e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.1) project(RecastNavigation) diff --git a/RecastDemo/premake5.lua b/RecastDemo/premake5.lua index 52bbaf9..3c57b4f 100644 --- a/RecastDemo/premake5.lua +++ b/RecastDemo/premake5.lua @@ -213,7 +213,7 @@ project "Tests" "../Recast/Source", "../Tests/Recast", "../Tests", - "../Tests/Contrib/Catch" + "../Tests/Contrib" } files { "../Tests/*.h", @@ -223,7 +223,7 @@ project "Tests" "../Tests/Recast/*.cpp", "../Tests/Detour/*.h", "../Tests/Detour/*.cpp", - "../Tests/Contrib/Catch/*.cpp" + "../Tests/Contrib/catch2/*.cpp" } -- project dependencies diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 45d7d1f..9a87479 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1,9 +1,7 @@ -file(GLOB TESTS_SOURCES *.cpp Detour/*.cpp Recast/*.cpp Contrib/Catch/*.cpp) +file(GLOB TESTS_SOURCES Detour/*.cpp Recast/*.cpp) include_directories(../Detour/Include) include_directories(../Recast/Include) -include_directories(./Contrib/Catch) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_executable(Tests ${TESTS_SOURCES}) @@ -11,4 +9,13 @@ set_property(TARGET Tests PROPERTY CXX_STANDARD 17) add_dependencies(Tests Recast Detour) target_link_libraries(Tests Recast Detour) + +find_package(Catch2 QUIET) +if (Catch2_FOUND) + target_link_libraries(Tests Catch2::Catch2WithMain) +else() + include_directories(./Contrib) + target_sources(Tests PRIVATE Contrib/catch2/catch_amalgamated.cpp) +endif() + add_test(Tests Tests) diff --git a/Tests/Contrib/Catch/catch_amalgamated.hpp b/Tests/Contrib/catch2/catch_all.hpp similarity index 100% rename from Tests/Contrib/Catch/catch_amalgamated.hpp rename to Tests/Contrib/catch2/catch_all.hpp diff --git a/Tests/Contrib/Catch/catch_amalgamated.cpp b/Tests/Contrib/catch2/catch_amalgamated.cpp similarity index 99% rename from Tests/Contrib/Catch/catch_amalgamated.cpp rename to Tests/Contrib/catch2/catch_amalgamated.cpp index 1f5527a..ea60686 100644 --- a/Tests/Contrib/Catch/catch_amalgamated.cpp +++ b/Tests/Contrib/catch2/catch_amalgamated.cpp @@ -12,7 +12,7 @@ // You probably shouldn't edit it directly. // ---------------------------------------------------------- -#include "catch_amalgamated.hpp" +#include "catch_all.hpp" #ifndef CATCH_WINDOWS_H_PROXY_HPP_INCLUDED diff --git a/Tests/Detour/Tests_Detour.cpp b/Tests/Detour/Tests_Detour.cpp index 0e7d30a..9c550d6 100644 --- a/Tests/Detour/Tests_Detour.cpp +++ b/Tests/Detour/Tests_Detour.cpp @@ -1,4 +1,4 @@ -#include "catch_amalgamated.hpp" +#include "catch2/catch_all.hpp" #include "DetourCommon.h" diff --git a/Tests/Recast/Tests_Recast.cpp b/Tests/Recast/Tests_Recast.cpp index 39ac430..eac837f 100644 --- a/Tests/Recast/Tests_Recast.cpp +++ b/Tests/Recast/Tests_Recast.cpp @@ -1,7 +1,7 @@ #include #include -#include "catch_amalgamated.hpp" +#include "catch2/catch_all.hpp" #include "Recast.h" #include "RecastAlloc.h" diff --git a/Tests/main.cpp b/Tests/main.cpp deleted file mode 100644 index c7810e3..0000000 --- a/Tests/main.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include "catch_amalgamated.hpp"