Skip to content

Commit a38e6e7

Browse files
authored
Merge pull request #3102 from SunBlack/fix_threading_library_dependency
Add thread library of the system by Threads::Threads instead of via -pthread flag
2 parents b51bf29 + 73bf70d commit a38e6e7

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
112112
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}")
113113
endif()
114114

115-
if(NOT ANDROID)
116-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
117-
endif()
118-
119115
if("${CMAKE_SHARED_LINKER_FLAGS}" STREQUAL "" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
120116
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
121117
endif()
@@ -179,7 +175,7 @@ endif()
179175

180176
if(CMAKE_COMPILER_IS_PATHSCALE)
181177
if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
182-
set(CMAKE_CXX_FLAGS "-Wno-uninitialized -zerouv -pthread -mp")
178+
set(CMAKE_CXX_FLAGS "-Wno-uninitialized -zerouv -mp")
183179
endif()
184180
if("${CMAKE_SHARED_LINKER_FLAGS}" STREQUAL "")
185181
set(CMAKE_SHARED_LINKER_FLAGS "-mp")
@@ -280,6 +276,9 @@ else()
280276
message(STATUS "Not found OpenMP")
281277
endif()
282278

279+
# Threads (required)
280+
find_package(Threads REQUIRED)
281+
283282
# Eigen (required)
284283
find_package(Eigen 3.1 REQUIRED)
285284
include_directories(SYSTEM ${EIGEN_INCLUDE_DIRS})

cmake/pcl_targets.cmake

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function(PCL_ADD_LIBRARY _name)
223223
PCL_ADD_VERSION_INFO(${_name})
224224
target_compile_features(${_name} PUBLIC ${PCL_CXX_COMPILE_FEATURES})
225225
# must link explicitly against boost.
226-
target_link_libraries(${_name} ${Boost_LIBRARIES})
226+
target_link_libraries(${_name} ${Boost_LIBRARIES} Threads::Threads)
227227
if((UNIX AND NOT ANDROID) OR MINGW)
228228
target_link_libraries(${_name} m)
229229
endif()
@@ -302,11 +302,7 @@ function(PCL_ADD_EXECUTABLE _name)
302302
endif()
303303
PCL_ADD_VERSION_INFO(${_name})
304304
# must link explicitly against boost.
305-
if(UNIX AND NOT ANDROID)
306-
target_link_libraries(${_name} ${Boost_LIBRARIES} pthread m ${CLANG_LIBRARIES})
307-
else()
308-
target_link_libraries(${_name} ${Boost_LIBRARIES})
309-
endif()
305+
target_link_libraries(${_name} ${Boost_LIBRARIES} Threads::Threads)
310306

311307
if(WIN32 AND MSVC)
312308
set_target_properties(${_name} PROPERTIES DEBUG_OUTPUT_NAME ${_name}${CMAKE_DEBUG_POSTFIX}
@@ -384,12 +380,7 @@ macro(PCL_ADD_TEST _name _exename)
384380
#target_link_libraries(${_exename} ${GTEST_BOTH_LIBRARIES} ${PCL_ADD_TEST_LINK_WITH})
385381
target_link_libraries(${_exename} ${PCL_ADD_TEST_LINK_WITH} ${CLANG_LIBRARIES})
386382

387-
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
388-
target_link_libraries(${_exename} pthread)
389-
elseif(UNIX AND NOT ANDROID)
390-
# GTest >= 1.5 requires pthread and CMake's 2.8.4 FindGTest is broken
391-
target_link_libraries(${_exename} pthread)
392-
endif()
383+
target_link_libraries(${_exename} Threads::Threads)
393384

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

0 commit comments

Comments
 (0)