Skip to content

Commit

Permalink
Build gtest from source by adding its subdirectory
Browse files Browse the repository at this point in the history
Disable warnings for the gtest library target
  • Loading branch information
dneto0 committed Dec 13, 2024
1 parent 1efedac commit 26b68e8
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,25 +297,22 @@ if(CPPDAP_BUILD_TESTS)

if(CPPDAP_USE_EXTERNAL_GTEST_PACKAGE)
find_package(GTest REQUIRED)
set(CPPDAP_GTEST_TARGET GTest::gtest)
else()
list(APPEND DAP_TEST_LIST
${CPPDAP_GOOGLETEST_DIR}/googletest/src/gtest-all.cc
)
set_property(SOURCE
${CPPDAP_GOOGLETEST_DIR}/googletest/src/gtest-all.cc
APPEND PROPERTY COMPILE_OPTIONS -w)

set(DAP_TEST_INCLUDE_DIR
${CPPDAP_GOOGLETEST_DIR}/googlemock/include/
${CPPDAP_GOOGLETEST_DIR}/googletest/
${CPPDAP_GOOGLETEST_DIR}/googletest/include/
)
# Build gtest from source
set(INSTALL_GTEST OFF)
add_subdirectory(${CPPDAP_GOOGLETEST_DIR}/googlemock)
# googletest has -Werror=maybe-uninitialized problem.
# Disable all warnings in googletest code.
target_compile_options(gtest PRIVATE -w)
set(CPPDAP_GTEST_TARGET gtest)
set(DAP_TEST_INCLUDE_DIR ${CPPDAP_GOOGLETEST_DIR}/googlemock/include/)
endif()

add_executable(cppdap-unittests ${DAP_TEST_LIST})
add_test(NAME cppdap-unittests COMMAND cppdap-unittests)

target_include_directories(cppdap-unittests PUBLIC ${DAP_TEST_INCLUDE_DIR} )
target_include_directories(cppdap-unittests PUBLIC ${DAP_TEST_INCLUDE_DIR})
set_target_properties(cppdap-unittests PROPERTIES
FOLDER "Tests"
)
Expand All @@ -326,11 +323,7 @@ if(CPPDAP_BUILD_TESTS)
endif()

cppdap_set_target_options(cppdap-unittests)
if(CPPDAP_USE_EXTERNAL_GTEST_PACKAGE)
target_link_libraries(cppdap-unittests PRIVATE cppdap GTest::gtest)
else()
target_link_libraries(cppdap-unittests PRIVATE cppdap)
endif()
target_link_libraries(cppdap-unittests PRIVATE cppdap ${CPPDAP_GTEST_TARGET})
endif(CPPDAP_BUILD_TESTS)

# fuzzer
Expand Down

0 comments on commit 26b68e8

Please sign in to comment.