]> git.proxmox.com Git - libgit2.git/blobdiff - CMakeLists.txt
Update d/ch for 1.1.0+dfsg.1-1 release
[libgit2.git] / CMakeLists.txt
index 88eb9ec10a2346e04b564265b02b13dc1fac99ec..b6f23cf6bf12acc19ded342c726c35140d75e514 100644 (file)
 # Install:
 # > cmake --build . --target install
 
-PROJECT(libgit2 C)
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
-CMAKE_POLICY(SET CMP0015 NEW)
-IF(POLICY CMP0051)
-       CMAKE_POLICY(SET CMP0051 NEW)
-ENDIF()
-IF(POLICY CMP0042)
-       CMAKE_POLICY(SET CMP0042 NEW)
-ENDIF()
-IF(POLICY CMP0054)
-       CMAKE_POLICY(SET CMP0054 NEW)
-ENDIF()
+CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1)
+
+project(libgit2 VERSION "1.1.0" LANGUAGES C)
 
 # Add find modules to the path
-SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/Modules/")
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/")
 
 INCLUDE(CheckLibraryExists)
 INCLUDE(CheckFunctionExists)
@@ -36,6 +27,7 @@ INCLUDE(AddCFlagIfSupported)
 INCLUDE(FindPkgLibraries)
 INCLUDE(FindThreads)
 INCLUDE(FindStatNsec)
+INCLUDE(GNUInstallDirs)
 INCLUDE(IdeSplitSources)
 INCLUDE(FeatureSummary)
 INCLUDE(EnableWarnings)
@@ -48,23 +40,28 @@ OPTION(THREADSAFE                   "Build libgit2 as threadsafe"                            ON)
 OPTION(BUILD_CLAR                      "Build Tests using the Clar suite"                       ON)
 OPTION(BUILD_EXAMPLES                  "Build library usage example apps"                      OFF)
 OPTION(BUILD_FUZZERS                   "Build the fuzz targets"                                OFF)
-OPTION(TAGS                            "Generate tags"                                         OFF)
-OPTION(PROFILE                         "Generate profiling information"                        OFF)
-OPTION(ENABLE_TRACE                    "Enables tracing support"                               OFF)
+OPTION(ENABLE_TRACE                    "Enables tracing support"                               ON)
 OPTION(LIBGIT2_FILENAME                        "Name of the produced binary"                           OFF)
-
-   SET(SHA1_BACKEND                    "CollisionDetection"                           CACHE STRING
-       "Backend to use for SHA1. One of Generic, OpenSSL, Win32, CommonCrypto, mbedTLS, CollisionDetection.")
 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_SHA1                                "Enable SHA1. Can be set to CollisionDetection(ON)/HTTPS/Generic" ON)
 OPTION(USE_GSSAPI                      "Link with libgssapi for SPNEGO auth"                   OFF)
 OPTION(USE_STANDALONE_FUZZERS          "Enable standalone fuzzers (compatible with gcc)"       OFF)
-OPTION(VALGRIND                                "Configure build for valgrind"                          OFF)
-OPTION(USE_EXT_HTTP_PARSER             "Use system HTTP_Parser if available"                    ON)
+OPTION(USE_LEAK_CHECKER                        "Run tests with leak checker"                           OFF)
 OPTION(DEBUG_POOL                      "Enable debug pool allocator"                           OFF)
 OPTION(ENABLE_WERROR                   "Enable compilation with -Werror"                       OFF)
 OPTION(USE_BUNDLED_ZLIB                "Use the bundled version of zlib"                       OFF)
+   SET(USE_HTTP_PARSER                 "" CACHE STRING "Specifies the HTTP Parser implementation; either system or builtin.")
 OPTION(DEPRECATE_HARD                  "Do not include deprecated functions in the library"    OFF)
+   SET(REGEX_BACKEND                   "" CACHE STRING "Regular expression implementation. One of regcomp_l, pcre2, pcre, regcomp, or builtin.")
+
+IF (UNIX)
+       IF (NOT USE_HTTPS)
+           OPTION(USE_NTLMCLIENT               "Enable NTLM support on Unix."                          OFF )
+       ELSE()
+           OPTION(USE_NTLMCLIENT               "Enable NTLM support on Unix."                          ON )
+       ENDIF()
+ENDIF()
 
 IF (UNIX AND NOT APPLE)
        OPTION(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds"                          OFF)
@@ -96,16 +93,6 @@ IF(MSVC)
        OPTION(MSVC_CRTDBG              "Enable CRTDBG memory leak reporting"                   OFF)
 ENDIF()
 
-FILE(STRINGS "${libgit2_SOURCE_DIR}/include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$")
-
-STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}")
-STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR  "${GIT2_HEADER}")
-STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}")
-SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}")
-
-FILE(STRINGS "${libgit2_SOURCE_DIR}/include/git2/version.h" GIT2_HEADER_SOVERSION REGEX "^#define LIBGIT2_SOVERSION [0-9]+$")
-STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION ([0-9]+)$" "\\1" LIBGIT2_SOVERSION "${GIT2_HEADER_SOVERSION}")
-
 IF (DEPRECATE_HARD)
        ADD_DEFINITIONS(-DGIT_DEPRECATE_HARD)
 ENDIF()
@@ -129,6 +116,11 @@ IF (MSVC)
        # /Gd - explicitly set cdecl calling convention
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd")
 
+       IF (NOT (MSVC_VERSION LESS 1900))
+               # /guard:cf - Enable Control Flow Guard
+               SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf")
+       ENDIF()
+
        IF (STATIC_CRT)
                SET(CRT_FLAG_DEBUG "/MTd")
                SET(CRT_FLAG_RELEASE "/MT")
@@ -173,7 +165,12 @@ IF (MSVC)
        # /NXCOMPAT - Data execution prevention (DEP)
        # /LARGEADDRESSAWARE - >2GB user address space on x86
        # /VERSION - Embed version information in PE header
-       SET(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}")
+       SET(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
+
+       IF (NOT (MSVC_VERSION LESS 1900))
+               # /GUARD:CF - Enable Control Flow Guard
+               SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF")
+       ENDIF()
 
        # /DEBUG - Create a PDB
        # /LTCG - Link time code generation (whole program optimization)
@@ -224,23 +221,32 @@ ELSE ()
                ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1)
        ENDIF ()
 
-       ENABLE_WARNINGS(documentation)
-       DISABLE_WARNINGS(missing-field-initializers)
-       ENABLE_WARNINGS(strict-aliasing)
-       ENABLE_WARNINGS(strict-prototypes)
-       ENABLE_WARNINGS(declaration-after-statement)
-       ENABLE_WARNINGS(shift-count-overflow)
-       ENABLE_WARNINGS(unused-const-variable)
-       ENABLE_WARNINGS(unused-function)
-       ENABLE_WARNINGS(format)
-       ENABLE_WARNINGS(format-security)
-       ENABLE_WARNINGS(int-conversion)
-       DISABLE_WARNINGS(documentation-deprecated-sync)
-
-       IF (PROFILE)
-               SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")
-               SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}")
-       ENDIF ()
+       enable_warnings(documentation)
+       disable_warnings(documentation-deprecated-sync)
+       disable_warnings(missing-field-initializers)
+       enable_warnings(strict-aliasing)
+       enable_warnings(strict-prototypes)
+       enable_warnings(declaration-after-statement)
+       enable_warnings(shift-count-overflow)
+       enable_warnings(unused-const-variable)
+       enable_warnings(unused-function)
+       enable_warnings(int-conversion)
+
+       # MinGW uses gcc, which expects POSIX formatting for printf, but
+       # uses the Windows C library, which uses its own format specifiers.
+       # Disable format specifier warnings.
+       if(MINGW)
+               disable_warnings(format)
+               disable_warnings(format-security)
+       else()
+               enable_warnings(format)
+               enable_warnings(format-security)
+       endif()
+ENDIF()
+
+# Ensure that MinGW provides the correct header files.
+IF (WIN32 AND NOT CYGWIN)
+       ADD_DEFINITIONS(-DWIN32 -D_WIN32_WINNT=0x0600)
 ENDIF()
 
 IF( NOT CMAKE_CONFIGURATION_TYPES )
@@ -275,25 +281,6 @@ IF (BUILD_CLAR)
        ADD_SUBDIRECTORY(tests)
 ENDIF ()
 
-IF (TAGS)
-       FIND_PROGRAM(CTAGS ctags)
-       IF (NOT CTAGS)
-               MESSAGE(FATAL_ERROR "Could not find ctags command")
-       ENDIF ()
-
-       FILE(GLOB_RECURSE SRC_ALL *.[ch])
-
-       ADD_CUSTOM_COMMAND(
-               OUTPUT tags
-               COMMAND ${CTAGS} -a ${SRC_ALL}
-               DEPENDS ${SRC_ALL}
-       )
-       ADD_CUSTOM_TARGET(
-               do_tags ALL
-               DEPENDS tags
-       )
-ENDIF ()
-
 IF (BUILD_EXAMPLES)
        ADD_SUBDIRECTORY(examples)
 ENDIF ()
@@ -310,10 +297,5 @@ IF(BUILD_FUZZERS)
        ADD_SUBDIRECTORY(fuzzers)
 ENDIF()
 
-IF(CMAKE_VERSION VERSION_GREATER 3)
-       FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
-       FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
-ELSE()
-       PRINT_ENABLED_FEATURES()
-       PRINT_DISABLED_FEATURES()
-ENDIF()
+FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
+FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")