Skip to content

Commit

Permalink
Merge pull request #3102 from SunBlack/fix_threading_library_dependency
Browse files Browse the repository at this point in the history
Add thread library of the system by Threads::Threads instead of via -pthread flag
  • Loading branch information
taketwo authored May 30, 2019
2 parents b51bf29 + 73bf70d commit a38e6e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-Wabi -Wall -Wextra -Wno-unknown-pragmas -fno-strict-aliasing -Wno-format-extra-args -Wno-sign-compare -Wno-invalid-offsetof -Wno-conversion ${SSE_FLAGS_STR}")
endif()

if(NOT ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()

if("${CMAKE_SHARED_LINKER_FLAGS}" STREQUAL "" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
endif()
Expand Down Expand Up @@ -179,7 +175,7 @@ endif()

if(CMAKE_COMPILER_IS_PATHSCALE)
if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
set(CMAKE_CXX_FLAGS "-Wno-uninitialized -zerouv -pthread -mp")
set(CMAKE_CXX_FLAGS "-Wno-uninitialized -zerouv -mp")
endif()
if("${CMAKE_SHARED_LINKER_FLAGS}" STREQUAL "")
set(CMAKE_SHARED_LINKER_FLAGS "-mp")
Expand Down Expand Up @@ -280,6 +276,9 @@ else()
message(STATUS "Not found OpenMP")
endif()

# Threads (required)
find_package(Threads REQUIRED)

# Eigen (required)
find_package(Eigen 3.1 REQUIRED)
include_directories(SYSTEM ${EIGEN_INCLUDE_DIRS})
Expand Down
15 changes: 3 additions & 12 deletions cmake/pcl_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function(PCL_ADD_LIBRARY _name)
PCL_ADD_VERSION_INFO(${_name})
target_compile_features(${_name} PUBLIC ${PCL_CXX_COMPILE_FEATURES})
# must link explicitly against boost.
target_link_libraries(${_name} ${Boost_LIBRARIES})
target_link_libraries(${_name} ${Boost_LIBRARIES} Threads::Threads)
if((UNIX AND NOT ANDROID) OR MINGW)
target_link_libraries(${_name} m)
endif()
Expand Down Expand Up @@ -302,11 +302,7 @@ function(PCL_ADD_EXECUTABLE _name)
endif()
PCL_ADD_VERSION_INFO(${_name})
# must link explicitly against boost.
if(UNIX AND NOT ANDROID)
target_link_libraries(${_name} ${Boost_LIBRARIES} pthread m ${CLANG_LIBRARIES})
else()
target_link_libraries(${_name} ${Boost_LIBRARIES})
endif()
target_link_libraries(${_name} ${Boost_LIBRARIES} Threads::Threads)

if(WIN32 AND MSVC)
set_target_properties(${_name} PROPERTIES DEBUG_OUTPUT_NAME ${_name}${CMAKE_DEBUG_POSTFIX}
Expand Down Expand Up @@ -384,12 +380,7 @@ macro(PCL_ADD_TEST _name _exename)
#target_link_libraries(${_exename} ${GTEST_BOTH_LIBRARIES} ${PCL_ADD_TEST_LINK_WITH})
target_link_libraries(${_exename} ${PCL_ADD_TEST_LINK_WITH} ${CLANG_LIBRARIES})

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_libraries(${_exename} pthread)
elseif(UNIX AND NOT ANDROID)
# GTest >= 1.5 requires pthread and CMake's 2.8.4 FindGTest is broken
target_link_libraries(${_exename} pthread)
endif()
target_link_libraries(${_exename} Threads::Threads)

# must link explicitly against boost only on Windows
target_link_libraries(${_exename} ${Boost_LIBRARIES})
Expand Down

0 comments on commit a38e6e7

Please sign in to comment.