|
1 | | -# gtest external download |
2 | | -set(EXTERNAL_DIR "${CLEAVER2_BINARY_DIR}/externals") |
3 | | -set(GTEST_INSTALL_DIR "${EXTERNAL_DIR}/googletest") |
4 | | -if(WIN32) |
5 | | - set(GTEST_SHARED_ARG ON) |
6 | | -else() |
7 | | - set(GTEST_SHARED_ARG OFF) |
8 | | -endif() |
9 | | - |
10 | | -include(ExternalProject) |
11 | | - |
12 | | -set(googletest_GIT_TAG "origin/cleaver") |
13 | | - |
14 | | -set(debug_suffix ) |
15 | | -if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") |
16 | | - set(debug_suffix d) |
17 | | -endif() |
18 | | - |
19 | | -set(_ep_arg_build_byproducts) |
20 | | -if("${CMAKE_GENERATOR}" STREQUAL "Ninja") |
21 | | - set(_build_byproducts "") |
22 | | - if(WIN32) |
23 | | - foreach(_lib IN ITEMS gtest gtest_main gmock gmock_main) |
24 | | - list(APPEND _build_byproducts |
25 | | - ${GTEST_INSTALL_DIR}/lib/lib/${CMAKE_FIND_LIBRARY_PREFIXES}${_lib}${debug_suffix}${CMAKE_STATIC_LIBRARY_SUFFIX}) |
26 | | - endforeach() |
27 | | - else() |
28 | | - foreach(_lib IN ITEMS gtest gtest_main gmock gmock_main) |
29 | | - list(APPEND _build_byproducts ${GTEST_INSTALL_DIR}/lib/lib/${CMAKE_FIND_LIBRARY_PREFIXES}${_lib}${debug_suffix}${CMAKE_STATIC_LIBRARY_SUFFIX}) |
30 | | - endforeach() |
31 | | - endif() |
32 | | - set(_ep_arg_build_byproducts BUILD_BYPRODUCTS ${_build_byproducts}) |
33 | | -endif() |
34 | | - |
35 | | -set(_cmake_cache_args) |
36 | | -if(DEFINED CMAKE_BUILD_TYPE) |
37 | | - list(APPEND _cmake_cache_args -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}) |
38 | | -endif() |
39 | | -ExternalProject_Add(googletest |
40 | | - PREFIX "${GTEST_INSTALL_DIR}" |
41 | | - GIT_REPOSITORY "https://github.com/CIBC-Internal/googletest.git" |
42 | | - GIT_TAG ${googletest_GIT_TAG} |
43 | | - CMAKE_CACHE_ARGS |
44 | | - ${_cmake_cache_args} |
45 | | - INSTALL_DIR "${GTEST_INSTALL_DIR}/include" |
46 | | - BINARY_DIR "${GTEST_INSTALL_DIR}/lib" |
47 | | - INSTALL_COMMAND "" |
48 | | - ${_ep_arg_build_byproducts} |
49 | | - CMAKE_ARGS |
50 | | - -DCMAKE_CXX_FLAGS=-Wno-error=maybe-uninitialized |
51 | | - -DCMAKE_C_FLAGS=-Wno-error=maybe-uninitialized |
52 | | -) |
53 | | - |
54 | | -# Copy and Specify Include Directory |
55 | | -ExternalProject_Get_Property(googletest source_dir) |
56 | | -ExternalProject_Add_Step( |
57 | | - googletest |
58 | | - copy_deps |
59 | | - COMMAND ${CMAKE_COMMAND} -E copy_directory ${source_dir}/googletest/include ${GTEST_INSTALL_DIR}/include |
60 | | - COMMAND ${CMAKE_COMMAND} -E copy_directory ${source_dir}/googlemock/include ${GTEST_INSTALL_DIR}/include |
61 | | - DEPENDEES install |
| 1 | +# Fetch googletest via FetchContent (replaces CIBC-Internal/googletest ExternalProject) |
| 2 | +include(FetchContent) |
| 3 | +FetchContent_Declare( |
| 4 | + googletest |
| 5 | + GIT_REPOSITORY https://github.com/google/googletest.git |
| 6 | + GIT_TAG v1.15.2 |
62 | 7 | ) |
63 | | -include_directories("${GTEST_INSTALL_DIR}/include") |
64 | | - |
65 | | -# Set up library paths |
66 | | -set(GTEST_LIBRARY gtest) |
67 | | -add_library(${GTEST_LIBRARY} UNKNOWN IMPORTED) |
68 | | -ExternalProject_Get_Property(googletest binary_dir) |
69 | | -if(NOT WIN32) |
70 | | - set(GTEST_LIBRARY_PATH_OTHER ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtest${debug_suffix}${CMAKE_STATIC_LIBRARY_SUFFIX}) |
71 | | - set_target_properties(${GTEST_LIBRARY} PROPERTIES IMPORTED_LOCATION ${GTEST_LIBRARY_PATH_OTHER}) |
72 | | -endif() |
73 | | -add_dependencies(${GTEST_LIBRARY} googletest) |
74 | | - |
75 | | -set(GTEST_MAIN_LIBRARY gtest_main) |
76 | | -add_library(${GTEST_MAIN_LIBRARY} UNKNOWN IMPORTED) |
77 | | -if(NOT WIN32) |
78 | | - set(GTEST_MAIN_LIBRARY_PATH_OTHER ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main${debug_suffix}${CMAKE_STATIC_LIBRARY_SUFFIX}) |
79 | | - set_target_properties(${GTEST_MAIN_LIBRARY} PROPERTIES IMPORTED_LOCATION ${GTEST_MAIN_LIBRARY_PATH_OTHER}) |
80 | | -endif() |
81 | | -add_dependencies(${GTEST_MAIN_LIBRARY} googletest) |
82 | | - |
83 | | -set(GMOCK_LIBRARY gmock) |
84 | | -add_library(${GMOCK_LIBRARY} UNKNOWN IMPORTED) |
85 | | -if(NOT WIN32) |
86 | | - set(GMOCK_LIBRARY_PATH_OTHER ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gmock${debug_suffix}${CMAKE_STATIC_LIBRARY_SUFFIX}) |
87 | | - set_target_properties(${GMOCK_LIBRARY} PROPERTIES IMPORTED_LOCATION ${GMOCK_LIBRARY_PATH_OTHER}) |
88 | | -endif() |
89 | | -add_dependencies(${GMOCK_LIBRARY} googletest) |
90 | | - |
91 | | -set(GMOCK_MAIN_LIBRARY gmock_main) |
92 | | -add_library(${GMOCK_MAIN_LIBRARY} UNKNOWN IMPORTED) |
93 | | -if(NOT WIN32) |
94 | | - set(GMOCK_MAIN_LIBRARY_PATH_OTHER ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gmock_main${debug_suffix}${CMAKE_STATIC_LIBRARY_SUFFIX}) |
95 | | - set_target_properties(${GMOCK_MAIN_LIBRARY} PROPERTIES IMPORTED_LOCATION ${GMOCK_MAIN_LIBRARY_PATH_OTHER}) |
96 | | -endif() |
97 | | -add_dependencies(${GMOCK_MAIN_LIBRARY} ${GTEST_LIBRARY}) |
98 | | - |
| 8 | +# Prevent googletest from overriding our compiler/linker options |
| 9 | +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 10 | +set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) |
| 11 | +FetchContent_MakeAvailable(googletest) |
99 | 12 |
|
100 | 13 | # Definitions for Tests |
101 | 14 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CLEAVER2_BINARY_DIR}/test/bin) |
102 | | -#test macro |
| 15 | + |
| 16 | +# test macro |
103 | 17 | function(NEWTEST name) |
104 | 18 | add_executable(${name} ${name}.cpp ${ARGN}) |
105 | | - if(NOT WIN32) |
106 | | - target_link_libraries(${name} ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} cleaver -lpthread) |
107 | | - else () |
108 | | - if (CMAKE_CONFIGURATION_TYPES) |
109 | | - target_link_libraries(${name} |
110 | | - ${binary_dir}/lib/$<CONFIG>/${CMAKE_FIND_LIBRARY_PREFIXES}gtest$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX} |
111 | | - ${binary_dir}/lib/$<CONFIG>/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX} |
112 | | - ${binary_dir}/lib/$<CONFIG>/${CMAKE_FIND_LIBRARY_PREFIXES}gmock$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX} |
113 | | - ${binary_dir}/lib/$<CONFIG>/${CMAKE_FIND_LIBRARY_PREFIXES}gmock_main$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX} |
114 | | - cleaver ) |
115 | | - else() |
116 | | - # Ninja |
117 | | - target_link_libraries(${name} |
118 | | - ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtest$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX} |
119 | | - ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX} |
120 | | - ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gmock$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX} |
121 | | - ${binary_dir}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gmock_main$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX} |
122 | | - cleaver ) |
123 | | - endif() |
124 | | - endif() |
125 | | - add_test(${name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${name}) |
126 | | - add_dependencies(${name} gtest gtest_main cleaver) |
| 19 | + target_link_libraries(${name} GTest::gtest_main GTest::gmock cleaver) |
| 20 | + add_test(NAME ${name} COMMAND ${name}) |
127 | 21 | endfunction() |
128 | 22 |
|
129 | 23 | add_subdirectory(cleaver) |
|
0 commit comments