Skip to content

Commit

Permalink
Fix build when included with cmake_add_subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed Oct 24, 2019
1 parent fde512a commit b63e455
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion osrf_testing_tools_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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 "${PROJECT_SOURCE_DIR}/vendor")

add_subdirectory(test)
endif()
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 @@ -74,13 +74,13 @@ macro(osrf_testing_tools_cpp_extract_and_build_googletest
# add the -pthread flag for Linux machines so it will always work
execute_process(COMMAND bash "-c" "sed -i 's@\${CMAKE_THREAD_LIBS_INIT}@\${CMAKE_THREAD_LIBS_INIT} -pthread@' ${__prefix}-src/googletest/cmake/internal_utils.cmake"
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${__prefix}-extracted)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${__prefix}-extracted)
endif()
# 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()
# 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
4 changes: 2 additions & 2 deletions osrf_testing_tools_cpp/src/memory_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ add_library(memory_tools SHARED

target_include_directories(memory_tools
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

Expand Down Expand Up @@ -97,4 +97,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:${PROJECT_SOURCE_DIR}/src>" 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"
"${PROJECT_SOURCE_DIR}/test/cmake/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

0 comments on commit b63e455

Please sign in to comment.