mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
cmake: update threads
For consistency with other backend/provider selection, allow `USE_THREADS` to select the threads provider.
This commit is contained in:
@@ -25,10 +25,8 @@ option(BUILD_CLI "Build the command-line interface"
|
||||
option(BUILD_EXAMPLES "Build library usage example apps" OFF)
|
||||
option(BUILD_FUZZERS "Build the fuzz targets" OFF)
|
||||
|
||||
# Suggested functionality that may not be available on a per-platform basis
|
||||
option(USE_THREADS "Use threads for parallel processing when possible" ON)
|
||||
|
||||
# Feature enablement and backend selection
|
||||
set(USE_THREADS "" CACHE STRING "Use threads for parallel processing when possible. One of ON, OFF, or a specific provider: pthreads or win32. (Defaults to ON.)")
|
||||
set(USE_SSH "" CACHE STRING "Enables SSH support and optionally selects provider. One of ON, OFF, or a specific provider: libssh2 or exec. (Defaults to OFF.)")
|
||||
set(USE_HTTPS "" CACHE STRING "Enable HTTPS support and optionally selects the provider. One of ON, OFF, or a specific provider: OpenSSL, OpenSSL-FIPS, OpenSSL-Dynamic, mbedTLS, SecureTransport, Schannel, or WinHTTP. (Defaults to ON.)")
|
||||
set(USE_SHA1 "" CACHE STRING "Selects SHA1 provider. One of builtin, HTTPS, or a specific provider. (Defaults to builtin.)")
|
||||
|
||||
41
cmake/SelectThreads.cmake
Normal file
41
cmake/SelectThreads.cmake
Normal file
@@ -0,0 +1,41 @@
|
||||
include(SanitizeBool)
|
||||
|
||||
sanitizebool(USE_THREADS)
|
||||
|
||||
if(NOT WIN32)
|
||||
find_package(Threads)
|
||||
endif()
|
||||
|
||||
if((USE_THREADS STREQUAL ON OR USE_THREADS STREQUAL "") AND THREADS_FOUND)
|
||||
set(USE_THREADS "pthreads")
|
||||
elseif((USE_THREADS STREQUAL ON OR USE_THREADS STREQUAL "") AND WIN32)
|
||||
set(USE_THREADS "win32")
|
||||
elseif(USE_THREADS STREQUAL "")
|
||||
set(USE_THREADS OFF)
|
||||
endif()
|
||||
|
||||
if(USE_THREADS STREQUAL "pthreads")
|
||||
if(NOT THREADS_FOUND)
|
||||
message(FATAL_ERROR "pthreads were requested but not found")
|
||||
endif()
|
||||
|
||||
list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
set(GIT_THREADS 1)
|
||||
set(GIT_THREADS_PTHREADS 1)
|
||||
add_feature_info("Threads" ON "using pthreads")
|
||||
elseif(USE_THREADS STREQUAL "win32")
|
||||
if(NOT WIN32)
|
||||
message(FATAL_ERROR "Win32 API support is not available on this platform")
|
||||
endif()
|
||||
|
||||
set(GIT_THREADS 1)
|
||||
set(GIT_THREADS_WIN32 1)
|
||||
add_feature_info("Threads" ON "using Win32 APIs")
|
||||
elseif(USE_THREADS STREQUAL OFF)
|
||||
set(GIT_THREADS 0)
|
||||
add_feature_info("Threads" OFF "threads support is disabled")
|
||||
else()
|
||||
message(FATAL_ERROR "unknown threads option: ${USE_THREADS}")
|
||||
endif()
|
||||
@@ -36,6 +36,7 @@ add_feature_info(debugopen GIT_DEBUG_STRICT_OPEN "path validation in open")
|
||||
# Optional feature enablement
|
||||
#
|
||||
|
||||
include(SelectThreads)
|
||||
include(SelectNsec)
|
||||
include(SelectHTTPSBackend)
|
||||
include(SelectHashes)
|
||||
@@ -141,19 +142,6 @@ if(AMIGA)
|
||||
add_definitions(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP)
|
||||
endif()
|
||||
|
||||
# threads
|
||||
|
||||
if(USE_THREADS)
|
||||
if(NOT WIN32)
|
||||
find_package(Threads REQUIRED)
|
||||
list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
set(GIT_THREADS 1)
|
||||
endif()
|
||||
add_feature_info(threadsafe USE_THREADS "threadsafe support")
|
||||
|
||||
#
|
||||
# Include child projects
|
||||
#
|
||||
|
||||
@@ -116,10 +116,12 @@ const char *git_libgit2_feature_backend(git_feature_t feature)
|
||||
{
|
||||
switch (feature) {
|
||||
case GIT_FEATURE_THREADS:
|
||||
#if defined(GIT_THREADS) && defined(GIT_WIN32)
|
||||
#if defined(GIT_THREADS_PTHREADS)
|
||||
return "pthread";
|
||||
#elif defined(GIT_THREADS_WIN32)
|
||||
return "win32";
|
||||
#elif defined(GIT_THREADS)
|
||||
return "pthread";
|
||||
GIT_ASSERT_WITH_RETVAL(!"Unknown threads backend", NULL);
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#cmakedefine GIT_DEBUG_STRICT_OPEN 1
|
||||
|
||||
#cmakedefine GIT_THREADS 1
|
||||
#cmakedefine GIT_THREADS_PTHREADS 1
|
||||
#cmakedefine GIT_THREADS_WIN32 1
|
||||
|
||||
#cmakedefine GIT_WIN32_LEAKCHECK 1
|
||||
|
||||
#cmakedefine GIT_ARCH_64 1
|
||||
|
||||
@@ -82,10 +82,12 @@ void test_core_features__backends(void)
|
||||
const char *sha1 = git_libgit2_feature_backend(GIT_FEATURE_SHA1);
|
||||
const char *sha256 = git_libgit2_feature_backend(GIT_FEATURE_SHA256);
|
||||
|
||||
#if defined(GIT_THREADS) && defined(GIT_WIN32)
|
||||
#if defined(GIT_THREADS_WIN32)
|
||||
cl_assert_equal_s("win32", threads);
|
||||
#elif defined(GIT_THREADS)
|
||||
#elif defined(GIT_THREADS_PTHREADS)
|
||||
cl_assert_equal_s("pthread", threads);
|
||||
#elif defined(GIT_THREADS)
|
||||
cl_assert(0);
|
||||
#else
|
||||
cl_assert(threads == NULL);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user