Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of googletest using colcon [12009] #2054

Merged
merged 8 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions cmake/common/gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,6 @@

option(GTEST_INDIVIDUAL "Activate the execution of GTest tests" OFF)

macro(check_gtest)
if(NOT GTEST_FOUND)
if(WIN32)
option(EPROSIMA_GTEST "Activate special set of GTEST_ROOT" OFF)
if(EPROSIMA_BUILD)
set(EPROSIMA_GTEST ON)
endif()
endif()

# Find package GTest
if(WIN32 AND EPROSIMA_GTEST)
if(NOT GTEST_ROOT)
set(GTEST_ROOT_ $ENV{GTEST_ROOT})
if(GTEST_ROOT_)
file(TO_CMAKE_PATH "${GTEST_ROOT_}/${MSVC_ARCH}" GTEST_ROOT)
endif()
else()
file(TO_CMAKE_PATH "${GTEST_ROOT}/${MSVC_ARCH}" GTEST_ROOT)
endif()
endif()
find_package(GTest)

if(GTEST_FOUND)
find_package(Threads REQUIRED)
set(GTEST_LIBRARIES ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
set(GTEST_BOTH_LIBRARIES ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif()
endif()
endmacro()

macro(check_gmock)
if(NOT GMOCK_FOUND)
if(WIN32)
option(EPROSIMA_GMOCK "Activate special set of GMOCK_ROOT" OFF)
if(EPROSIMA_BUILD)
set(EPROSIMA_GMOCK ON)
endif()
endif()

# Find package GMock
if(WIN32 AND EPROSIMA_GMOCK)
if(NOT GMOCK_ROOT)
set(GMOCK_ROOT_ $ENV{GMOCK_ROOT})
if(GMOCK_ROOT_)
file(TO_CMAKE_PATH "${GMOCK_ROOT_}/${MSVC_ARCH}" GMOCK_ROOT)
endif()
else()
file(TO_CMAKE_PATH "${GMOCK_ROOT}/${MSVC_ARCH}" GMOCK_ROOT)
endif()
endif()
find_package(GMock)

if(GMOCK_FOUND)
find_package(Threads REQUIRED)
set(GMOCK_LIBRARIES ${GMOCK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
set(GMOCK_BOTH_LIBRARIES ${GMOCK_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif()
endif()
endmacro()

macro(add_gtest)
# Parse arguments
if("${ARGV0}" STREQUAL "NAME")
Expand Down
130 changes: 0 additions & 130 deletions cmake/modules/FindGMock.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions colcon.pkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fastrtps",
"type": "cmake",
"dependencies" : ["fastcdr", "FOONATHAN_MEMORY", "foonathan_memory_vendor"]
}
"dependencies" : ["fastcdr", "FOONATHAN_MEMORY", "foonathan_memory_vendor", "googletest-distribution"]
}
10 changes: 3 additions & 7 deletions examples/C++/DDS/DeadlineQoSExample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,14 @@ endif()
message(STATUS "Configuring DDSDeadlineQoS example...")
file(GLOB DDS_DEADLINEQOS_EXAMPLE_SOURCES "*.cxx")

add_definitions(
-DBOOST_ASIO_STANDALONE
-DASIO_STANDALONE
)

include_directories(${Asio_INCLUDE_DIR})

add_executable(DDSDeadlineQoSExample ${DDS_DEADLINEQOS_EXAMPLE_SOURCES})
target_compile_definitions(DDSDeadlineQoSExample PRIVATE
BOOST_ASIO_STANDALONE
ASIO_STANDALONE
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(DDSDeadlineQoSExample PRIVATE ${Asio_INCLUDE_DIR})
target_link_libraries(DDSDeadlineQoSExample fastrtps fastcdr foonathan_memory)
if(UNIX)
target_link_libraries(DDSDeadlineQoSExample pthread)
Expand Down
10 changes: 3 additions & 7 deletions examples/C++/DeadlineQoSExample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,14 @@ endif()
message(STATUS "Configuring DeadlineQoS example...")
file(GLOB DEADLINEQOS_EXAMPLE_SOURCES "*.cxx")

add_definitions(
-DBOOST_ASIO_STANDALONE
-DASIO_STANDALONE
)

include_directories(${Asio_INCLUDE_DIR})

add_executable(DeadlineQoSExample ${DEADLINEQOS_EXAMPLE_SOURCES})
target_compile_definitions(DeadlineQoSExample PRIVATE
BOOST_ASIO_STANDALONE
ASIO_STANDALONE
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(DeadlineQoSExample PRIVATE ${Asio_INCLUDE_DIR})
target_link_libraries(DeadlineQoSExample fastrtps fastcdr foonathan_memory)
if(UNIX)
target_link_libraries(DeadlineQoSExample pthread)
Expand Down
9 changes: 5 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

include(${PROJECT_SOURCE_DIR}/cmake/common/gtest.cmake)
check_gtest()
check_gmock()

option(PERFORMANCE_TESTS "Activate the building and execution of performance tests" OFF)
option(SYSTEM_TESTS "Activate the building and execution of system tests" OFF)
option(PROFILING_TESTS "Activate the building and execution of profiling tests" OFF)
Expand All @@ -33,6 +29,11 @@ set(MEMORYCHECK_SUPPRESSIONS_FILE ${MEMORYCHECK_SUPPRESSIONS_FILE_TMP} CACHE FIL
# Testing
###############################################################################
if(EPROSIMA_BUILD_TESTS AND IS_TOP_LEVEL AND NOT EPROSIMA_INSTALLER)
find_package(GTest CONFIG REQUIRED)
if (GTest_FOUND)
include(${PROJECT_SOURCE_DIR}/cmake/common/gtest.cmake)
endif()

add_subdirectory(blackbox)
add_subdirectory(communication)
add_subdirectory(unittest)
Expand Down
34 changes: 15 additions & 19 deletions test/blackbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,14 @@ option(FASTRTPS_API_TESTS "Enable tests using FastRTPS API" ON)
option(FASTDDS_PIM_API_TESTS "Enable tests using FastDDS API" OFF)

if(NOT ((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER) AND fastcdr_FOUND)
include(${PROJECT_SOURCE_DIR}/cmake/common/gtest.cmake)
check_gtest()

if(GTEST_FOUND)
if(GTest_FOUND)
if(WIN32)
add_definitions(
-D_WIN32_WINNT=0x0601
-D_CRT_SECURE_NO_WARNINGS
)
endif()

add_definitions(
-DBOOST_ASIO_STANDALONE
-DASIO_STANDALONE
)

include_directories(${Asio_INCLUDE_DIR})

###############################################################################
# Unit tests
###############################################################################
Expand All @@ -200,13 +190,15 @@ if(NOT ((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER) AND fastcdr_FOUND)
)
add_executable(BlackboxTests_RTPS ${RTPS_BLACKBOXTESTS_SOURCE})
target_compile_definitions(BlackboxTests_RTPS PRIVATE
BOOST_ASIO_STANDALONE
ASIO_STANDALONE
$<$<NOT:$<BOOL:${IS_THIRDPARTY_BOOST_SUPPORTED}>>:FASTDDS_SHM_TRANSPORT_DISABLED> # Do not compile SHM Transport
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(BlackboxTests_RTPS PRIVATE
${GTEST_INCLUDE_DIRS})
target_link_libraries(BlackboxTests_RTPS fastrtps fastcdr foonathan_memory ${GTEST_LIBRARIES})
${Asio_INCLUDE_DIR})
target_link_libraries(BlackboxTests_RTPS fastrtps fastcdr foonathan_memory GTest::gtest)
add_blackbox_gtest(BlackboxTests_RTPS SOURCES ${RTPS_BLACKBOXTESTS_TEST_SOURCE})

file(GLOB BLACKBOXTESTS_TEST_SOURCE "common/BlackboxTests*.cpp")
Expand Down Expand Up @@ -270,14 +262,16 @@ if(NOT ((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER) AND fastcdr_FOUND)

add_executable(BlackboxTests_FastRTPS ${BLACKBOXTESTS_FASTRTPS_SOURCE})
target_compile_definitions(BlackboxTests_FastRTPS PRIVATE
BOOST_ASIO_STANDALONE
ASIO_STANDALONE
$<$<NOT:$<BOOL:${IS_THIRDPARTY_BOOST_SUPPORTED}>>:FASTDDS_SHM_TRANSPORT_DISABLED> # Do not compile SHM Transport
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(BlackboxTests_FastRTPS PRIVATE
api/fastrtps_deprecated
${GTEST_INCLUDE_DIRS})
target_link_libraries(BlackboxTests_FastRTPS fastrtps fastcdr foonathan_memory ${GTEST_LIBRARIES})
${Asio_INCLUDE_DIR}
api/fastrtps_deprecated)
target_link_libraries(BlackboxTests_FastRTPS fastrtps fastcdr foonathan_memory GTest::gtest)
add_blackbox_gtest(BlackboxTests_FastRTPS SOURCES ${BLACKBOXTESTS_TEST_SOURCE}
ENVIRONMENTS "CERTS_PATH=${PROJECT_SOURCE_DIR}/test/certs"
"TOPIC_RANDOM_NUMBER=${TOPIC_RANDOM_NUMBER}"
Expand Down Expand Up @@ -307,14 +301,16 @@ if(NOT ((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER) AND fastcdr_FOUND)

add_executable(BlackboxTests_DDS_PIM ${BLACKBOXTESTS_FASTDDS_PIM_SOURCE})
target_compile_definitions(BlackboxTests_DDS_PIM PRIVATE
BOOST_ASIO_STANDALONE
ASIO_STANDALONE
$<$<NOT:$<BOOL:${IS_THIRDPARTY_BOOST_SUPPORTED}>>:FASTDDS_SHM_TRANSPORT_DISABLED> # Do not compile SHM Transport
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(BlackboxTests_DDS_PIM PRIVATE
api/dds-pim
${GTEST_INCLUDE_DIRS})
target_link_libraries(BlackboxTests_DDS_PIM fastrtps fastcdr foonathan_memory ${GTEST_LIBRARIES})
${Asio_INCLUDE_DIR}
api/dds-pim)
target_link_libraries(BlackboxTests_DDS_PIM fastrtps fastcdr foonathan_memory GTest::gtest)
add_blackbox_gtest(BlackboxTests_DDS_PIM SOURCES ${DDS_BLACKBOXTESTS_SOURCE}
ENVIRONMENTS "CERTS_PATH=${PROJECT_SOURCE_DIR}/test/certs"
"TOPIC_RANDOM_NUMBER=${TOPIC_RANDOM_NUMBER}"
Expand Down
Loading