Skip to content

Commit

Permalink
gtest dependency (#2163)
Browse files Browse the repository at this point in the history
Allow gtest to be external dependency, see also #1731
  • Loading branch information
boeschf authored Aug 4, 2023
1 parent 0f2a81b commit c899572
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ install(FILES mechanisms/BuildModules.cmake DESTINATION ${ARB_INSTALL_DATADIR})

cmake_dependent_option(ARB_USE_BUNDLED_FMT "Use bundled FMT lib." ON "ARB_USE_BUNDLED_LIBS" OFF)
cmake_dependent_option(ARB_USE_BUNDLED_PUGIXML "Use bundled XML lib." ON "ARB_USE_BUNDLED_LIBS" OFF)
cmake_dependent_option(ARB_USE_BUNDLED_GTEST "Use bundled GoogleTest." ON "ARB_USE_BUNDLED_LIBS" OFF)

cmake_dependent_option(ARB_USE_BUNDLED_JSON "Use bundled Niels Lohmann's json library." ON "ARB_USE_BUNDLED_LIBS" OFF)
if(NOT ARB_USE_BUNDLED_JSON)
Expand Down
39 changes: 25 additions & 14 deletions ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,29 @@ add_external_cmake_project(

# Google Test framework:

# Set up google test as an external project.
add_external_cmake_project(
NAME googletest
INTERFACE_NAME ext-gtest
LIB libgtest.a
CMAKE_ARGS
"-DCMAKE_BUILD_TYPE=release"
"-DBUILD_SHARED_LIBS=OFF"
"-DBUILD_GMOCK=OFF")

# on some systems we need link explicitly against threads
if (TARGET ext-gtest)
find_package (Threads)
target_link_libraries(ext-gtest INTERFACE Threads::Threads)
if (ARB_USE_BUNDLED_GTEST)
# Set up google test as an external project.
add_external_cmake_project(
NAME googletest
INTERFACE_NAME ext-gtest
LIB libgtest.a
CMAKE_ARGS
"-DCMAKE_BUILD_TYPE=release"
"-DBUILD_SHARED_LIBS=OFF"
"-DBUILD_GMOCK=OFF")

# on some systems we need link explicitly against threads
if (TARGET ext-gtest)
find_package (Threads)
target_link_libraries(ext-gtest INTERFACE Threads::Threads)
endif()
else()
# Use system provided google test
find_package(GTest)
add_library(ext-gtest INTERFACE)
if (${CMAKE_VERSION} VERSION_LESS "3.20.0")
target_link_libraries(ext-gtest INTERFACE GTest::GTest GTest::Main)
else()
target_link_libraries(ext-gtest INTERFACE GTest::gtest GTest::gtest_main)
endif()
endif()
2 changes: 1 addition & 1 deletion spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Arbor(CMakePackage, CudaPackage):
# misc dependencies
depends_on("[email protected]:", when="@0.5.3:") # required by the modcc compiler
depends_on("[email protected]:", when="@0.7.1:")
depends_on("[email protected]", type="test", when="@0.7.1:")
depends_on("[email protected]", when="@0.7.1:")
depends_on("[email protected]:", when="@0.7.1:")
depends_on("nlohmann-json")
depends_on("random123")
Expand Down

0 comments on commit c899572

Please sign in to comment.