Skip to content

Commit 9324d16

Browse files
committed
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 parent ceddeed commit 9324d16

File tree

6 files changed

+33
-36
lines changed

6 files changed

+33
-36
lines changed

CMakeLists.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.5.1)
66
project(libgit2 VERSION "1.3.0" LANGUAGES C)
77

88
# Add find modules to the path
9-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/")
9+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake")
1010

1111
# Modules
1212

@@ -30,12 +30,15 @@ include(EnableWarnings)
3030
#
3131

3232
# Optional subsystems
33-
option(THREADSAFE "Build libgit2 as threadsafe" ON)
3433
option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
3534
option(BUILD_TESTS "Build Tests using the Clar suite" ON)
3635
option(BUILD_EXAMPLES "Build library usage example apps" OFF)
3736
option(BUILD_FUZZERS "Build the fuzz targets" OFF)
3837

38+
# Suggested functionality that may not be available on a per-platform basis
39+
option(USE_THREADS "Use threads for parallel processing when possible" ON)
40+
option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON)
41+
3942
# Backend selection
4043
option(USE_SSH "Link with libssh2 to enable SSH support" ON)
4144
option(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON)
@@ -55,43 +58,43 @@ option(DEBUG_STRICT_OPEN "Enable path validation in open"
5558
# Output options
5659
option(SONAME "Set the (SO)VERSION of the target" ON)
5760
option(LIBGIT2_FILENAME "Name of the produced binary" OFF)
58-
option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
61+
option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
5962

6063
# Compilation options
6164
option(ENABLE_WERROR "Enable compilation with -Werror" OFF)
6265

6366
if(UNIX)
6467
# NTLM client requires crypto libraries from the system HTTPS stack
6568
if(NOT USE_HTTPS)
66-
option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF)
69+
option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF)
6770
else()
68-
option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON)
71+
option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON)
6972
endif()
7073

71-
option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)
74+
option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)
7275
endif()
7376

7477
if(APPLE)
75-
option(USE_ICONV "Link with and use iconv library" ON)
78+
option(USE_ICONV "Link with and use iconv library" ON)
7679
endif()
7780

7881
if(MSVC)
7982
# This option must match the settings used in your program, in particular if you
8083
# are linking statically
81-
option(STATIC_CRT "Link the static CRT libraries" ON)
84+
option(STATIC_CRT "Link the static CRT libraries" ON)
8285

8386
# If you want to embed a copy of libssh2 into libgit2, pass a
8487
# path to libssh2
85-
option(EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF)
88+
option(EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF)
8689

8790
# Enable leak checking using the debugging C runtime.
88-
option(WIN32_LEAKCHECK "Enable leak reporting via crtdbg" OFF)
91+
option(WIN32_LEAKCHECK "Enable leak reporting via crtdbg" OFF)
8992
endif()
9093

9194
if(WIN32)
9295
# By default, libgit2 is built with WinHTTP. To use the built-in
9396
# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
94-
option(WINHTTP "Use Win32 WinHTTP routines" ON)
97+
option(WINHTTP "Use Win32 WinHTTP routines" ON)
9598
endif()
9699

97100

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ The following CMake variables are declared:
279279
- `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to.
280280
- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
281281
- `BUILD_TESTS`: Build the unit and integration test suites (defaults to ON)
282-
- `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
282+
- `USE_THREADS`: Build libgit2 with threading support (defaults to ON)
283283

284284
To list all build options and their current value, you can do the
285285
following:

cmake/FindStatNsec.cmake

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1-
INCLUDE(FeatureSummary)
1+
include(FeatureSummary)
22

3-
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
3+
check_struct_has_member("struct stat" st_mtim "sys/types.h;sys/stat.h"
44
HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
5-
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
5+
check_struct_has_member("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
66
HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C)
7-
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h
7+
check_struct_has_member("struct stat" st_mtime_nsec sys/stat.h
88
HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C)
99

10-
IF (HAVE_STRUCT_STAT_ST_MTIM)
11-
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
10+
if(HAVE_STRUCT_STAT_ST_MTIM)
11+
check_struct_has_member("struct stat" st_mtim.tv_nsec sys/stat.h
1212
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
13-
ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC)
14-
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h
13+
elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
14+
check_struct_has_member("struct stat" st_mtimespec.tv_nsec sys/stat.h
1515
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
16-
ELSE ()
17-
SET( HAVE_STRUCT_STAT_NSEC ON )
18-
ENDIF()
16+
else()
17+
set(HAVE_STRUCT_STAT_NSEC ON )
18+
endif()
1919

20-
IF (HAVE_STRUCT_STAT_NSEC OR WIN32)
21-
OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON )
22-
ELSE()
23-
SET(USE_NSEC OFF)
24-
ENDIF()
25-
26-
ADD_FEATURE_INFO(nanoseconds USE_NSEC "whether to use sub-second file mtimes and ctimes")
20+
add_feature_info(nanoseconds USE_NSEC "support nanosecond precision file mtimes and ctimes")

docs/error-handling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ critical failures (such as a packfile being corrupted, a loose object
2121
having the wrong access permissions, etc.) all of which will return -1.
2222
When the object lookup is successful, it will return 0.
2323

24-
If libgit2 was compiled with threads enabled (`-DTHREADSAFE=ON` when using
24+
If libgit2 was compiled with threads enabled (`-DUSE_THREADS=ON` when using
2525
CMake), then the error message will be kept in thread-local storage, so it
2626
will not be modified by other threads. If threads are not enabled, then
2727
the error message is in global data.

src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ if(NEED_LIBRT)
8181
list(APPEND LIBGIT2_PC_LIBS "-lrt")
8282
endif()
8383

84-
if(THREADSAFE)
84+
if(USE_THREADS)
8585
list(APPEND LIBGIT2_LIBS ${CMAKE_THREAD_LIBS_INIT})
8686
list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
8787
endif()
88-
add_feature_info(threadsafe THREADSAFE "threadsafe support")
88+
add_feature_info(threadsafe USE_THREADS "threadsafe support")
8989

9090

9191
if(WIN32 AND EMBED_SSH_PATH)
@@ -277,7 +277,7 @@ endif()
277277
add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support")
278278

279279

280-
if(THREADSAFE)
280+
if(USE_THREADS)
281281
if(NOT WIN32)
282282
find_package(Threads REQUIRED)
283283
endif()

src/thread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
#if defined(__clang__)
1313

1414
# if (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 1))
15-
# error Atomic primitives do not exist on this version of clang; configure libgit2 with -DTHREADSAFE=OFF
15+
# error Atomic primitives do not exist on this version of clang; configure libgit2 with -DUSE_THREADS=OFF
1616
# else
1717
# define GIT_BUILTIN_ATOMIC
1818
# endif
1919

2020
#elif defined(__GNUC__)
2121

2222
# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1))
23-
# error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DTHREADSAFE=OFF
23+
# error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DUSE_THREADS=OFF
2424
# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
2525
# define GIT_BUILTIN_ATOMIC
2626
# else

0 commit comments

Comments
 (0)