CMake: Use Threads instead of pthread directly

On some systems, such as Android, threads are not provided via
`-lpthread`.

CMake comes with a built-in module for finding the correct threads
library.

Use it to fix the linking issue on Android and possibly other systems.
This commit is contained in:
Gleb Mazovetskiy
2021-01-20 02:16:51 +00:00
parent 48514d038b
commit 6442613ba6
8 changed files with 22 additions and 11 deletions

View File

@@ -10,7 +10,8 @@ ADD_DEFINITIONS(-D_VARIADIC_MAX=10)
LINK_LIBRARIES(BulletDynamics BulletCollision LinearMath gtest)
IF (NOT WIN32)
LINK_LIBRARIES(pthread)
FIND_PACKAGE(Threads)
LINK_LIBRARIES( ${CMAKE_THREAD_LIBS_INIT} )
ENDIF()
ADD_EXECUTABLE(Test_btKinematicCharacterController test_btKinematicCharacterController.cpp)

View File

@@ -14,7 +14,8 @@ LINK_LIBRARIES(
)
IF (NOT WIN32)
LINK_LIBRARIES( pthread )
FIND_PACKAGE(Threads)
LINK_LIBRARIES( ${CMAKE_THREAD_LIBS_INIT} )
ENDIF()
ADD_EXECUTABLE(Test_BulletDynamics

View File

@@ -17,7 +17,8 @@ IF (BULLET_BUILD_RBDL_COMPARE_TEST)
LINK_LIBRARIES( BulletDynamics BulletCollision Bullet3Common LinearMath gtest rbdl_urdfreader rbdl)
ENDIF (MSVC)
IF (NOT WIN32)
LINK_LIBRARIES( pthread )
FIND_PACKAGE(Threads)
LINK_LIBRARIES( ${CMAKE_THREAD_LIBS_INIT} )
ENDIF()
@@ -81,7 +82,8 @@ LINK_LIBRARIES(
BulletInverseDynamicsUtils BulletInverseDynamics Bullet3Common LinearMath gtest
)
IF (NOT WIN32)
LINK_LIBRARIES( pthread )
FIND_PACKAGE(Threads)
LINK_LIBRARIES( ${CMAKE_THREAD_LIBS_INIT} )
ENDIF()
@@ -113,7 +115,8 @@ LINK_LIBRARIES(
BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics Bullet3Common LinearMath gtest
)
IF (NOT WIN32)
LINK_LIBRARIES( pthread )
FIND_PACKAGE(Threads)
LINK_LIBRARIES( ${CMAKE_THREAD_LIBS_INIT} )
ENDIF()
@@ -176,7 +179,8 @@ LINK_LIBRARIES(
BulletInverseDynamicsUtils BulletInverseDynamics Bullet3Common LinearMath gtest
)
IF (NOT WIN32)
LINK_LIBRARIES( pthread )
FIND_PACKAGE(Threads)
LINK_LIBRARIES( ${CMAKE_THREAD_LIBS_INIT} )
ENDIF()

View File

@@ -20,7 +20,8 @@ LINK_LIBRARIES(
)
IF (NOT WIN32)
LINK_LIBRARIES( pthread )
FIND_PACKAGE(Threads)
LINK_LIBRARIES( ${CMAKE_THREAD_LIBS_INIT} )
IF (NOT APPLE)
LINK_LIBRARIES(${DL})
ENDIF()

View File

@@ -14,7 +14,8 @@ LINK_LIBRARIES(
)
IF (NOT WIN32)
LINK_LIBRARIES( pthread )
FIND_PACKAGE(Threads)
LINK_LIBRARIES( ${CMAKE_THREAD_LIBS_INIT} )
ENDIF()
ADD_EXECUTABLE(Test_Collision