Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
mdbx-cmake: pthread workaround for buggy toolchain/cmake/buildroot.
Browse files Browse the repository at this point in the history
Change-Id: I0d95e783abbd10a63cd1595a9de50593e814a967
  • Loading branch information
erthink committed Oct 5, 2020
1 parent 8d4e799 commit 787eaaa
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,27 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

include(cmake/utils.cmake)
include(cmake/compiler.cmake)
include(cmake/profile.cmake)

# Workaround for `-pthread` toolchain/cmake bug
if(NOT APPLE AND NOT MSVC
AND CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_THREAD_LIBS_INIT
AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
check_compiler_flag("-pthread" CC_HAS_PTHREAD)
if(CC_HAS_PTHREAD AND NOT CMAKE_EXE_LINKER_FLAGS MATCHES "-pthread")
message(STATUS "Force add -pthread for linker flags to avoid troubles")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pthread")
endif()
endif()

CHECK_FUNCTION_EXISTS(pow NOT_NEED_LIBM)
if(NOT_NEED_LIBM)
set(LIB_MATH "")
Expand All @@ -190,8 +207,6 @@ else()
endif()
endif()

find_package(Threads REQUIRED)

if(SUBPROJECT)
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" OFF)
Expand Down Expand Up @@ -541,7 +556,7 @@ macro(target_setup_options TARGET)
endmacro()

macro(libmdbx_setup_libs TARGET MODE)
target_link_libraries(${TARGET} ${MODE} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${TARGET} ${MODE} Threads::Threads)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
target_link_libraries(${TARGET} ${MODE} ntdll.lib)
if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_AVOID_CRT)
Expand Down

0 comments on commit 787eaaa

Please sign in to comment.