Browse Source

Refined test compilation

tastytea 2 months ago
parent
commit
dbb15bee87
Signed by: tastytea <tastytea@tastytea.de> GPG Key ID: CFC39497F1B26E07
1 changed files with 17 additions and 14 deletions
  1. 17
    14
      tests.CMakeLists.txt

+ 17
- 14
tests.CMakeLists.txt View File

@@ -1,24 +1,27 @@
1 1
 if(WITH_TESTS)
2
+    include(CTest)
3
+    file(GLOB sources_tests src/tests/test_*.cpp)
4
+
2 5
     find_package(Catch2)
3
-    if(Catch2_FOUND)
4
-        set(MYCATCH, Catch2::Catch2)
5
-    else()
6
+    if(Catch2_FOUND)    # Catch 2.x
7
+        include(Catch)
8
+        add_executable(all_tests src/tests/main.cpp ${sources_tests})
9
+        target_link_libraries(all_tests ${CMAKE_PROJECT_NAME} Catch2::Catch2)
10
+        target_include_directories(all_tests PRIVATE "/usr/include/catch2")
11
+        catch_discover_tests(all_tests)
12
+    else()              # Catch 1.x
6 13
         if(EXISTS "/usr/include/catch.hpp")
7 14
             message(STATUS "Catch 1.x found.")
8
-            set(MYCATCH, "")
15
+            foreach(src ${sources_tests})
16
+                get_filename_component(bin ${src} NAME_WE)
17
+                add_executable(${bin} src/tests/main.cpp ${src})
18
+                target_link_libraries(${bin} ${CMAKE_PROJECT_NAME})
19
+                target_include_directories(${bin} PRIVATE "/usr/include/catch2")
20
+                add_test(${bin} ${bin})
21
+            endforeach()
9 22
         else()
10 23
             message(FATAL_ERROR
11 24
                     "Neither Catch 2.x nor Catch 1.x could be found.")
12 25
         endif()
13 26
     endif()
14
-    include(CTest)
15
-
16
-    file(GLOB sources_tests src/tests/test_*.cpp)
17
-    foreach(src ${sources_tests})
18
-        get_filename_component(bin ${src} NAME_WE)
19
-        add_executable(${bin} src/tests/main.cpp ${src})
20
-        target_link_libraries(${bin} ${CMAKE_PROJECT_NAME} ${MYCATCH})
21
-        target_include_directories(${bin} PRIVATE "/usr/include/catch2")
22
-        add_test(${bin} ${bin})
23
-    endforeach()
24 27
 endif()

Loading…
Cancel
Save