1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ include (FetchContent)
16+
17+ fetchcontent_declare(googletest
18+ GIT_REPOSITORY
19+ https://github.com/abseil/googletest
20+ GIT_TAG
21+ ed2fe122f8dc9aca844d724986d1d5cf5b65ea4e)
22+ fetchcontent_declare(abseil
23+ GIT_REPOSITORY
24+ https://github.com/abseil/abseil-cpp
25+ GIT_TAG
26+ master)
27+ fetchcontent_declare(prometheus
28+ GIT_REPOSITORY
29+ https://github.com/jupp0r/prometheus-cpp
30+ GIT_TAG
31+ master)
32+
33+ fetchcontent_getproperties(googletest)
1534if (BUILD_TESTING)
16- if (NOT TARGET gtest_main)
17- message (STATUS "Dependency: googletest (BUILD_TESTING=${BUILD_TESTING} )" )
35+ message (STATUS "Dependency: googletest (BUILD_TESTING=${BUILD_TESTING} )" )
1836
37+ if (NOT googletest_POPULATED)
1938 if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "MSVC" )
2039 # All the libraries in the build must use either /MD or /MT (runtime
2140 # library to link)
@@ -29,73 +48,27 @@ if(BUILD_TESTING)
2948 ON )
3049 endif ()
3150
32- configure_file (${CMAKE_CURRENT_SOURCE_DIR} /cmake/googletest.CMakeLists.txt
33- ${CMAKE_BINARY_DIR} /googletest-download/CMakeLists.txt)
34- execute_process (COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR} " .
35- RESULT_VARIABLE result
36- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /googletest-download)
37- if (result)
38- message (FATAL_ERROR "CMake step failed: ${result} " )
39- endif ()
40- execute_process (COMMAND ${CMAKE_COMMAND} --build .
41- RESULT_VARIABLE result
42- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /googletest-download)
43- if (result)
44- message (FATAL_ERROR "Build step failed: ${result} " )
45- endif ()
46-
47- add_subdirectory (${CMAKE_BINARY_DIR} /googletest-src
48- ${CMAKE_BINARY_DIR} /googletest-build EXCLUDE_FROM_ALL )
51+ fetchcontent_populate(googletest)
52+ add_subdirectory (${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}
53+ EXCLUDE_FROM_ALL )
4954 endif ()
5055endif ()
5156
52- # Load abseil second, it depends on googletest.
53- if (NOT TARGET absl::base)
54- message (STATUS "Dependency: abseil" )
55-
56- configure_file (${CMAKE_CURRENT_SOURCE_DIR} /cmake/abseil.CMakeLists.txt
57- ${CMAKE_BINARY_DIR} /abseil-download/CMakeLists.txt)
58- execute_process (COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR} " .
59- RESULT_VARIABLE result
60- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /abseil-download)
61- if (result)
62- message (FATAL_ERROR "CMake step failed: ${result} " )
63- endif ()
64- execute_process (COMMAND ${CMAKE_COMMAND} --build .
65- RESULT_VARIABLE result
66- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /abseil-download)
67- if (result)
68- message (FATAL_ERROR "Build step failed: ${result} " )
69- endif ()
70-
71- add_subdirectory (${CMAKE_BINARY_DIR} /abseil-src
72- ${CMAKE_BINARY_DIR} /abseil-build EXCLUDE_FROM_ALL )
57+ fetchcontent_getproperties(abseil)
58+ if (NOT abseil_POPULATED)
59+ fetchcontent_populate(abseil)
60+ add_subdirectory (${abseil_SOURCE_DIR} ${abseil_BINARY_DIR} EXCLUDE_FROM_ALL )
7361endif ()
7462
75- if (NOT TARGET prometheus-cpp::core)
76- message (STATUS "Dependency: prometheus-cpp" )
77-
78- configure_file (${CMAKE_CURRENT_SOURCE_DIR} /cmake/prometheus-cpp.CMakeLists.txt
79- ${CMAKE_BINARY_DIR} /prometheus-download/CMakeLists.txt)
80- execute_process (COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR} " .
81- RESULT_VARIABLE result
82- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /prometheus-download)
83- if (result)
84- message (FATAL_ERROR "CMake step failed: ${result} " )
85- endif ()
86- execute_process (COMMAND ${CMAKE_COMMAND} --build .
87- RESULT_VARIABLE result
88- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /prometheus-download)
89- if (result)
90- message (FATAL_ERROR "Build step failed: ${result} " )
91- endif ()
92-
63+ fetchcontent_getproperties(prometheus)
64+ if (NOT prometheus_POPULATED)
9365 set (ENABLE_PUSH OFF CACHE BOOL "Build prometheus-cpp push library" FORCE)
9466 set (ENABLE_PULL OFF CACHE BOOL "Build prometheus-cpp pull library" FORCE)
9567 set (ENABLE_COMPRESSION OFF
9668 CACHE BOOL "Enable gzip compression for prometheus-cpp"
9769 FORCE)
9870 set (ENABLE_TESTING OFF CACHE BOOL "Build test for prometheus-cpp" FORCE)
99- add_subdirectory (${CMAKE_BINARY_DIR} /prometheus-src
100- ${CMAKE_BINARY_DIR} /prometheus-build EXCLUDE_FROM_ALL )
71+ fetchcontent_populate(prometheus)
72+ add_subdirectory (${prometheus_SOURCE_DIR} ${prometheus_BINARY_DIR}
73+ EXCLUDE_FROM_ALL )
10174endif ()
0 commit comments