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

GTest improvements #563

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open
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
19 changes: 12 additions & 7 deletions ament_cmake_gmock/ament_cmake_gmock-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,22 @@ macro(_ament_cmake_gmock_find_gmock)
set(_AMENT_CMAKE_GMOCK_FIND_GMOCK TRUE)

find_package(ament_cmake_test QUIET REQUIRED)
find_package(gmock_vendor QUIET)

# if gmock sources were not found in a previous run
if(NOT GMOCK_FROM_SOURCE_FOUND)
# search path for gmock includes and sources
set(_search_path_include "")
set(_search_path_src "")
# check the system installed path (i.e. on Ubuntu)
set(_search_path_include "/usr/include/gmock")
set(_search_path_src "/usr/src/gmock/src")

# option() consider environment variable to find gmock
if(NOT $ENV{GMOCK_DIR} STREQUAL "")
list(APPEND _search_path_include "$ENV{GMOCK_DIR}/include/gmock")
list(APPEND _search_path_src "$ENV{GMOCK_DIR}/src")
endif()

# check to system installed path (i.e. on Ubuntu)
set(_search_path_include "/usr/include/gmock")
set(_search_path_src "/usr/src/gmock/src")

# check gmock_vendor path, prefer this version over a system installed
find_package(gmock_vendor QUIET)
if(gmock_vendor_FOUND AND gmock_vendor_BASE_DIR)
list(INSERT _search_path_include 0 "${gmock_vendor_BASE_DIR}/include/gmock")
list(INSERT _search_path_src 0 "${gmock_vendor_BASE_DIR}/src")
Expand Down Expand Up @@ -71,6 +68,14 @@ macro(_ament_cmake_gmock_find_gmock)

set(GMOCK_FROM_SOURCE_LIBRARIES "gmock" CACHE INTERNAL "")
set(GMOCK_FROM_SOURCE_MAIN_LIBRARIES "gmock_main" CACHE INTERNAL "")
else()
# try to find and use gmock from GTest
find_package(GTest QUIET)
if(GTest_FOUND)
set(GMOCK_FOUND TRUE)
set(GMOCK_LIBRARIES GTest::gmock)
set(GMOCK_MAIN_LIBRARIES GTest::gmock_main)
endif()
Comment on lines +71 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a little strange to me. Mind explaining when we can assume GTest will provide targets for gmock prefixed with GTest::?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endif()
endif()

Expand Down
9 changes: 9 additions & 0 deletions ament_cmake_gtest/ament_cmake_gtest-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ macro(_ament_cmake_gtest_find_gtest)

set(GTEST_FROM_SOURCE_LIBRARIES "gtest" CACHE INTERNAL "")
set(GTEST_FROM_SOURCE_MAIN_LIBRARIES "gtest_main" CACHE INTERNAL "")
else()
# try to find and use gtest from GTest
find_package(GTest QUIET)
if(GTest_FOUND)
set(GTEST_FOUND TRUE)
set(GTEST_LIBRARIES GTest::gtest)
set(GTEST_MAIN_LIBRARIES GTest::gtest_main)
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
endif()
endif()
endif()

Expand Down