@@ -13,11 +13,9 @@ set(META_PROJECT_NAME "glkernel")
13
13
project ("${META_PROJECT_NAME} -tests" C CXX)
14
14
15
15
# Set policies
16
- set_policy(CMP0028 NEW) # ENABLE CMP0028: Double colon in target name means ALIAS or IMPORTED target.
17
16
set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted.
18
17
set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default.
19
18
set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types.
20
- set_policy(CMP0037 OLD) # DISABLE CMP0037: Target names should not be reserved and should match a validity pattern.
21
19
22
20
# Compiler settings and options
23
21
@@ -41,40 +39,31 @@ function(add_test_without_ctest target)
41
39
42
40
add_dependencies (test ${target} )
43
41
add_custom_command (TARGET test POST_BUILD
44
- COMMAND $<TARGET_FILE:${target} > --gtest_output=xml:gtests-${target} .xml)
42
+ COMMAND $<TARGET_FILE:${target} > --gtest_output=xml:gtests-${target} .xml
43
+ )
45
44
endfunction ()
46
45
47
- # Build gmock
48
- set (gmock_build_tests OFF CACHE BOOL "" )
49
- set (gtest_build_samples OFF CACHE BOOL "" )
50
- set (gtest_build_tests OFF CACHE BOOL "" )
51
- set (gtest_disable_pthreads OFF CACHE BOOL "" )
52
- set (gtest_force_shared_crt ON CACHE BOOL "" )
53
- set (gtest_hide_internal_symbols OFF CACHE BOOL "" )
54
-
55
- add_subdirectory (googletest/googlemock)
56
-
57
- # Create interface library to link against gmock
58
- add_library (gmock-dev INTERFACE )
59
-
60
- target_include_directories (gmock-dev
61
- SYSTEM INTERFACE
62
- ${CMAKE_CURRENT_SOURCE_DIR} /googletest/googletest/include
63
- ${CMAKE_CURRENT_SOURCE_DIR} /googletest/googlemock/include
64
- )
65
-
66
- target_link_libraries (gmock-dev
67
- INTERFACE
68
- gmock
69
- )
46
+ find_package (googletest QUIET )
70
47
48
+ if (NOT TARGET googletest::googletest)
49
+ message (STATUS "Tests skipped: googletest not found" )
50
+ return ()
51
+ endif ()
71
52
72
53
#
73
54
# Target 'test'
74
55
#
75
56
76
- add_custom_target (test )
77
- set_target_properties (test PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
57
+ if (${CMAKE_VERSION} VERSION_LESS "3.11" )
58
+ set_policy(CMP0037 OLD) # DISABLE CMP0037: Target names should be reserved and should match a validity pattern.
59
+ add_custom_target (test )
60
+ set_target_properties (test PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
61
+ else ()
62
+ if (NOT TARGET test )
63
+ add_custom_target (test )
64
+ set_target_properties (test PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
65
+ endif ()
66
+ endif ()
78
67
79
68
80
69
#
0 commit comments