--- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,7 @@ option(BUILD_TESTS "Build test suite" OFF) option(ENABLE_ASAN_PACKAGING "" OFF) option(ENABLE_ESMI_LIB "Build ESMI Library" ON) option(BUILD_EXAMPLES "Build examples" OFF) +option(USE_SYSTEM_GTEST "Use system-installed googletest instead of fetching it" OFF) include(CMakeDependentOption) # these options don't work without BUILD_SHARED_LIBS --- a/tests/amd_smi_test/CMakeLists.txt +++ b/tests/amd_smi_test/CMakeLists.txt @@ -6,10 +6,14 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--enable-new-dtags") set(CMAKE_INSTALL_RPATH "\$ORIGIN:\$ORIGIN/../../../lib" CACHE STRING "RUNPATH for tests. Helps find libgtest.so and libamd_smi.so") -# Download and compile googletest -include(FetchContent) -FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.14.0) -FetchContent_MakeAvailable(googletest) +if(USE_SYSTEM_GTEST) + find_package(GTest 1.14.0 REQUIRED) +else() + # Download and compile googletest + include(FetchContent) + FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.14.0) + FetchContent_MakeAvailable(googletest) +endif() enable_testing() @@ -63,8 +67,10 @@ install( DESTINATION ${SHARE_INSTALL_PREFIX}/tests COMPONENT ${TESTS_COMPONENT}) -# Install googletest libraries with tests -install( - TARGETS gtest gtest_main - DESTINATION ${SHARE_INSTALL_PREFIX}/tests - COMPONENT ${TESTS_COMPONENT}) +if(NOT USE_SYSTEM_GTEST) + # Install googletest libraries with tests + install( + TARGETS gtest gtest_main + DESTINATION ${SHARE_INSTALL_PREFIX}/tests + COMPONENT ${TESTS_COMPONENT}) +endif()