Skip to content

Commit

Permalink
Fix -pthread handling in Debian buster
Browse files Browse the repository at this point in the history
FindBoost.cmake blindly adds `${CMAKE_THREAD_LIBS_INIT}` to
`${Boost_LIBRARIES}` when the component `thread` is found.
On Debian buster the `FindThreads.cmake` sets that to `-pthread`.
This breaks a bunch of stuff becakse `-pthread` is a linker flag, not a
library.

There were earlier fixes for `-lpthread`.
This PR expands upon them.
First this PR modifies the fix from ros#998 to not add `-l` to any linker flag.
Second it adds to the fix in ros#975 to make sure `-pthread` is passed to
downstream users.
There's no standard cmake variable for linker flags, so this PR opts to
create an interface target with just the flag, and add that to
`${PROJECT_NAME}_LIBRARIES` instead.

Both this PR and ros-visualization/python_qt_binding#68 are required to strip or `qt_gui_cpp` will fail at link time.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
  • Loading branch information
sloretz committed Aug 3, 2019
1 parent 4a73103 commit 524306a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmake/catkin_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ function(_catkin_package)
catkin_filter_libraries_for_build_configuration(libraries ${PKG_CONFIG_LIBRARIES})
foreach(library ${libraries})
if(NOT IS_ABSOLUTE ${library})
if(NOT ${library} MATCHES "^-l")
# Append -l to anything that's not a linker flag
if(NOT ${library} MATCHES "^-")
set(library "-l${library}")
endif()
endif()
Expand Down
16 changes: 16 additions & 0 deletions cmake/templates/pkgConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ foreach(library ${libraries})
list(APPEND @PROJECT_NAME@_LIBRARIES ${library})
elseif(${library} MATCHES "^-l")
list(APPEND @PROJECT_NAME@_LIBRARIES ${library})
elseif(${library} MATCHES "^-")
# This is a linker flag/option (like -pthread)
# There's no standard variable for these, so create an interface library to hold it
if(NOT @PROJECT_NAME@_NUM_DUMMY_TARGETS)
set(@PROJECT_NAME@_NUM_DUMMY_TARGETS 0)
endif()
MATH(EXPR VAR "${@PROJECT_NAME@_NUM_DUMMY_TARGETS}+1")
add_library("catkin::@PROJECT_NAME@::dummy${@PROJECT_NAME@_NUM_DUMMY_TARGETS}" INTERFACE IMPORTED)
if("${CMAKE_VERSION}" VERSION_LESS "3.13.0")
set_target_properties(
"catkin::@PROJECT_NAME@::dummy${@PROJECT_NAME@_NUM_DUMMY_TARGETS}"
PROPERTIES LINK_FLAGS $<TARGET_PROPERTY:LINK_FLAGS> "${library}")
else()
target_link_options("catkin::@PROJECT_NAME@::dummy${@PROJECT_NAME@_NUM_DUMMY_TARGETS}" INTERFACE "${library}")
endif()
list(APPEND @PROJECT_NAME@_LIBRARIES "catkin::@PROJECT_NAME@::dummy${@PROJECT_NAME@_NUM_DUMMY_TARGETS}")
elseif(TARGET ${library})
list(APPEND @PROJECT_NAME@_LIBRARIES ${library})
elseif(IS_ABSOLUTE ${library})
Expand Down

0 comments on commit 524306a

Please sign in to comment.