cmake: standardize USE_THREADS and USE_NSEC Threading can now be disabled with `USE_THREADS=OFF` instead of `THREADSAFE=OFF` to better support the other cmake semantics. Nanosecond support is the default _if_ we can detect it. This should be our default always - like threads - and people can opt out explicitly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f7b2e71..2c442d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.5.1)
project(libgit2 VERSION "1.3.0" LANGUAGES C)
# Add find modules to the path
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/")
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake")
# Modules
@@ -30,12 +30,15 @@ include(EnableWarnings)
#
# Optional subsystems
-option(THREADSAFE "Build libgit2 as threadsafe" ON)
option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
option(BUILD_TESTS "Build Tests using the Clar suite" ON)
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)
+option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON)
+
# Backend selection
option(USE_SSH "Link with libssh2 to enable SSH support" ON)
option(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON)
@@ -55,7 +58,7 @@ option(DEBUG_STRICT_OPEN "Enable path validation in open"
# Output options
option(SONAME "Set the (SO)VERSION of the target" ON)
option(LIBGIT2_FILENAME "Name of the produced binary" OFF)
-option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
+option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
# Compilation options
option(ENABLE_WERROR "Enable compilation with -Werror" OFF)
@@ -63,35 +66,35 @@ option(ENABLE_WERROR "Enable compilation with -Werror"
if(UNIX)
# NTLM client requires crypto libraries from the system HTTPS stack
if(NOT USE_HTTPS)
- option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF)
+ option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF)
else()
- option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON)
+ option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON)
endif()
- option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)
+ option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)
endif()
if(APPLE)
- option(USE_ICONV "Link with and use iconv library" ON)
+ option(USE_ICONV "Link with and use iconv library" ON)
endif()
if(MSVC)
# This option must match the settings used in your program, in particular if you
# are linking statically
- option(STATIC_CRT "Link the static CRT libraries" ON)
+ option(STATIC_CRT "Link the static CRT libraries" ON)
# If you want to embed a copy of libssh2 into libgit2, pass a
# path to libssh2
- option(EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF)
+ option(EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF)
# Enable leak checking using the debugging C runtime.
- option(WIN32_LEAKCHECK "Enable leak reporting via crtdbg" OFF)
+ option(WIN32_LEAKCHECK "Enable leak reporting via crtdbg" OFF)
endif()
if(WIN32)
# By default, libgit2 is built with WinHTTP. To use the built-in
# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
- option(WINHTTP "Use Win32 WinHTTP routines" ON)
+ option(WINHTTP "Use Win32 WinHTTP routines" ON)
endif()
diff --git a/README.md b/README.md
index 2a365df..7ed5f6c 100644
--- a/README.md
+++ b/README.md
@@ -279,7 +279,7 @@ The following CMake variables are declared:
- `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to.
- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
- `BUILD_TESTS`: Build the unit and integration test suites (defaults to ON)
-- `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
+- `USE_THREADS`: Build libgit2 with threading support (defaults to ON)
To list all build options and their current value, you can do the
following:
diff --git a/cmake/FindStatNsec.cmake b/cmake/FindStatNsec.cmake
index a4a09fa..9dfdf51 100644
--- a/cmake/FindStatNsec.cmake
+++ b/cmake/FindStatNsec.cmake
@@ -1,26 +1,20 @@
-INCLUDE(FeatureSummary)
+include(FeatureSummary)
-CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
+check_struct_has_member("struct stat" st_mtim "sys/types.h;sys/stat.h"
HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
-CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
+check_struct_has_member("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C)
-CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h
+check_struct_has_member("struct stat" st_mtime_nsec sys/stat.h
HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C)
-IF (HAVE_STRUCT_STAT_ST_MTIM)
- CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
+if(HAVE_STRUCT_STAT_ST_MTIM)
+ check_struct_has_member("struct stat" st_mtim.tv_nsec sys/stat.h
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
-ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC)
- CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h
+elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
+ check_struct_has_member("struct stat" st_mtimespec.tv_nsec sys/stat.h
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
-ELSE ()
- SET( HAVE_STRUCT_STAT_NSEC ON )
-ENDIF()
+else()
+ set(HAVE_STRUCT_STAT_NSEC ON )
+endif()
-IF (HAVE_STRUCT_STAT_NSEC OR WIN32)
- OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON )
-ELSE()
- SET(USE_NSEC OFF)
-ENDIF()
-
-ADD_FEATURE_INFO(nanoseconds USE_NSEC "whether to use sub-second file mtimes and ctimes")
+add_feature_info(nanoseconds USE_NSEC "support nanosecond precision file mtimes and ctimes")
diff --git a/docs/error-handling.md b/docs/error-handling.md
index 05725f2..13ce78f 100644
--- a/docs/error-handling.md
+++ b/docs/error-handling.md
@@ -21,7 +21,7 @@ critical failures (such as a packfile being corrupted, a loose object
having the wrong access permissions, etc.) all of which will return -1.
When the object lookup is successful, it will return 0.
-If libgit2 was compiled with threads enabled (`-DTHREADSAFE=ON` when using
+If libgit2 was compiled with threads enabled (`-DUSE_THREADS=ON` when using
CMake), then the error message will be kept in thread-local storage, so it
will not be modified by other threads. If threads are not enabled, then
the error message is in global data.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9812fc0..de8beef 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -81,11 +81,11 @@ if(NEED_LIBRT)
list(APPEND LIBGIT2_PC_LIBS "-lrt")
endif()
-if(THREADSAFE)
+if(USE_THREADS)
list(APPEND LIBGIT2_LIBS ${CMAKE_THREAD_LIBS_INIT})
list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
endif()
-add_feature_info(threadsafe THREADSAFE "threadsafe support")
+add_feature_info(threadsafe USE_THREADS "threadsafe support")
if(WIN32 AND EMBED_SSH_PATH)
@@ -277,7 +277,7 @@ endif()
add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support")
-if(THREADSAFE)
+if(USE_THREADS)
if(NOT WIN32)
find_package(Threads REQUIRED)
endif()
diff --git a/src/thread.h b/src/thread.h
index 4b091c0..82eb7fc 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -12,7 +12,7 @@
#if defined(__clang__)
# if (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 1))
-# error Atomic primitives do not exist on this version of clang; configure libgit2 with -DTHREADSAFE=OFF
+# error Atomic primitives do not exist on this version of clang; configure libgit2 with -DUSE_THREADS=OFF
# else
# define GIT_BUILTIN_ATOMIC
# endif
@@ -20,7 +20,7 @@
#elif defined(__GNUC__)
# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1))
-# error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DTHREADSAFE=OFF
+# error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DUSE_THREADS=OFF
# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
# define GIT_BUILTIN_ATOMIC
# else