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

Fix build when included with cmake_add_subdirectory #32

Open
wants to merge 5 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
10 changes: 5 additions & 5 deletions osrf_testing_tools_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ if(BUILD_TESTING)
include(cmake/osrf_testing_tools_cpp_require_googletest.cmake)
# ensures target gtest_main exists
osrf_testing_tools_cpp_require_googletest(VERSION_GTE 1.8
VENDOR_DIR "${CMAKE_SOURCE_DIR}/vendor")
VENDOR_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vendor")

add_subdirectory(test)
endif()

configure_file(osrf_testing_tools_cppConfig.cmake.in
"${PROJECT_BINARY_DIR}/osrf_testing_tools_cppConfig.cmake" @ONLY)
"${CMAKE_CURRENT_BINARY_DIR}/osrf_testing_tools_cppConfig.cmake" @ONLY)
configure_file(osrf_testing_tools_cppConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/osrf_testing_tools_cppConfigVersion.cmake" @ONLY)
"${CMAKE_CURRENT_BINARY_DIR}/osrf_testing_tools_cppConfigVersion.cmake" @ONLY)

install(FILES
"${PROJECT_BINARY_DIR}/osrf_testing_tools_cppConfig.cmake"
"${PROJECT_BINARY_DIR}/osrf_testing_tools_cppConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/osrf_testing_tools_cppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/osrf_testing_tools_cppConfigVersion.cmake"
DESTINATION share/${PROJECT_NAME}/cmake
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ macro(osrf_testing_tools_cpp_extract_and_build_googletest

execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-${GOOGLETEST_VERSION}-extracted)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-${GOOGLETEST_VERSION}-extracted)
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()

execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-${GOOGLETEST_VERSION}-extracted)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-${GOOGLETEST_VERSION}-extracted)
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
Expand All @@ -77,8 +77,8 @@ macro(osrf_testing_tools_cpp_extract_and_build_googletest
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(
${CMAKE_BINARY_DIR}/${__prefix}-extracted/${__prefix}-src
${CMAKE_BINARY_DIR}/${__prefix}-extracted/${__prefix}-build
${CMAKE_CURRENT_BINARY_DIR}/${__prefix}-extracted/${__prefix}-src
${CMAKE_CURRENT_BINARY_DIR}/${__prefix}-extracted/${__prefix}-build
EXCLUDE_FROM_ALL
)
unset(__prefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ set(OSRF_TESTING_TOOLS_CPP_REQUIRE_GOOGLETEST_VERSION_SETUP)
# @public
#
macro(osrf_testing_tools_cpp_require_googletest)
if (TARGET gtest OR TARGET gtest_main)
return()
endif()
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? I assume there was a duplicate target, but honestly I'm not sure this is the right way to handle it. If the target already exists then either osrf_testing_tools_cpp_require_googletest() was called more than once (which is explicitly not allowed) or it was created by another piece of CMake logic, which is also bad, since it might not have the version osrf_testing_tools_cpp_require_googletest() would have given.

# Make sure this was only called once.
if(OSRF_TESTING_TOOLS_CPP_REQUIRE_GOOGLETEST_VERSION_SETUP)
set(error_msg "osrf_testing_tools_cpp_require_googletest():")
Expand Down
5 changes: 3 additions & 2 deletions osrf_testing_tools_cpp/src/memory_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ add_library(memory_tools SHARED

target_include_directories(memory_tools
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(memory_tools PRIVATE Backward::Backward)
Expand Down Expand Up @@ -93,4 +94,4 @@ install(EXPORT memory_tools_interpose
set(memory_tools_extra_test_env "${memory_tools_extra_test_env}" PARENT_SCOPE)
set(memory_tools_is_available "${memory_tools_is_available}" PARENT_SCOPE)
set(memory_tools_src_dir_internal_testing_only
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>" PARENT_SCOPE)
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>" PARENT_SCOPE)
2 changes: 1 addition & 1 deletion osrf_testing_tools_cpp/test/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ add_test(
NAME "test_osrf_testing_tools_cpp_filter_versions_cmake"
COMMAND
${CMAKE_COMMAND} -P
"${CMAKE_SOURCE_DIR}/test/cmake/test_osrf_testing_tools_cpp_filter_versions.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/test_osrf_testing_tools_cpp_filter_versions.cmake"
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ include(ExternalProject)
ExternalProject_Add(googletest
URL "@GOOGLETEST_ARCHIVE_LOCATION@"
URL_MD5 "@GOOGLETEST_MD5SUM@"
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-@GOOGLETEST_VERSION@-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-@GOOGLETEST_VERSION@-build"
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-@GOOGLETEST_VERSION@-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-@GOOGLETEST_VERSION@-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
Expand Down