Skip to content

Commit b63e455

Browse files
committed
Fix build when included with cmake_add_subdirectory
1 parent fde512a commit b63e455

6 files changed

+14
-11
lines changed

osrf_testing_tools_cpp/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if(BUILD_TESTING)
2020
include(cmake/osrf_testing_tools_cpp_require_googletest.cmake)
2121
# ensures target gtest_main exists
2222
osrf_testing_tools_cpp_require_googletest(VERSION_GTE 1.8
23-
VENDOR_DIR "${CMAKE_SOURCE_DIR}/vendor")
23+
VENDOR_DIR "${PROJECT_SOURCE_DIR}/vendor")
2424

2525
add_subdirectory(test)
2626
endif()

osrf_testing_tools_cpp/cmake/osrf_testing_tools_cpp_extract_and_build_googletest.cmake

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ macro(osrf_testing_tools_cpp_extract_and_build_googletest
4848

4949
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
5050
RESULT_VARIABLE result
51-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-${GOOGLETEST_VERSION}-extracted)
51+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-${GOOGLETEST_VERSION}-extracted)
5252
if(result)
5353
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
5454
endif()
5555

5656
execute_process(COMMAND ${CMAKE_COMMAND} --build .
5757
RESULT_VARIABLE result
58-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-${GOOGLETEST_VERSION}-extracted)
58+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-${GOOGLETEST_VERSION}-extracted)
5959
if(result)
6060
message(FATAL_ERROR "Build step for googletest failed: ${result}")
6161
endif()
@@ -74,13 +74,13 @@ macro(osrf_testing_tools_cpp_extract_and_build_googletest
7474
# add the -pthread flag for Linux machines so it will always work
7575
execute_process(COMMAND bash "-c" "sed -i 's@\${CMAKE_THREAD_LIBS_INIT}@\${CMAKE_THREAD_LIBS_INIT} -pthread@' ${__prefix}-src/googletest/cmake/internal_utils.cmake"
7676
RESULT_VARIABLE result
77-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${__prefix}-extracted)
77+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${__prefix}-extracted)
7878
endif()
7979
# Add googletest directly to our build. This defines
8080
# the gtest and gtest_main targets.
8181
add_subdirectory(
82-
${CMAKE_BINARY_DIR}/${__prefix}-extracted/${__prefix}-src
83-
${CMAKE_BINARY_DIR}/${__prefix}-extracted/${__prefix}-build
82+
${CMAKE_CURRENT_BINARY_DIR}/${__prefix}-extracted/${__prefix}-src
83+
${CMAKE_CURRENT_BINARY_DIR}/${__prefix}-extracted/${__prefix}-build
8484
EXCLUDE_FROM_ALL
8585
)
8686
unset(__prefix)

osrf_testing_tools_cpp/cmake/osrf_testing_tools_cpp_require_googletest.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ set(OSRF_TESTING_TOOLS_CPP_REQUIRE_GOOGLETEST_VERSION_SETUP)
4545
# @public
4646
#
4747
macro(osrf_testing_tools_cpp_require_googletest)
48+
if (TARGET gtest OR TARGET gtest_main)
49+
return()
50+
endif()
4851
# Make sure this was only called once.
4952
if(OSRF_TESTING_TOOLS_CPP_REQUIRE_GOOGLETEST_VERSION_SETUP)
5053
set(error_msg "osrf_testing_tools_cpp_require_googletest():")

osrf_testing_tools_cpp/src/memory_tools/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ add_library(memory_tools SHARED
1313

1414
target_include_directories(memory_tools
1515
PUBLIC
16-
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
16+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
1717
$<INSTALL_INTERFACE:include>
1818
)
1919

@@ -97,4 +97,4 @@ install(EXPORT memory_tools_interpose
9797
set(memory_tools_extra_test_env "${memory_tools_extra_test_env}" PARENT_SCOPE)
9898
set(memory_tools_is_available "${memory_tools_is_available}" PARENT_SCOPE)
9999
set(memory_tools_src_dir_internal_testing_only
100-
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>" PARENT_SCOPE)
100+
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>" PARENT_SCOPE)

osrf_testing_tools_cpp/test/cmake/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ add_test(
33
NAME "test_osrf_testing_tools_cpp_filter_versions_cmake"
44
COMMAND
55
${CMAKE_COMMAND} -P
6-
"${CMAKE_SOURCE_DIR}/test/cmake/test_osrf_testing_tools_cpp_filter_versions.cmake"
6+
"${PROJECT_SOURCE_DIR}/test/cmake/test_osrf_testing_tools_cpp_filter_versions.cmake"
77
)

osrf_testing_tools_cpp/vendor/google/googletest/googletest-external-project-add.cmake.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ include(ExternalProject)
99
ExternalProject_Add(googletest
1010
URL "@GOOGLETEST_ARCHIVE_LOCATION@"
1111
URL_MD5 "@GOOGLETEST_MD5SUM@"
12-
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-@GOOGLETEST_VERSION@-src"
13-
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-@GOOGLETEST_VERSION@-build"
12+
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-@GOOGLETEST_VERSION@-src"
13+
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-@GOOGLETEST_VERSION@-build"
1414
CONFIGURE_COMMAND ""
1515
BUILD_COMMAND ""
1616
INSTALL_COMMAND ""

0 commit comments

Comments
 (0)