[Infra] Fix version-check workflow (#100090)
[llvm-project.git] / third-party / benchmark / cmake / GoogleTest.cmake
blobe66e9d1a2076ea6ae56a01f63ab52e1e78ce4826
1 # Download and unpack googletest at configure time
2 set(GOOGLETEST_PREFIX "${benchmark_BINARY_DIR}/third_party/googletest")
3 configure_file(${benchmark_SOURCE_DIR}/cmake/GoogleTest.cmake.in ${GOOGLETEST_PREFIX}/CMakeLists.txt @ONLY)
5 set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/googletest" CACHE PATH "") # Mind the quotes
6 execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
7   -DALLOW_DOWNLOADING_GOOGLETEST=${BENCHMARK_DOWNLOAD_DEPENDENCIES} -DGOOGLETEST_PATH:PATH=${GOOGLETEST_PATH} .
8   RESULT_VARIABLE result
9   WORKING_DIRECTORY ${GOOGLETEST_PREFIX}
12 if(result)
13   message(FATAL_ERROR "CMake step for googletest failed: ${result}")
14 endif()
16 execute_process(
17   COMMAND ${CMAKE_COMMAND} --build .
18   RESULT_VARIABLE result
19   WORKING_DIRECTORY ${GOOGLETEST_PREFIX}
22 if(result)
23   message(FATAL_ERROR "Build step for googletest failed: ${result}")
24 endif()
26 # Prevent overriding the parent project's compiler/linker
27 # settings on Windows
28 set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
30 include(${GOOGLETEST_PREFIX}/googletest-paths.cmake)
32 # Add googletest directly to our build. This defines
33 # the gtest and gtest_main targets.
34 add_subdirectory(${GOOGLETEST_SOURCE_DIR}
35                  ${GOOGLETEST_BINARY_DIR}
36                  EXCLUDE_FROM_ALL)
38 # googletest doesn't seem to want to stay build warning clean so let's not hurt ourselves.
39 if (MSVC)
40   target_compile_options(gtest PRIVATE "/wd4244" "/wd4722")
41   target_compile_options(gtest_main PRIVATE "/wd4244" "/wd4722")
42   target_compile_options(gmock PRIVATE "/wd4244" "/wd4722")
43   target_compile_options(gmock_main PRIVATE "/wd4244" "/wd4722")
44 else()
45   target_compile_options(gtest PRIVATE "-w")
46   target_compile_options(gtest_main PRIVATE "-w")
47   target_compile_options(gmock PRIVATE "-w")
48   target_compile_options(gmock_main PRIVATE "-w")
49 endif()
51 if(NOT DEFINED GTEST_COMPILE_COMMANDS)
52     set(GTEST_COMPILE_COMMANDS ON)
53 endif()
55 set_target_properties(gtest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})
56 set_target_properties(gtest_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest_main,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})
57 set_target_properties(gmock PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})
58 set_target_properties(gmock_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock_main,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})