Commit 9324d16e by Edward Thomson

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.
parent ceddeed8
......@@ -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()
......
......@@ -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:
......
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")
......@@ -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.
......
......@@ -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()
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment