diff --git a/.gitignore b/.gitignore index 02da815..134a7dc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ build/ *.swp compile_commands.json .vscode/ +.idea +cmake-build-debug \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b77565..f5df727 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.14) project(dense_hash_map) +string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level) +option(DENSE_HASH_MAP_BUILD_TEST "Build Dense Hash Map tests" ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -9,5 +11,7 @@ add_library(dense_hash_map INTERFACE) target_include_directories(dense_hash_map INTERFACE include/) add_library(JGuegant::dense_hash_map ALIAS dense_hash_map) -add_subdirectory(thirdparty/catch2) -add_subdirectory(tests) +if (is_top_level OR ${DENSE_HASH_MAP_BUILD_TEST}) + add_subdirectory(thirdparty/catch2_ext) + add_subdirectory(tests) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1842019..7be9925 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,8 +5,8 @@ project(dense_hash_map_tests) option(ENABLE_ASAN "Enable ASAN during the tests" OFF) option(ENABLE_UBASAN "Enable UBASAN during the tests" OFF) -add_executable(dense_hash_map_tests src/dense_hash_map_tests) -target_link_libraries(dense_hash_map_tests Catch2::Catch2) +add_executable(dense_hash_map_tests src/dense_hash_map_tests.cpp) +target_link_libraries(dense_hash_map_tests Catch2::Catch2WithMain) target_link_libraries(dense_hash_map_tests dense_hash_map) if(MSVC) diff --git a/tests/src/dense_hash_map_tests.cpp b/tests/src/dense_hash_map_tests.cpp index f73bf76..5e6dead 100644 --- a/tests/src/dense_hash_map_tests.cpp +++ b/tests/src/dense_hash_map_tests.cpp @@ -1,6 +1,6 @@ #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file -#include "catch2/catch.hpp" +#include #include "jg/dense_hash_map.hpp" #include "jg/details/type_traits.hpp" diff --git a/thirdparty/catch2 b/thirdparty/catch2 deleted file mode 160000 index 59d2d08..0000000 --- a/thirdparty/catch2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 59d2d08c0fb1a65c5a9acee4aa4a8b8bcc0bb140 diff --git a/thirdparty/catch2_ext/CMakeLists.txt b/thirdparty/catch2_ext/CMakeLists.txt new file mode 100644 index 0000000..677e801 --- /dev/null +++ b/thirdparty/catch2_ext/CMakeLists.txt @@ -0,0 +1,12 @@ +include(FetchContent) +FetchContent_Declare( + Catch2 + GIT_SHALLOW TRUE + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.6.0) +FetchContent_MakeAvailable(Catch2) + +# For catch 2 only +list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/contrib) +# For catch 3 only +# list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras) \ No newline at end of file