Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1516 Use GTest detection in own cmake macro
Browse files Browse the repository at this point in the history
Write a central macro used by other libraries to
detect if GTest or gtest_vendor package is present
  • Loading branch information
dkroenke committed Jul 19, 2022
1 parent f9754b6 commit d0a48ee
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 48 deletions.
3 changes: 2 additions & 1 deletion iceoryx_binding_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ iox_add_library(
#
########## build test executables ##########
#
if(BUILD_TEST)
if(BUILD_TESTING)
detect_gtest_package()
add_subdirectory(test)
endif()
2 changes: 2 additions & 0 deletions iceoryx_binding_c/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

<doc_depend>doxygen</doc_depend>

<test_depend>gtest_vendor</test_depend>

<export>
<build_type>cmake</build_type>
</export>
Expand Down
4 changes: 1 addition & 3 deletions iceoryx_binding_c/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ project(test_binding_c VERSION 0)

find_package(iceoryx_hoofs_testing REQUIRED)
find_package(iceoryx_posh_testing REQUIRED)
find_package(GTest CONFIG REQUIRED)

set(PROJECT_PREFIX "binding_c")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_PREFIX}/test)
Expand All @@ -28,8 +27,7 @@ file(GLOB_RECURSE MODULETESTS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/moduletests/*.cpp

set(TEST_LINK_LIBS
${CODE_COVERAGE_LIBS}
GTest::gtest
GTest::gmock
${IOX_GTEST_LIBS}
iceoryx_binding_c::iceoryx_binding_c
iceoryx_hoofs::iceoryx_hoofs
iceoryx_hoofs_testing::iceoryx_hoofs_testing
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_dds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ iox_add_executable(
#
########## build test executables ##########
#
if(BUILD_TEST)
if(BUILD_TESTING)
detect_gtest_package()
add_subdirectory(test)
endif()
4 changes: 1 addition & 3 deletions iceoryx_dds/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ project(test_iox_to_dds VERSION 0)

find_package(iceoryx_hoofs_testing REQUIRED)
find_package(iceoryx_posh_testing REQUIRED)
find_package(GTest CONFIG REQUIRED)

set(PROJECT_PREFIX "dds_gateway")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_PREFIX}/test)
Expand All @@ -28,8 +27,7 @@ file(GLOB_RECURSE MODULETESTS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/moduletests/*.cpp

set(TEST_LINK_LIBS
${CODE_COVERAGE_LIBS}
GTest::gtest
GTest::gmock
${IOX_GTEST_LIBS}
iceoryx_hoofs::iceoryx_hoofs
iceoryx_hoofs_testing::iceoryx_hoofs_testing
iceoryx_posh::iceoryx_posh
Expand Down
14 changes: 4 additions & 10 deletions iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,12 @@ iox_add_library(
########## hoofs testing ##########
#

# Finding gtest and adding the subdirectories is split to support the use case of
# building the testing lib without the tests by providing gtest externally
if(NOT GTest_FOUND AND BUILD_TEST)
find_package(GTest CONFIG REQUIRED)
endif()

if(GTest_FOUND)
message(STATUS "GTest was found, building iceoryx_hoofs_testing enabled.")

if(BUILD_TESTING)
detect_gtest_package()
add_subdirectory(testing)
if(BUILD_TEST)
add_subdirectory(test)
endif()
add_subdirectory(test)
endif()

install(
Expand Down
18 changes: 18 additions & 0 deletions iceoryx_hoofs/cmake/IceoryxPlatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,21 @@ if(COVERAGE)
message( FATAL_ERROR "You need to run gcov with gcc compiler." )
endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
endif()

Macro(detect_gtest_package)
if(NOT GTest_FOUND)
find_package(GTest 1.10.0 EXACT CONFIG QUIET)
if(NOT GTest_FOUND)
message(STATUS "GTest not found, trying to find gtest_vendor package...")
find_package(gtest_vendor CONFIG REQUIRED)
set(IOX_GTEST_LIBS
gtest
gmock)
message(STATUS "gtest_vendor package found successfully")
else()
set(IOX_GTEST_LIBS
GTest::gtest
GTest::gmock)
endif()
endif()
endMacro()
2 changes: 2 additions & 0 deletions iceoryx_hoofs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

<doc_depend>doxygen</doc_depend>

<test_depend>gtest_vendor</test_depend>

<export>
<build_type>cmake</build_type>
</export>
Expand Down
3 changes: 1 addition & 2 deletions iceoryx_hoofs/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_PREFIX}/test)

set(TEST_LINK_LIBS
${CODE_COVERAGE_LIBS}
GTest::gtest
GTest::gmock
${IOX_GTEST_LIBS}
iceoryx_hoofs::iceoryx_hoofs
iceoryx_hoofs_testing::iceoryx_hoofs_testing
)
Expand Down
3 changes: 1 addition & 2 deletions iceoryx_hoofs/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ iox_add_library(
TARGET ${PROJECT_NAME}_testing
NAMESPACE iceoryx_hoofs_testing
PROJECT_PREFIX ${PREFIX}
PUBLIC_LIBS GTest::gtest
GTest::gmock
PUBLIC_LIBS ${IOX_GTEST_LIBS}
PRIVATE_LIBS ${CODE_COVERAGE_LIBS}
iceoryx_hoofs
${CMAKE_DL_LIBS}
Expand Down
24 changes: 4 additions & 20 deletions iceoryx_posh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,27 +297,11 @@ setup_install_directories_and_export_package(
INCLUDE_DIRECTORY include/
)

if(ROUDI_ENVIRONMENT OR BUILD_TEST)
#
######### posh roudi environment ##########
#
iox_add_library(
STATIC
TARGET iceoryx_posh_testing
NAMESPACE iceoryx_posh_testing
PROJECT_PREFIX ${PREFIX}
BUILD_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/testing/include
INSTALL_INTERFACE include/${PREFIX}
PRIVATE_LIBS iceoryx_posh::iceoryx_posh
iceoryx_hoofs::iceoryx_hoofs
iceoryx_posh::iceoryx_posh_roudi
iceoryx_hoofs_testing::iceoryx_hoofs_testing
FILES
testing/roudi_environment/runtime_test_interface.cpp
testing/roudi_environment/roudi_environment.cpp
)
if(ROUDI_ENVIRONMENT OR BUILD_TESTING)
detect_gtest_package()
add_subdirectory(testing)
endif()

if(BUILD_TEST)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
2 changes: 2 additions & 0 deletions iceoryx_posh/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

<doc_depend>doxygen</doc_depend>

<test_depend>gtest_vendor</test_depend>

<export>
<build_type>cmake</build_type>
</export>
Expand Down
7 changes: 1 addition & 6 deletions iceoryx_posh/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ find_package(iceoryx_posh_testing REQUIRED)

set(ICEORYX_POSH_TEST_STACK_SIZE 5000000)

if(BUILD_TEST AND NOT GTest_FOUND)
find_package(GTest CONFIG REQUIRED)
endif(BUILD_TEST AND NOT GTest_FOUND)

set(PROJECT_PREFIX "posh")

# Set path for input files in test
Expand All @@ -46,8 +42,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_PREFIX}/test)

set(TEST_LINK_LIBS
${CODE_COVERAGE_LIBS}
GTest::gtest
GTest::gmock
${IOX_GTEST_LIBS}
iceoryx_hoofs::iceoryx_hoofs
iceoryx_hoofs::iceoryx_platform
iceoryx_hoofs_testing::iceoryx_hoofs_testing
Expand Down
37 changes: 37 additions & 0 deletions iceoryx_posh/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved.
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.16)

find_package(iceoryx_hoofs_testing REQUIRED)
#
######### posh roudi environment ##########
#
iox_add_library(
STATIC
TARGET iceoryx_posh_testing
NAMESPACE iceoryx_posh_testing
PROJECT_PREFIX ${PREFIX}
BUILD_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include
INSTALL_INTERFACE include/${PREFIX}
PRIVATE_LIBS iceoryx_posh::iceoryx_posh
iceoryx_hoofs::iceoryx_hoofs
iceoryx_posh::iceoryx_posh_roudi
iceoryx_hoofs_testing::iceoryx_hoofs_testing
FILES
roudi_environment/runtime_test_interface.cpp
roudi_environment/roudi_environment.cpp
)

0 comments on commit d0a48ee

Please sign in to comment.