Merge pull request #6886 from libgit2/ethomson/preciousobjects
[libgit2/github.git] / CMakeLists.txt
blob578ec177729a540baf443edd4c2190951af2e07b
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")
15 # Build options
18 # Experimental features
19 option(EXPERIMENTAL_SHA256     "Enable experimental SHA256 support (for R&D/testing)"  OFF)
21 # Optional subsystems
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)
32 # Backend selection
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)
43 # Debugging options
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)
50 # Output options
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)
55 # Compilation options
56 option(ENABLE_WERROR           "Enable compilation with -Werror"                       OFF)
58 if(UNIX)
59         # NTLM client requires crypto libraries from the system HTTPS stack
60         if(NOT USE_HTTPS)
61                 option(USE_NTLMCLIENT  "Enable NTLM support on Unix."                  OFF)
62         else()
63                 option(USE_NTLMCLIENT  "Enable NTLM support on Unix."                   ON)
64         endif()
66         option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds"                 OFF)
67 endif()
69 if(APPLE)
70         option(USE_ICONV           "Link with and use iconv library"                    ON)
71 endif()
73 if(MSVC)
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
79         # path to libssh2
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)
84 endif()
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)
88 endif()
91 # Modules
93 include(CheckLibraryExists)
94 include(CheckFunctionExists)
95 include(CheckSymbolExists)
96 include(CheckStructHasMember)
97 include(CheckPrototypeDefinitionSafe)
98 include(AddCFlagIfSupported)
99 include(FindPkgLibraries)
100 include(FindThreads)
101 include(FindStatNsec)
102 include(Findfutimens)
103 include(GNUInstallDirs)
104 include(IdeSplitSources)
105 include(FeatureSummary)
106 include(EnableWarnings)
107 include(DefaultCFlags)
108 include(ExperimentalFeatures)
112 # Subdirectories
115 add_subdirectory(src)
117 if(BUILD_TESTS)
118         enable_testing()
119         add_subdirectory(tests)
120 endif()
122 if(BUILD_EXAMPLES)
123         add_subdirectory(examples)
124 endif()
126 if(BUILD_FUZZERS)
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")
129         endif()
130         add_subdirectory(fuzzers)
131 endif()
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)
139 endif()
142 # Summary
144 feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
145 feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")