@@ -23,6 +23,9 @@ OPTION(CPUINFO_BUILD_UNIT_TESTS "Build cpuinfo unit tests" ON)
23
23
OPTION (CPUINFO_BUILD_MOCK_TESTS "Build cpuinfo mock tests" ON )
24
24
OPTION (CPUINFO_BUILD_BENCHMARKS "Build cpuinfo micro-benchmarks" ON )
25
25
OPTION (CPUINFO_BUILD_PKG_CONFIG "Build pkg-config manifest" ON )
26
+ OPTION (USE_SYSTEM_LIBS "Use system libraries instead of downloading and building them" OFF )
27
+ OPTION (USE_SYSTEM_GOOGLEBENCHMARK "Use system Google Benchmark library instead of downloading and building it" ${USE_SYSTEM_LIBS} )
28
+ OPTION (USE_SYSTEM_GOOGLETEST "Use system Google Test library instead of downloading and building it" ${USE_SYSTEM_LIBS} )
26
29
27
30
# ---[ CMake options
28
31
INCLUDE (GNUInstallDirs)
@@ -117,8 +120,10 @@ SET(CONFU_DEPENDENCIES_SOURCE_DIR ${CMAKE_SOURCE_DIR}/deps
117
120
SET (CONFU_DEPENDENCIES_BINARY_DIR ${CMAKE_BINARY_DIR} /deps
118
121
CACHE PATH "Confu-style dependencies binary directory" )
119
122
120
- IF (CPUINFO_BUILD_MOCK_TESTS OR CPUINFO_BUILD_UNIT_TESTS)
121
- IF (CPUINFO_SUPPORTED_PLATFORM AND NOT DEFINED GOOGLETEST_SOURCE_DIR)
123
+ IF (CPUINFO_SUPPORTED_PLATFORM AND (CPUINFO_BUILD_MOCK_TESTS OR CPUINFO_BUILD_UNIT_TESTS))
124
+ IF (USE_SYSTEM_GOOGLETEST)
125
+ FIND_PACKAGE (GTest REQUIRED)
126
+ ELSEIF (NOT DEFINED GOOGLETEST_SOURCE_DIR)
122
127
MESSAGE (STATUS "Downloading Google Test to ${CONFU_DEPENDENCIES_SOURCE_DIR} /googletest (define GOOGLETEST_SOURCE_DIR to avoid it)" )
123
128
CONFIGURE_FILE (cmake/DownloadGoogleTest.cmake "${CONFU_DEPENDENCIES_BINARY_DIR} /googletest-download/CMakeLists.txt" )
124
129
EXECUTE_PROCESS (COMMAND "${CMAKE_COMMAND} " -G "${CMAKE_GENERATOR} " .
@@ -129,8 +134,10 @@ IF(CPUINFO_BUILD_MOCK_TESTS OR CPUINFO_BUILD_UNIT_TESTS)
129
134
ENDIF ()
130
135
ENDIF ()
131
136
132
- IF (CPUINFO_BUILD_BENCHMARKS)
133
- IF (CPUINFO_SUPPORTED_PLATFORM AND NOT DEFINED GOOGLEBENCHMARK_SOURCE_DIR)
137
+ IF (CPUINFO_SUPPORTED_PLATFORM AND CPUINFO_BUILD_BENCHMARKS)
138
+ IF (USE_SYSTEM_GOOGLEBENCHMARK)
139
+ FIND_PACKAGE (benchmark REQUIRED)
140
+ ELSEIF (NOT DEFINED GOOGLEBENCHMARK_SOURCE_DIR)
134
141
MESSAGE (STATUS "Downloading Google Benchmark to ${CONFU_DEPENDENCIES_SOURCE_DIR} /googlebenchmark (define GOOGLEBENCHMARK_SOURCE_DIR to avoid it)" )
135
142
CONFIGURE_FILE (cmake/DownloadGoogleBenchmark.cmake "${CONFU_DEPENDENCIES_BINARY_DIR} /googlebenchmark-download/CMakeLists.txt" )
136
143
EXECUTE_PROCESS (COMMAND "${CMAKE_COMMAND} " -G "${CMAKE_GENERATOR} " .
@@ -308,7 +315,7 @@ INSTALL(EXPORT cpuinfo-targets
308
315
# ---[ cpuinfo micro-benchmarks
309
316
IF (CPUINFO_SUPPORTED_PLATFORM AND CPUINFO_BUILD_BENCHMARKS)
310
317
# ---[ Build google benchmark
311
- IF (NOT TARGET benchmark)
318
+ IF (NOT TARGET benchmark AND NOT USE_SYSTEM_GOOGLEBENCHMARK )
312
319
SET (BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" )
313
320
ADD_SUBDIRECTORY (
314
321
"${GOOGLEBENCHMARK_SOURCE_DIR} "
@@ -327,7 +334,7 @@ ENDIF()
327
334
IF (CPUINFO_SUPPORTED_PLATFORM)
328
335
IF (CPUINFO_BUILD_MOCK_TESTS OR CPUINFO_BUILD_UNIT_TESTS)
329
336
# ---[ Build google test
330
- IF (NOT TARGET gtest)
337
+ IF (NOT TARGET gtest AND NOT USE_SYSTEM_GOOGLETEST )
331
338
IF (MSVC AND NOT CPUINFO_RUNTIME_TYPE STREQUAL "static" )
332
339
SET (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
333
340
ENDIF ()
0 commit comments