1 # libgit2: the cross-platform, linkable library implementation of git.
2 # See `README.md` for build instructions.
4 # This top-level CMakeLists.txt sets up configuration options and
5 # determines which subprojects to build.
7 cmake_minimum_required(VERSION 3.5.1)
9 project(libgit2 VERSION "1.8.2" LANGUAGES C)
11 # Add find modules to the path
12 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
18 # Experimental features
19 option(EXPERIMENTAL_SHA256 "Enable experimental SHA256 support (for R&D/testing)" OFF)
22 option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
23 option(BUILD_TESTS "Build Tests using the Clar suite" ON)
24 option(BUILD_CLI "Build the command-line interface" ON)
25 option(BUILD_EXAMPLES "Build library usage example apps" OFF)
26 option(BUILD_FUZZERS "Build the fuzz targets" OFF)
28 # Suggested functionality that may not be available on a per-platform basis
29 option(USE_THREADS "Use threads for parallel processing when possible" ON)
30 option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON)
33 option(USE_SSH "Enable SSH support. Can be set to a specific backend" OFF)
34 option(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON)
35 option(USE_SHA1 "Enable SHA1. Can be set to CollisionDetection(ON)/HTTPS" ON)
36 option(USE_SHA256 "Enable SHA256. Can be set to HTTPS/Builtin" ON)
37 option(USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF)
38 set(USE_HTTP_PARSER "" CACHE STRING "Specifies the HTTP Parser implementation; either system or builtin.")
39 # set(USE_XDIFF "" CACHE STRING "Specifies the xdiff implementation; either system or builtin.")
40 set(REGEX_BACKEND "" CACHE STRING "Regular expression implementation. One of regcomp_l, pcre2, pcre, regcomp, or builtin.")
41 option(USE_BUNDLED_ZLIB "Use the bundled version of zlib. Can be set to one of Bundled(ON)/Chromium. The Chromium option requires a x86_64 processor with SSE4.2 and CLMUL" OFF)
44 option(USE_LEAK_CHECKER "Run tests with leak checker" OFF)
45 option(USE_STANDALONE_FUZZERS "Enable standalone fuzzers (compatible with gcc)" OFF)
46 option(DEBUG_POOL "Enable debug pool allocator" OFF)
47 option(DEBUG_STRICT_ALLOC "Enable strict allocator behavior" OFF)
48 option(DEBUG_STRICT_OPEN "Enable path validation in open" OFF)
51 option(SONAME "Set the (SO)VERSION of the target" ON)
52 set(LIBGIT2_FILENAME "git2" CACHE STRING "Name of the produced binary")
53 option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
56 option(ENABLE_WERROR "Enable compilation with -Werror" OFF)
59 # NTLM client requires crypto libraries from the system HTTPS stack
61 option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF)
63 option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON)
66 option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)
70 option(USE_ICONV "Link with and use iconv library" ON)
74 # This option must match the settings used in your program, in particular if you
75 # are linking statically
76 option(STATIC_CRT "Link the static CRT libraries" ON)
78 # If you want to embed a copy of libssh2 into libgit2, pass a
80 option(EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF)
82 # Enable leak checking using the debugging C runtime.
83 option(WIN32_LEAKCHECK "Enable leak reporting via crtdbg" OFF)
86 if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
87 set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
93 include(CheckLibraryExists)
94 include(CheckFunctionExists)
95 include(CheckSymbolExists)
96 include(CheckStructHasMember)
97 include(CheckPrototypeDefinitionSafe)
98 include(AddCFlagIfSupported)
99 include(FindPkgLibraries)
101 include(FindStatNsec)
102 include(Findfutimens)
103 include(GNUInstallDirs)
104 include(IdeSplitSources)
105 include(FeatureSummary)
106 include(EnableWarnings)
107 include(DefaultCFlags)
108 include(ExperimentalFeatures)
115 add_subdirectory(src)
119 add_subdirectory(tests)
123 add_subdirectory(examples)
127 if((BUILD_TESTS OR BUILD_EXAMPLES) AND NOT USE_STANDALONE_FUZZERS)
128 message(FATAL_ERROR "Cannot build the fuzzer and the tests or examples together")
130 add_subdirectory(fuzzers)
134 # Export for people who use us as a dependency
136 if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
137 set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE)
138 set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE)
144 feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
145 feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")