Skip to content
Snippets Groups Projects
Commit 21b6127d authored by webmanue's avatar webmanue
Browse files

customize finding googletest

- use source at /usr/src/googletest if not found
- automatically builds library in dev environment
parent 9d4a649c
No related branches found
No related tags found
No related merge requests found
Pipeline #91911 passed
# © 2021 ETH Zurich, Mechanics and Materials Lab
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
find_package(GTest 1.8.1 CONFIG)
if (NOT GTest_FOUND)
set(FETCHCONTENT_SOURCE_DIR_AE108_GOOGLETEST "/usr/src/googletest")
if (IS_DIRECTORY "${FETCHCONTENT_SOURCE_DIR_AE108_GOOGLETEST}")
message(STATUS
"GTest was not found, using source at ${FETCHCONTENT_SOURCE_DIR_AE108_GOOGLETEST} instead."
)
include(FetchContent)
FetchContent_Declare("ae108_googletest")
FetchContent_GetProperties(
ae108_googletest
SOURCE_DIR ae108_googletest_SOURCE_DIR
BINARY_DIR ae108_googletest_BINARY_DIR
POPULATED ae108_googletest_POPULATED
)
if (NOT ae108_googletest_POPULATED)
FetchContent_Populate("ae108_googletest")
add_subdirectory(
"${ae108_googletest_SOURCE_DIR}"
"${ae108_googletest_BINARY_DIR}"
EXCLUDE_FROM_ALL
)
endif()
foreach(LIBRARY_NAME gtest gmock gtest_main gmock_main)
add_library("GTest::${LIBRARY_NAME}" ALIAS "${LIBRARY_NAME}")
endforeach()
set(GTest_FOUND TRUE)
endif()
endif()
find_package_handle_standard_args(AE108_GTest
REQUIRED_VARS GTest_FOUND
)
\ No newline at end of file
......@@ -19,7 +19,7 @@ add_executable(${PROJECT_NAME}-CmdLineTests
./CommandLineOptionParser_Test.cc
)
find_package(GTest 1.8.1 CONFIG REQUIRED)
find_package(AE108_GTest MODULE REQUIRED)
target_link_libraries(${PROJECT_NAME}-CmdLineTests
PRIVATE ${PROJECT_NAME}::cmdline
PRIVATE GTest::gmock_main
......
......@@ -25,8 +25,8 @@ add_library(${PROJECT_NAME}::cppptest ALIAS ${PROJECT_NAME}-cppptest)
target_include_directories(${PROJECT_NAME}-cppptest PUBLIC include)
find_package(AE108_GTest MODULE REQUIRED)
find_package(AE108_PETSc 3.10 MODULE REQUIRED)
find_package(GTest 1.8.1 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME}-cppptest
PRIVATE ${PROJECT_NAME}::external::petsc
PUBLIC GTest::gmock
......
......@@ -46,7 +46,7 @@ add_executable(${PROJECT_NAME}-ElementsTests
add_test(NAME ${PROJECT_NAME}-ElementsTests COMMAND $<TARGET_FILE:${PROJECT_NAME}-ElementsTests>)
find_package(GTest 1.8.1 CONFIG REQUIRED)
find_package(AE108_GTest MODULE REQUIRED)
target_link_libraries(${PROJECT_NAME}-ElementsTests PUBLIC
${PROJECT_NAME}-elements
GTest::gmock_main
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment