Skip to content

Commit

Permalink
third_party: get gtest like other dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Oes <julian@oes.ch>
  • Loading branch information
julianoes committed May 1, 2024
1 parent c8aff6e commit 8c25356
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 38 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "gtest"]
path = src/third_party/gtest
url = https://github.com/google/googletest
[submodule "mavsdk-proto"]
path = proto
url = https://github.com/mavlink/MAVSDK-Proto.git
3 changes: 0 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,9 @@ include(cmake/static_analyzers.cmake)

if(BUILD_TESTS)
enable_testing()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/gtest EXCLUDE_FROM_ALL)

add_subdirectory(integration_tests)

add_subdirectory(unit_tests)

add_subdirectory(system_tests)
endif()

Expand Down
28 changes: 5 additions & 23 deletions src/integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,6 @@ target_include_directories(integration_tests_runner
${PROJECT_SOURCE_DIR}/mavsdk/core
)

# SYSTEM because we don't want warnings for gtest headers.
target_include_directories(integration_tests_runner
SYSTEM
PRIVATE ${PROJECT_SOURCE_DIR}/third_party/gtest/googletest/include
PRIVATE ${PROJECT_SOURCE_DIR}/third_party/gtest/googlemock/include
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../third_party/include
)

if(MSVC)
target_compile_options(integration_tests_runner
PRIVATE
/wd4996 # ignore deprecated
)
else()
target_compile_options(integration_tests_runner
PRIVATE
-Wno-error=deprecated-declarations
)
endif()

target_compile_definitions(integration_tests_runner
PRIVATE
"-DTESTING")
Expand All @@ -87,12 +67,14 @@ set_target_properties(integration_tests_runner
PROPERTIES COMPILE_FLAGS ${warnings}
)

find_package(GTest)

target_link_libraries(integration_tests_runner
PRIVATE
mavsdk
gtest
gtest_main
gmock
GTest::gtest
GTest::gtest_main
GTest::gmock
)

add_test(integration_tests
Expand Down
8 changes: 5 additions & 3 deletions src/mavsdk_server/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ target_include_directories(unit_tests_mavsdk_server
${PROJECT_SOURCE_DIR}/mavsdk_server/src/generated
)

find_package(GTest REQUIRED)

target_link_libraries(unit_tests_mavsdk_server
PRIVATE
mavsdk
mavsdk_server
gRPC::grpc++
gtest
gmock
gmock_main
GTest::gtest
GTest::gmock
GTest::gmock_main
)

if (BUILD_STATIC_MAVSDK_SERVER)
Expand Down
8 changes: 5 additions & 3 deletions src/system_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ target_include_directories(system_tests_runner
${PROJECT_SOURCE_DIR}/mavsdk/core
)

find_package(GTest)

target_link_libraries(system_tests_runner
PRIVATE
mavsdk
gtest
gtest_main
gmock
GTest::gtest
GTest::gtest_main
GTest::gmock
)

if(ENABLE_CPPTRACE)
Expand Down
8 changes: 5 additions & 3 deletions src/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ set_target_properties(unit_tests_runner
PROPERTIES COMPILE_FLAGS ${warnings}
)

find_package(GTest)

target_link_libraries(unit_tests_runner
mavsdk
CURL::libcurl
JsonCpp::JsonCpp
gtest
gtest_main
gmock
GTest::gtest
GTest::gtest_main
GTest::gmock
)

target_include_directories(unit_tests_runner
Expand Down
2 changes: 2 additions & 0 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ if (SUPERBUILD)
build_target(grpc)
endif()

build_target(gtest)

endif()

if (ENABLE_CPPTRACE)
Expand Down
34 changes: 34 additions & 0 deletions third_party/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.1)

project(external-gtest)
include(ExternalProject)

list(APPEND CMAKE_ARGS
"-DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}"
"-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}"
"-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}"
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DBUILD_SHARED_LIBS=OFF"
)

if(IOS)
list(APPEND CMAKE_ARGS
"-DPLATFORM=${PLATFORM}"
"-DDEPLOYMENT_TARGET=${DEPLOYMENT_TARGET}"
"-DENABLE_STRICT_TRY_COMPILE=${ENABLE_STRICT_TRY_COMPILE}"
)
endif()

message(STATUS "Preparing external project \"gtest\" with args:")
foreach(CMAKE_ARG ${CMAKE_ARGS})
message(STATUS "-- ${CMAKE_ARG}")
endforeach()

ExternalProject_Add(
gtest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG v1.14.0
PREFIX gtest
CMAKE_ARGS "${CMAKE_ARGS}"
)

0 comments on commit 8c25356

Please sign in to comment.