Skip to content

Commit 2ed0026

Browse files
Merge pull request #10 from benaliabderrahmane/fix/rolling-cmake-probe
fix(build): stop Rolling CMake configure aborting in the localhost_only probe
2 parents bfbf725 + a3fafde commit 2ed0026

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎rmw_unix_socket_cpp/CMakeLists.txt‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,23 @@ find_package(rosidl_typesupport_fastrtps_cpp REQUIRED)
2222
# rmw_init_options_t::localhost_only was removed in Kilted (rmw >= 7.8).
2323
# Probe so we can keep setting it on older distros without breaking newer ones.
2424
include(CheckCXXSourceCompiles)
25-
set(_rmw_probe_saved_libs ${CMAKE_REQUIRED_LIBRARIES})
26-
set(CMAKE_REQUIRED_LIBRARIES rmw::rmw rcutils::rcutils)
25+
# The probe only needs the rmw headers, so feed it include dirs rather than
26+
# linking rmw::rmw / rcutils::rcutils. Linking the C rcutils target pulls its
27+
# INTERFACE_COMPILE_FEATURES (a C compile feature) into this CXX-only
28+
# try_compile; on toolchains where the scratch project doesn't enable C that
29+
# aborts configure with "No known features for C compiler" (seen on Rolling).
30+
set(_rmw_probe_saved_inc "${CMAKE_REQUIRED_INCLUDES}")
31+
# init_options.h pulls in rcutils/allocator.h, so the probe needs both the rmw
32+
# and rcutils include dirs (gathered without linking either target).
33+
set(CMAKE_REQUIRED_INCLUDES "")
34+
get_target_property(_rmw_probe_rmw_inc rmw::rmw INTERFACE_INCLUDE_DIRECTORIES)
35+
if(_rmw_probe_rmw_inc)
36+
list(APPEND CMAKE_REQUIRED_INCLUDES ${_rmw_probe_rmw_inc})
37+
endif()
38+
get_target_property(_rmw_probe_rcutils_inc rcutils::rcutils INTERFACE_INCLUDE_DIRECTORIES)
39+
if(_rmw_probe_rcutils_inc)
40+
list(APPEND CMAKE_REQUIRED_INCLUDES ${_rmw_probe_rcutils_inc})
41+
endif()
2742
check_cxx_source_compiles("
2843
#include <rmw/init_options.h>
2944
int main() {
@@ -32,7 +47,7 @@ int main() {
3247
return 0;
3348
}
3449
" RMW_HAS_LOCALHOST_ONLY)
35-
set(CMAKE_REQUIRED_LIBRARIES ${_rmw_probe_saved_libs})
50+
set(CMAKE_REQUIRED_INCLUDES "${_rmw_probe_saved_inc}")
3651

3752
add_library(rmw_unix_socket_cpp SHARED
3853
src/registry.cpp

0 commit comments

Comments
 (0)