diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/dmclock/cmake | |
parent | Initial commit. (diff) | |
download | ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/dmclock/cmake/modules/BuildGTest.cmake | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/dmclock/cmake/modules/BuildGTest.cmake b/src/dmclock/cmake/modules/BuildGTest.cmake new file mode 100644 index 000000000..2b3f2ae52 --- /dev/null +++ b/src/dmclock/cmake/modules/BuildGTest.cmake @@ -0,0 +1,71 @@ +macro(_build_gtest gtest_root) + include(ExternalProject) + ExternalProject_Add(googletest + SOURCE_DIR ${gtest_root} + CMAKE_ARGS -DBUILD_GMOCK=OFF -DBUILD_GTEST=ON + INSTALL_COMMAND "" + LOG_CONFIGURE ON + LOG_BUILD ON) + + ExternalProject_Get_Property(googletest source_dir) + find_path(GTEST_INCLUDE_DIRS + NAMES gtest/gtest.h + PATHS ${source_dir}/googletest/include /usr/include) + find_path(GMOCK_INCLUDE_DIRS + NAMES gmock/gmock.h + PATHS ${source_dir}/googlemock/include /usr/include) + + find_package(Threads REQUIRED) + + ExternalProject_Get_Property(googletest binary_dir) + set(GTEST_LIBRARY_PATH ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a) + set(GTEST_LIBRARY GTest::GTest) + add_library(${GTEST_LIBRARY} STATIC IMPORTED) + set_target_properties(${GTEST_LIBRARY} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIRS}" + IMPORTED_LOCATION ${GTEST_LIBRARY_PATH} + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LINK_INTERFACE_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + add_dependencies(${GTEST_LIBRARY} googletest) + set(GTEST_LIBRARIES ${GTEST_LIBRARY}) + + set(GTEST_MAIN_LIBRARY_PATH ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a) + set(GTEST_MAIN_LIBRARY GTest::Main) + add_library(${GTEST_MAIN_LIBRARY} STATIC IMPORTED) + set_target_properties(${GTEST_MAIN_LIBRARY} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIRS}" + IMPORTED_LOCATION ${GTEST_MAIN_LIBRARY_PATH} + IMPORTED_LINK_INTERFACE_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + add_dependencies(${GTEST_MAIN_LIBRARY} googletest) + + set(GMOCK_LIBRARY_PATH ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gmock.a) + set(GMOCK_LIBRARY GMock::GMock) + add_library(${GMOCK_LIBRARY} STATIC IMPORTED) + set_target_properties(${GMOCK_LIBRARY} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GMOCK_INCLUDE_DIRS}" + IMPORTED_LOCATION "${GMOCK_LIBRARY_PATH}" + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LINK_INTERFACE_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + add_dependencies(${GMOCK_LIBRARY} googletest) + + set(GMOCK_MAIN_LIBRARY_PATH ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gmock_main.a) + set(GMOCK_MAIN_LIBRARY GMock::Main) + add_library(${GMOCK_MAIN_LIBRARY} STATIC IMPORTED) + set_target_properties(${GMOCK_MAIN_LIBRARY} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GMOCK_INCLUDE_DIRS}" + IMPORTED_LOCATION ${GMOCK_MAIN_LIBRARY_PATH} + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LINK_INTERFACE_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + add_dependencies(${GMOCK_MAIN_LIBRARY} ${GTEST_LIBRARY}) +endmacro() + +find_path(GTEST_ROOT src/gtest.cc + HINTS $ENV{GTEST_ROOT} + PATHS /usr/src/googletest/googletest /usr/src/gtest) + +if(EXISTS ${GTEST_ROOT}) + message(STATUS "Found googletest: ${GTEST_ROOT}") + _build_gtest(${GTEST_ROOT}) +else() + message(SEND_ERROR "Could NOT find googletest") +endif() |