Skip to content
Snippets Groups Projects
Commit 64b99e3b authored by Marc-Olivier Andrez's avatar Marc-Olivier Andrez
Browse files

build: use `GTest` CMake module to handle dependencies on gtest

As a consequence, we can remove code in CMake files to handle these
dependencies on `gtest` and `gmock`, which fixes the following error
when running CMake:

```sh
$ cmake -G Ninja ../.. -DPython_EXECUTABLE=python3.7 -DBUILD_TESTS=ON -DENABLE_COVERAGE=ON -DBUILD_CPP_DOCS=ON -DBUILD_PYTHON_DOCS=ON
...
CMake Error at CMakeModules/testing_cpp.cmake:47 (IF):
  if given arguments:

    "WIN32" "AND" "STREQUAL" "Debug"

  Unknown arguments specified
Call Stack (most recent call first):
  common/cpp/src/common/CMakeLists.txt:11 (add_plain_unit_test)
```
parent 05c67ed4
No related branches found
No related tags found
No related merge requests found
......@@ -18,14 +18,12 @@ set (TOKENS "${TOKENS};BT_TEST_RUN_RW_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
if (BUILD_TESTS)
set(ASAPO_MINIMUM_COVERAGE 70)
find_package(GTest REQUIRED)
set(GTEST_LIBS GTest::gmock GTest::gmock_main)
find_package(Threads)
find_program(MEMORYCHECK_COMMAND valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS
"--trace-children=yes --leak-check=full --error-exitcode=1 --num-callers=20 --suppressions=${CMAKE_SOURCE_DIR}/tests/valgrind.suppressions")
if (NOT "$ENV{gtest_SOURCE_DIR}" STREQUAL "")
set(gtest_SOURCE_DIR $ENV{gtest_SOURCE_DIR})
endif ()
message(STATUS "Will look for google test at ${gtest_SOURCE_DIR}")
if (CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
......@@ -35,20 +33,12 @@ endif ()
#TODO: Call add_plain_unit_test in gtest
function(add_plain_unit_test target test_source_files linktarget)
if (BUILD_TESTS)
include_directories(SYSTEM ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
link_directories(${gtest_SOURCE_DIR}/lib)
add_executable(test-${target} ${test_source_files})
if (NOT ${libs} STREQUAL "")
target_link_libraries(test-${target} ${libs})
endif ()
IF (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(GTEST_LIBS gtestd gtest_maind gmockd)
ELSE ()
set(GTEST_LIBS gtest gmock gtest_main)
ENDIF (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
target_link_libraries(test-${target} ${GTEST_LIBS} ${CMAKE_THREAD_LIBS_INIT})
GET_PROPERTY(ASAPO_COMMON_IO_LIBRARIES GLOBAL PROPERTY ASAPO_COMMON_IO_LIBRARIES)
......@@ -67,9 +57,6 @@ endfunction()
function(gtest target test_source_files linktarget)
if (BUILD_TESTS)
include_directories(SYSTEM ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
link_directories(${gtest_SOURCE_DIR}/lib)
FOREACH (lib ${linktarget})
if (NOT ${lib} STREQUAL "")
get_target_property(target_type ${lib} TYPE)
......@@ -88,11 +75,6 @@ function(gtest target test_source_files linktarget)
target_link_libraries(test-${target} ${libs})
endif ()
IF (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(GTEST_LIBS gtestd gtest_maind gmockd)
ELSE ()
set(GTEST_LIBS gtest gmock gtest_main)
ENDIF (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
target_link_libraries(test-${target} ${GTEST_LIBS} ${CMAKE_THREAD_LIBS_INIT})
GET_PROPERTY(ASAPO_COMMON_IO_LIBRARIES GLOBAL PROPERTY ASAPO_COMMON_IO_LIBRARIES)
......
......@@ -68,7 +68,7 @@ The software is MIT licensed (see LICENSE.txt) and uses third party libraries th
(see LICENSE-3RD-PARTY.txt)
### with non-standard 3rd party libraries paths
- cmake -Dlibmongoc-static-1.0_DIR=... -Dlibbson-static-1.0_DIR=... -Dgtest_SOURCE_DIR=... -DLIBCURL_DIR=... ...
- cmake -Dlibmongoc-static-1.0_DIR=... -Dlibbson-static-1.0_DIR=... -DLIBCURL_DIR=... ...
### compile
- make -j 4
......
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