From 850bf1a94932ca9dd2c7c59c6a048ff5138d318d Mon Sep 17 00:00:00 2001 From: JosiahWI Date: Tue, 31 Jan 2023 08:42:35 -0600 Subject: [PATCH] Register Catch2 tests with CTest --- CMakeLists.txt | 4 ++++ README.md | 14 ++++++++++++++ source/Irrlicht/CMakeLists.txt | 4 +++- source/Irrlicht/tests/CMakeLists.txt | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 30e35d6f..6b0b2aab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,10 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE) endif() +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) +endif() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") add_subdirectory(source/lib/catch2) add_subdirectory(source/lib/tinygltf) diff --git a/README.md b/README.md index 0d17e194..76c174b3 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ The following libraries are required to be installed: Aside from standard search options (`ZLIB_INCLUDE_DIR`, `ZLIB_LIBRARY`, ...) the following options are available: * `BUILD_SHARED_LIBS` (default: `ON`) - Build IrrlichtMt as a shared library * `BUILD_EXAMPLES` (default: `OFF`) - Build example applications +* `BUILD_TESTING` (default: `ON`) - Build Catch2 tests e.g. on a Linux system you might want to build for local use like this: @@ -44,6 +45,19 @@ Run the following script in PowerShell: cd irrlicht cmake -B build -G "Visual Studio 17 2022" -A "Win64" -DCMAKE_TOOLCHAIN_FILE=[vcpkg-root]/scripts/buildsystems/vcpkg.cmake -DBUILD_SHARED_LIBS=OFF cmake --build build --config Release + +Test +---- + +To run the Catch2 tests, the project must first be built with `BUILD_TESTING` enabled. + +The tests can be run with ctest: + + cd build + ctest + +Run the tests directly for more detailed output: + build/bin//tests Platforms --------- diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index bf9501cd..d833d0f7 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -309,7 +309,9 @@ if(WIN32) set_target_properties(IrrlichtMt PROPERTIES PREFIX "") # for DLL name endif() -add_subdirectory(tests) +if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) AND BUILD_TESTING) + add_subdirectory(tests) +endif() # Installation of library if(ANDROID) diff --git a/source/Irrlicht/tests/CMakeLists.txt b/source/Irrlicht/tests/CMakeLists.txt index cef86516..17c1092f 100644 --- a/source/Irrlicht/tests/CMakeLists.txt +++ b/source/Irrlicht/tests/CMakeLists.txt @@ -18,3 +18,9 @@ target_link_libraries(tests Catch2::Catch IrrlichtMt::IrrlichtMt ) + +add_test( + NAME tests + COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" +)