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) ...@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.5.1)
project(libgit2 VERSION "1.3.0" LANGUAGES C) project(libgit2 VERSION "1.3.0" LANGUAGES C)
# Add find modules to the path # 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 # Modules
...@@ -30,12 +30,15 @@ include(EnableWarnings) ...@@ -30,12 +30,15 @@ include(EnableWarnings)
# #
# Optional subsystems # Optional subsystems
option(THREADSAFE "Build libgit2 as threadsafe" ON)
option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
option(BUILD_TESTS "Build Tests using the Clar suite" ON) option(BUILD_TESTS "Build Tests using the Clar suite" ON)
option(BUILD_EXAMPLES "Build library usage example apps" OFF) option(BUILD_EXAMPLES "Build library usage example apps" OFF)
option(BUILD_FUZZERS "Build the fuzz targets" 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 # Backend selection
option(USE_SSH "Link with libssh2 to enable SSH support" ON) 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) 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" ...@@ -55,7 +58,7 @@ option(DEBUG_STRICT_OPEN "Enable path validation in open"
# Output options # Output options
option(SONAME "Set the (SO)VERSION of the target" ON) option(SONAME "Set the (SO)VERSION of the target" ON)
option(LIBGIT2_FILENAME "Name of the produced binary" OFF) 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 # Compilation options
option(ENABLE_WERROR "Enable compilation with -Werror" OFF) option(ENABLE_WERROR "Enable compilation with -Werror" OFF)
...@@ -63,35 +66,35 @@ option(ENABLE_WERROR "Enable compilation with -Werror" ...@@ -63,35 +66,35 @@ option(ENABLE_WERROR "Enable compilation with -Werror"
if(UNIX) if(UNIX)
# NTLM client requires crypto libraries from the system HTTPS stack # NTLM client requires crypto libraries from the system HTTPS stack
if(NOT USE_HTTPS) if(NOT USE_HTTPS)
option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF) option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF)
else() else()
option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON) option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON)
endif() endif()
option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF) option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)
endif() endif()
if(APPLE) if(APPLE)
option(USE_ICONV "Link with and use iconv library" ON) option(USE_ICONV "Link with and use iconv library" ON)
endif() endif()
if(MSVC) if(MSVC)
# This option must match the settings used in your program, in particular if you # This option must match the settings used in your program, in particular if you
# are linking statically # 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 # If you want to embed a copy of libssh2 into libgit2, pass a
# path to libssh2 # 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. # 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() endif()
if(WIN32) if(WIN32)
# By default, libgit2 is built with WinHTTP. To use the built-in # By default, libgit2 is built with WinHTTP. To use the built-in
# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument. # HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
option(WINHTTP "Use Win32 WinHTTP routines" ON) option(WINHTTP "Use Win32 WinHTTP routines" ON)
endif() endif()
......
...@@ -279,7 +279,7 @@ The following CMake variables are declared: ...@@ -279,7 +279,7 @@ The following CMake variables are declared:
- `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to. - `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to.
- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON) - `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
- `BUILD_TESTS`: Build the unit and integration test suites (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 To list all build options and their current value, you can do the
following: 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) 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) 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) HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C)
IF (HAVE_STRUCT_STAT_ST_MTIM) if(HAVE_STRUCT_STAT_ST_MTIM)
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h check_struct_has_member("struct stat" st_mtim.tv_nsec sys/stat.h
HAVE_STRUCT_STAT_NSEC LANGUAGE C) HAVE_STRUCT_STAT_NSEC LANGUAGE C)
ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC) elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h check_struct_has_member("struct stat" st_mtimespec.tv_nsec sys/stat.h
HAVE_STRUCT_STAT_NSEC LANGUAGE C) HAVE_STRUCT_STAT_NSEC LANGUAGE C)
ELSE () else()
SET( HAVE_STRUCT_STAT_NSEC ON ) set(HAVE_STRUCT_STAT_NSEC ON )
ENDIF() endif()
IF (HAVE_STRUCT_STAT_NSEC OR WIN32) add_feature_info(nanoseconds USE_NSEC "support nanosecond precision file mtimes and ctimes")
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")
...@@ -21,7 +21,7 @@ critical failures (such as a packfile being corrupted, a loose object ...@@ -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. having the wrong access permissions, etc.) all of which will return -1.
When the object lookup is successful, it will return 0. 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 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 will not be modified by other threads. If threads are not enabled, then
the error message is in global data. the error message is in global data.
......
...@@ -81,11 +81,11 @@ if(NEED_LIBRT) ...@@ -81,11 +81,11 @@ if(NEED_LIBRT)
list(APPEND LIBGIT2_PC_LIBS "-lrt") list(APPEND LIBGIT2_PC_LIBS "-lrt")
endif() endif()
if(THREADSAFE) if(USE_THREADS)
list(APPEND LIBGIT2_LIBS ${CMAKE_THREAD_LIBS_INIT}) list(APPEND LIBGIT2_LIBS ${CMAKE_THREAD_LIBS_INIT})
list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT}) list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
endif() endif()
add_feature_info(threadsafe THREADSAFE "threadsafe support") add_feature_info(threadsafe USE_THREADS "threadsafe support")
if(WIN32 AND EMBED_SSH_PATH) if(WIN32 AND EMBED_SSH_PATH)
...@@ -277,7 +277,7 @@ endif() ...@@ -277,7 +277,7 @@ endif()
add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support") add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support")
if(THREADSAFE) if(USE_THREADS)
if(NOT WIN32) if(NOT WIN32)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
endif() endif()
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#if defined(__clang__) #if defined(__clang__)
# if (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 1)) # 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 # else
# define GIT_BUILTIN_ATOMIC # define GIT_BUILTIN_ATOMIC
# endif # endif
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#elif defined(__GNUC__) #elif defined(__GNUC__)
# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)) # 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)) # elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
# define GIT_BUILTIN_ATOMIC # define GIT_BUILTIN_ATOMIC
# else # 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