summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/AddCFlagIfSupported.cmake30
-rw-r--r--cmake/AddClarTest.cmake7
-rw-r--r--cmake/CheckPrototypeDefinitionSafe.cmake16
-rw-r--r--cmake/DefaultCFlags.cmake154
-rw-r--r--cmake/EnableWarnings.cmake15
-rw-r--r--cmake/ExperimentalFeatures.cmake23
-rw-r--r--cmake/FindCoreFoundation.cmake26
-rw-r--r--cmake/FindGSSAPI.cmake208
-rw-r--r--cmake/FindGSSFramework.cmake28
-rw-r--r--cmake/FindHTTPParser.cmake39
-rw-r--r--cmake/FindIconv.cmake45
-rw-r--r--cmake/FindLibSSH2.cmake13
-rw-r--r--cmake/FindPCRE.cmake37
-rw-r--r--cmake/FindPCRE2.cmake37
-rw-r--r--cmake/FindPkgLibraries.cmake28
-rw-r--r--cmake/FindSecurity.cmake28
-rw-r--r--cmake/FindStatNsec.cmake20
-rw-r--r--cmake/Findfutimens.cmake14
-rw-r--r--cmake/FindmbedTLS.cmake86
-rw-r--r--cmake/IdeSplitSources.cmake22
-rw-r--r--cmake/PkgBuildConfig.cmake77
-rw-r--r--cmake/SanitizeBool.cmake20
-rw-r--r--cmake/SelectGSSAPI.cmake48
-rw-r--r--cmake/SelectHTTPParser.cmake19
-rw-r--r--cmake/SelectHTTPSBackend.cmake143
-rw-r--r--cmake/SelectHashes.cmake104
-rw-r--r--cmake/SelectRegex.cmake51
-rw-r--r--cmake/SelectSSH.cmake41
-rw-r--r--cmake/SelectXdiff.cmake9
-rw-r--r--cmake/SelectZlib.cmake34
30 files changed, 1422 insertions, 0 deletions
diff --git a/cmake/AddCFlagIfSupported.cmake b/cmake/AddCFlagIfSupported.cmake
new file mode 100644
index 0000000..685f26a
--- /dev/null
+++ b/cmake/AddCFlagIfSupported.cmake
@@ -0,0 +1,30 @@
+# - Append compiler flag to CMAKE_C_FLAGS if compiler supports it
+# ADD_C_FLAG_IF_SUPPORTED(<flag>)
+# <flag> - the compiler flag to test
+# This internally calls the CHECK_C_COMPILER_FLAG macro.
+
+include(CheckCCompilerFlag)
+
+macro(ADD_C_FLAG _FLAG)
+ string(TOUPPER ${_FLAG} UPCASE)
+ string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
+ string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
+ check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)
+
+ if(IS_${UPCASE_PRETTY}_SUPPORTED)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
+ else()
+ message(FATAL_ERROR "Required flag ${_FLAG} is not supported")
+ endif()
+endmacro()
+
+macro(ADD_C_FLAG_IF_SUPPORTED _FLAG)
+ string(TOUPPER ${_FLAG} UPCASE)
+ string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
+ string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
+ check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)
+
+ if(IS_${UPCASE_PRETTY}_SUPPORTED)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
+ endif()
+endmacro()
diff --git a/cmake/AddClarTest.cmake b/cmake/AddClarTest.cmake
new file mode 100644
index 0000000..7439416
--- /dev/null
+++ b/cmake/AddClarTest.cmake
@@ -0,0 +1,7 @@
+function(ADD_CLAR_TEST project name)
+ if(NOT USE_LEAK_CHECKER STREQUAL "OFF")
+ add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/${project}" ${ARGN})
+ else()
+ add_test(${name} "${PROJECT_BINARY_DIR}/${project}" ${ARGN})
+ endif()
+endfunction(ADD_CLAR_TEST)
diff --git a/cmake/CheckPrototypeDefinitionSafe.cmake b/cmake/CheckPrototypeDefinitionSafe.cmake
new file mode 100644
index 0000000..f82603d
--- /dev/null
+++ b/cmake/CheckPrototypeDefinitionSafe.cmake
@@ -0,0 +1,16 @@
+include(CheckPrototypeDefinition)
+
+function(check_prototype_definition_safe function prototype return header variable)
+ # temporarily save CMAKE_C_FLAGS and disable warnings about unused
+ # unused functions and parameters, otherwise they will always fail
+ # if ENABLE_WERROR is on
+ set(SAVED_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+
+ disable_warnings(unused-function)
+ disable_warnings(unused-parameter)
+
+ check_prototype_definition("${function}" "${prototype}" "${return}" "${header}" "${variable}")
+
+ # restore CMAKE_C_FLAGS
+ set(CMAKE_C_FLAGS "${SAVED_CMAKE_C_FLAGS}")
+endfunction()
diff --git a/cmake/DefaultCFlags.cmake b/cmake/DefaultCFlags.cmake
new file mode 100644
index 0000000..a9c9ab9
--- /dev/null
+++ b/cmake/DefaultCFlags.cmake
@@ -0,0 +1,154 @@
+# Platform specific compilation flags
+if(MSVC)
+ add_definitions(-D_SCL_SECURE_NO_WARNINGS)
+ add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
+ add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
+
+ string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+
+ # /GF - String pooling
+ # /MP - Parallel build
+ set(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}")
+
+ # /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")
+ else()
+ set(CRT_FLAG_DEBUG "/MDd")
+ set(CRT_FLAG_RELEASE "/MD")
+ endif()
+
+ if(WIN32_LEAKCHECK)
+ set(GIT_WIN32_LEAKCHECK 1)
+ set(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG}")
+ set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib")
+ endif()
+
+ # /Zi - Create debugging information
+ # /Od - Disable optimization
+ # /D_DEBUG - #define _DEBUG
+ # /MTd - Statically link the multithreaded debug version of the CRT
+ # /MDd - Dynamically link the multithreaded debug version of the CRT
+ # /RTC1 - Run time checks
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}")
+
+ # /DNDEBUG - Disables asserts
+ # /MT - Statically link the multithreaded release version of the CRT
+ # /MD - Dynamically link the multithreaded release version of the CRT
+ # /O2 - Optimize for speed
+ # /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off)
+ # /GL - Link time code generation (whole program optimization)
+ # /Gy - Function-level linking
+ set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
+
+ # /Oy- - Disable frame pointer omission (FPO)
+ set(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}")
+
+ # /O1 - Optimize for size
+ set(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
+
+ # /IGNORE:4221 - Ignore empty compilation units
+ set(CMAKE_STATIC_LINKER_FLAGS "/IGNORE:4221")
+
+ # /DYNAMICBASE - Address space load randomization (ASLR)
+ # /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}")
+
+ 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)
+ # /OPT:REF /OPT:ICF - Fold out duplicate code at link step
+ # /INCREMENTAL:NO - Required to use /LTCG
+ # /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug)
+ set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
+ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
+ set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup")
+ set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
+
+ # Same linker settings for DLL as EXE
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
+ set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
+ set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
+ set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
+ set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}")
+else()
+ if(ENABLE_REPRODUCIBLE_BUILDS)
+ set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
+ endif()
+
+ if(NOT BUILD_SHARED_LIBS AND LINK_WITH_STATIC_LIBRARIES)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+ endif()
+
+ set(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
+
+ enable_warnings(all)
+ enable_warnings(extra)
+
+ if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
+ set(CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
+ endif()
+
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0")
+
+ if(MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to
+ string(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
+ elseif(BUILD_SHARED_LIBS)
+ add_c_flag_IF_SUPPORTED(-fvisibility=hidden)
+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+ endif()
+
+ if(MINGW)
+ # MinGW >= 3.14 uses the C99-style stdio functions
+ # automatically, but forks like mingw-w64 still want
+ # us to define this in order to use them
+ add_definitions(-D__USE_MINGW_ANSI_STDIO=1)
+ endif()
+
+ enable_warnings(documentation)
+ disable_warnings(documentation-deprecated-sync)
+ disable_warnings(missing-field-initializers)
+ enable_warnings(missing-declarations)
+ 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)
+ enable_warnings(c11-extensions)
+ enable_warnings(c99-c11-compat)
+
+ # 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()
diff --git a/cmake/EnableWarnings.cmake b/cmake/EnableWarnings.cmake
new file mode 100644
index 0000000..0700b52
--- /dev/null
+++ b/cmake/EnableWarnings.cmake
@@ -0,0 +1,15 @@
+macro(ENABLE_WARNINGS flag)
+ add_c_flag_if_supported(-W${flag})
+endmacro()
+
+macro(DISABLE_WARNINGS flag)
+ add_c_flag_if_supported(-Wno-${flag})
+endmacro()
+
+if(ENABLE_WERROR)
+ if(MSVC)
+ add_compile_options(-WX)
+ else()
+ add_c_flag_if_supported(-Werror)
+ endif()
+endif()
diff --git a/cmake/ExperimentalFeatures.cmake b/cmake/ExperimentalFeatures.cmake
new file mode 100644
index 0000000..7eff40b
--- /dev/null
+++ b/cmake/ExperimentalFeatures.cmake
@@ -0,0 +1,23 @@
+# Experimental feature support for libgit2 - developers can opt in to
+# experimental functionality, like sha256 support. When experimental
+# functionality is enabled, we set both a cmake flag *and* a compile
+# definition. The cmake flag is used to generate `experimental.h`,
+# which will be installed by a `make install`. But the compile definition
+# is used by the libgit2 sources to detect the functionality at library
+# build time. This allows us to have an in-tree `experimental.h` with
+# *no* experiments enabled. This lets us support users who build without
+# cmake and cannot generate the `experimental.h` file.
+
+if(EXPERIMENTAL_SHA256)
+ add_feature_info("SHA256 API" ON "experimental SHA256 APIs")
+
+ set(EXPERIMENTAL 1)
+ set(GIT_EXPERIMENTAL_SHA256 1)
+ add_definitions(-DGIT_EXPERIMENTAL_SHA256=1)
+else()
+ add_feature_info("SHA256 API" OFF "experimental SHA256 APIs")
+endif()
+
+if(EXPERIMENTAL)
+ set(LIBGIT2_FILENAME "${LIBGIT2_FILENAME}-experimental")
+endif()
diff --git a/cmake/FindCoreFoundation.cmake b/cmake/FindCoreFoundation.cmake
new file mode 100644
index 0000000..b419ec9
--- /dev/null
+++ b/cmake/FindCoreFoundation.cmake
@@ -0,0 +1,26 @@
+# Find CoreFoundation.framework
+# This will define :
+#
+# COREFOUNDATION_FOUND
+# COREFOUNDATION_LIBRARIES
+# COREFOUNDATION_LDFLAGS
+#
+
+find_path(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h)
+find_library(COREFOUNDATION_LIBRARIES NAMES CoreFoundation)
+if(COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_LIBRARIES)
+ if(NOT CoreFoundation_FIND_QUIETLY)
+ message(STATUS "Found CoreFoundation ${COREFOUNDATION_LIBRARIES}")
+ endif()
+ set(COREFOUNDATION_FOUND TRUE)
+ set(COREFOUNDATION_LDFLAGS "-framework CoreFoundation")
+endif()
+
+if(CoreFoundation_FIND_REQUIRED AND NOT COREFOUNDATION_FOUND)
+ message(FATAL_ERROR "CoreFoundation not found")
+endif()
+
+mark_as_advanced(
+ COREFOUNDATION_INCLUDE_DIR
+ COREFOUNDATION_LIBRARIES
+)
diff --git a/cmake/FindGSSAPI.cmake b/cmake/FindGSSAPI.cmake
new file mode 100644
index 0000000..a11d72a
--- /dev/null
+++ b/cmake/FindGSSAPI.cmake
@@ -0,0 +1,208 @@
+# - Try to find GSSAPI
+# Once done this will define
+#
+# KRB5_CONFIG - Path to krb5-config
+# GSSAPI_ROOT_DIR - Set this variable to the root installation of GSSAPI
+#
+# Read-Only variables:
+# GSSAPI_FLAVOR_MIT - set to TRUE if MIT Kerberos has been found
+# GSSAPI_FLAVOR_HEIMDAL - set to TRUE if Heimdal Kerberos has been found
+# GSSAPI_FOUND - system has GSSAPI
+# GSSAPI_INCLUDE_DIR - the GSSAPI include directory
+# GSSAPI_LIBRARIES - Link these to use GSSAPI
+# GSSAPI_DEFINITIONS - Compiler switches required for using GSSAPI
+#
+#=============================================================================
+# Copyright (c) 2013 Andreas Schneider <asn@cryptomilk.org>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+#
+
+find_path(GSSAPI_ROOT_DIR
+ NAMES include/gssapi.h include/gssapi/gssapi.h
+ HINTS ${_GSSAPI_ROOT_HINTS}
+ PATHS ${_GSSAPI_ROOT_PATHS})
+mark_as_advanced(GSSAPI_ROOT_DIR)
+
+if(UNIX)
+ find_program(KRB5_CONFIG
+ NAMES krb5-config
+ PATHS ${GSSAPI_ROOT_DIR}/bin /opt/local/bin)
+ mark_as_advanced(KRB5_CONFIG)
+
+ if(KRB5_CONFIG)
+ # Check if we have MIT KRB5
+ execute_process(
+ COMMAND ${KRB5_CONFIG} --vendor
+ RESULT_VARIABLE _GSSAPI_VENDOR_RESULT
+ OUTPUT_VARIABLE _GSSAPI_VENDOR_STRING)
+
+ if(_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*")
+ set(GSSAPI_FLAVOR_MIT TRUE)
+ else()
+ execute_process(
+ COMMAND ${KRB5_CONFIG} --libs gssapi
+ RESULT_VARIABLE _GSSAPI_LIBS_RESULT
+ OUTPUT_VARIABLE _GSSAPI_LIBS_STRING)
+
+ if(_GSSAPI_LIBS_STRING MATCHES ".*roken.*")
+ set(GSSAPI_FLAVOR_HEIMDAL TRUE)
+ endif()
+ endif()
+
+ # Get the include dir
+ execute_process(
+ COMMAND ${KRB5_CONFIG} --cflags gssapi
+ RESULT_VARIABLE _GSSAPI_INCLUDE_RESULT
+ OUTPUT_VARIABLE _GSSAPI_INCLUDE_STRING)
+ string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}")
+ string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}")
+ endif()
+
+ if(NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL)
+ # Check for HEIMDAL
+ find_package(PkgConfig)
+ if(PKG_CONFIG_FOUND)
+ pkg_check_modules(_GSSAPI heimdal-gssapi)
+ endif()
+
+ if(_GSSAPI_FOUND)
+ set(GSSAPI_FLAVOR_HEIMDAL TRUE)
+ else()
+ find_path(_GSSAPI_ROKEN
+ NAMES roken.h
+ PATHS ${GSSAPI_ROOT_DIR}/include ${_GSSAPI_INCLUDEDIR})
+ if(_GSSAPI_ROKEN)
+ set(GSSAPI_FLAVOR_HEIMDAL TRUE)
+ endif()
+ endif()
+ endif()
+endif()
+
+find_path(GSSAPI_INCLUDE_DIR
+ NAMES gssapi.h gssapi/gssapi.h
+ PATHS ${GSSAPI_ROOT_DIR}/include ${_GSSAPI_INCLUDEDIR})
+
+if(GSSAPI_FLAVOR_MIT)
+ find_library(GSSAPI_LIBRARY
+ NAMES gssapi_krb5
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(KRB5_LIBRARY
+ NAMES krb5
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(K5CRYPTO_LIBRARY
+ NAMES k5crypto
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(COM_ERR_LIBRARY
+ NAMES com_err
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ if(GSSAPI_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${GSSAPI_LIBRARY})
+ endif()
+
+ if(KRB5_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${KRB5_LIBRARY})
+ endif()
+
+ if(K5CRYPTO_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${K5CRYPTO_LIBRARY})
+ endif()
+
+ if(COM_ERR_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${COM_ERR_LIBRARY})
+ endif()
+endif()
+
+if(GSSAPI_FLAVOR_HEIMDAL)
+ find_library(GSSAPI_LIBRARY
+ NAMES gssapi
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(KRB5_LIBRARY
+ NAMES krb5
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(HCRYPTO_LIBRARY
+ NAMES hcrypto
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(COM_ERR_LIBRARY
+ NAMES com_err
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(HEIMNTLM_LIBRARY
+ NAMES heimntlm
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(HX509_LIBRARY
+ NAMES hx509
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(ASN1_LIBRARY
+ NAMES asn1
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(WIND_LIBRARY
+ NAMES wind
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ find_library(ROKEN_LIBRARY
+ NAMES roken
+ PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR})
+
+ if(GSSAPI_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${GSSAPI_LIBRARY})
+ endif()
+
+ if(KRB5_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${KRB5_LIBRARY})
+ endif()
+
+ if(HCRYPTO_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HCRYPTO_LIBRARY})
+ endif()
+
+ if(COM_ERR_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${COM_ERR_LIBRARY})
+ endif()
+
+ if(HEIMNTLM_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HEIMNTLM_LIBRARY})
+ endif()
+
+ if(HX509_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HX509_LIBRARY})
+ endif()
+
+ if(ASN1_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${ASN1_LIBRARY})
+ endif()
+
+ if(WIND_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${WIND_LIBRARY})
+ endif()
+
+ if(ROKEN_LIBRARY)
+ set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${WIND_LIBRARY})
+ endif()
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(GSSAPI DEFAULT_MSG GSSAPI_LIBRARIES GSSAPI_INCLUDE_DIR)
+
+if(GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
+ set(GSSAPI_FOUND TRUE)
+endif(GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
+
+# show the GSSAPI_INCLUDE_DIRS and GSSAPI_LIBRARIES variables only in the advanced view
+mark_as_advanced(GSSAPI_INCLUDE_DIRS GSSAPI_LIBRARIES)
diff --git a/cmake/FindGSSFramework.cmake b/cmake/FindGSSFramework.cmake
new file mode 100644
index 0000000..1b0c936
--- /dev/null
+++ b/cmake/FindGSSFramework.cmake
@@ -0,0 +1,28 @@
+# Find GSS.framework
+# This will define :
+#
+# GSSFRAMEWORK_FOUND
+# GSSFRAMEWORK_INCLUDE_DIR
+# GSSFRAMEWORK_LIBRARIES
+# GSSFRAMEWORK_LDFLAGS
+#
+
+find_path(GSSFRAMEWORK_INCLUDE_DIR NAMES GSS.h)
+find_library(GSSFRAMEWORK_LIBRARIES NAMES GSS)
+if(GSSFRAMEWORK_INCLUDE_DIR AND GSSFRAMEWORK_LIBRARIES)
+ if(NOT CoreFoundation_FIND_QUIETLY)
+ message(STATUS "Found GSS.framework ${GSSFRAMEWORK_LIBRARIES}")
+ endif()
+ set(GSSFRAMEWORK_FOUND TRUE)
+ set(GSSFRAMEWORK_LDFLAGS "-framework GSS")
+endif()
+
+if(GSS_FIND_REQUIRED AND NOT GSSFRAMEWORK_FOUND)
+ message(FATAL_ERROR "CoreFoundation not found")
+endif()
+
+mark_as_advanced(
+ GSSFRAMEWORK_INCLUDE_DIR
+ GSSFRAMEWORK_LIBRARIES
+ GSSFRAMEWORK_LDFLAGS
+)
diff --git a/cmake/FindHTTPParser.cmake b/cmake/FindHTTPParser.cmake
new file mode 100644
index 0000000..3350190
--- /dev/null
+++ b/cmake/FindHTTPParser.cmake
@@ -0,0 +1,39 @@
+# - Try to find http-parser
+#
+# Defines the following variables:
+#
+# HTTP_PARSER_FOUND - system has http-parser
+# HTTP_PARSER_INCLUDE_DIR - the http-parser include directory
+# HTTP_PARSER_LIBRARIES - Link these to use http-parser
+# HTTP_PARSER_VERSION_MAJOR - major version
+# HTTP_PARSER_VERSION_MINOR - minor version
+# HTTP_PARSER_VERSION_STRING - the version of http-parser found
+
+# Find the header and library
+find_path(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h)
+find_library(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser)
+
+# Found the header, read version
+if(HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h")
+ file(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H)
+ if(HTTP_PARSER_H)
+ string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}")
+ string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}")
+ set(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}")
+ endif()
+ unset(HTTP_PARSER_H)
+endif()
+
+# Handle the QUIETLY and REQUIRED arguments and set HTTP_PARSER_FOUND
+# to TRUE if all listed variables are TRUE
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
+
+# Hide advanced variables
+mark_as_advanced(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
+
+# Set standard variables
+if(HTTP_PARSER_FOUND)
+ set(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY})
+ set(HTTP_PARSER_INCLUDE_DIRS ${HTTP_PARSER_INCLUDE_DIR})
+endif()
diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake
new file mode 100644
index 0000000..9e6ded9
--- /dev/null
+++ b/cmake/FindIconv.cmake
@@ -0,0 +1,45 @@
+# - Try to find Iconv
+# Once done this will define
+#
+# ICONV_FOUND - system has Iconv
+# ICONV_INCLUDE_DIR - the Iconv include directory
+# ICONV_LIBRARIES - Link these to use Iconv
+#
+
+if(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
+ # Already in cache, be silent
+ set(ICONV_FIND_QUIETLY TRUE)
+endif()
+
+find_path(ICONV_INCLUDE_DIR iconv.h)
+check_function_exists(iconv_open libc_has_iconv)
+find_library(iconv_lib NAMES iconv libiconv libiconv-2 c)
+
+if(ICONV_INCLUDE_DIR AND libc_has_iconv)
+ set(ICONV_FOUND TRUE)
+ set(ICONV_LIBRARIES "")
+ if(NOT ICONV_FIND_QUIETLY)
+ message(STATUS "Found Iconv: provided by libc")
+ endif(NOT ICONV_FIND_QUIETLY)
+elseif(ICONV_INCLUDE_DIR AND iconv_lib)
+ set(ICONV_FOUND TRUE)
+ # split iconv into -L and -l linker options, so we can
+ # set them for pkg-config
+ get_filename_component(iconv_path ${iconv_lib} PATH)
+ get_filename_component(iconv_name ${iconv_lib} NAME_WE)
+ string(REGEX REPLACE "^lib" "" iconv_name ${iconv_name})
+ set(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}")
+
+ if(NOT ICONV_FIND_QUIETLY)
+ message(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
+ endif()
+else()
+ if(Iconv_FIND_REQUIRED)
+ message(FATAL_ERROR "Could not find Iconv")
+ endif(Iconv_FIND_REQUIRED)
+endif()
+
+mark_as_advanced(
+ ICONV_INCLUDE_DIR
+ ICONV_LIBRARIES
+)
diff --git a/cmake/FindLibSSH2.cmake b/cmake/FindLibSSH2.cmake
new file mode 100644
index 0000000..c571997
--- /dev/null
+++ b/cmake/FindLibSSH2.cmake
@@ -0,0 +1,13 @@
+# LIBSSH2_FOUND - system has the libssh2 library
+# LIBSSH2_INCLUDE_DIR - the libssh2 include directory
+# LIBSSH2_LIBRARY - the libssh2 library name
+
+find_path(LIBSSH2_INCLUDE_DIR libssh2.h)
+
+find_library(LIBSSH2_LIBRARY NAMES ssh2 libssh2)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LibSSH2
+ REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR)
+
+mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY)
diff --git a/cmake/FindPCRE.cmake b/cmake/FindPCRE.cmake
new file mode 100644
index 0000000..02e7edc
--- /dev/null
+++ b/cmake/FindPCRE.cmake
@@ -0,0 +1,37 @@
+# Copyright (C) 2007-2009 LuaDist.
+# Created by Peter Kapec <kapecp@gmail.com>
+# Redistribution and use of this file is allowed according to the terms of the MIT license.
+# For details see the COPYRIGHT file distributed with LuaDist.
+# Note:
+# Searching headers and libraries is very simple and is NOT as powerful as scripts
+# distributed with CMake, because LuaDist defines directories to search for.
+# Everyone is encouraged to contact the author with improvements. Maybe this file
+# becomes part of CMake distribution sometimes.
+
+# - Find pcre
+# Find the native PCRE headers and libraries.
+#
+# PCRE_INCLUDE_DIRS - where to find pcre.h, etc.
+# PCRE_LIBRARIES - List of libraries when using pcre.
+# PCRE_FOUND - True if pcre found.
+
+# Look for the header file.
+find_path(PCRE_INCLUDE_DIR NAMES pcre.h)
+
+# Look for the library.
+find_library(PCRE_LIBRARY NAMES pcre)
+
+# Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE.
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR)
+
+# Copy the results to the output variables.
+if(PCRE_FOUND)
+ set(PCRE_LIBRARIES ${PCRE_LIBRARY})
+ set(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
+else(PCRE_FOUND)
+ set(PCRE_LIBRARIES)
+ set(PCRE_INCLUDE_DIRS)
+endif()
+
+mark_as_advanced(PCRE_INCLUDE_DIRS PCRE_LIBRARIES)
diff --git a/cmake/FindPCRE2.cmake b/cmake/FindPCRE2.cmake
new file mode 100644
index 0000000..41c165b
--- /dev/null
+++ b/cmake/FindPCRE2.cmake
@@ -0,0 +1,37 @@
+# Copyright (C) 2007-2009 LuaDist.
+# Created by Peter Kapec <kapecp@gmail.com>
+# Redistribution and use of this file is allowed according to the terms of the MIT license.
+# For details see the COPYRIGHT file distributed with LuaDist.
+# Note:
+# Searching headers and libraries is very simple and is NOT as powerful as scripts
+# distributed with CMake, because LuaDist defines directories to search for.
+# Everyone is encouraged to contact the author with improvements. Maybe this file
+# becomes part of CMake distribution sometimes.
+
+# - Find pcre
+# Find the native PCRE2 headers and libraries.
+#
+# PCRE2_INCLUDE_DIRS - where to find pcre.h, etc.
+# PCRE2_LIBRARIES - List of libraries when using pcre.
+# PCRE2_FOUND - True if pcre found.
+
+# Look for the header file.
+find_path(PCRE2_INCLUDE_DIR NAMES pcre2.h)
+
+# Look for the library.
+find_library(PCRE2_LIBRARY NAMES pcre2-8)
+
+# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR)
+
+# Copy the results to the output variables.
+if(PCRE2_FOUND)
+ set(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
+ set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
+else(PCRE2_FOUND)
+ set(PCRE2_LIBRARIES)
+ set(PCRE2_INCLUDE_DIRS)
+endif()
+
+mark_as_advanced(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)
diff --git a/cmake/FindPkgLibraries.cmake b/cmake/FindPkgLibraries.cmake
new file mode 100644
index 0000000..220bb2c
--- /dev/null
+++ b/cmake/FindPkgLibraries.cmake
@@ -0,0 +1,28 @@
+include(FindPkgConfig)
+
+# This function will find and set up a pkg-config based module.
+# If a pc-file was found, it will resolve library paths to
+# absolute paths. Furthermore, the function will automatically
+# fall back to use static libraries in case no dynamic libraries
+# were found.
+function(FIND_PKGLIBRARIES prefix package)
+ pkg_check_modules(${prefix} ${package})
+ if(NOT ${prefix}_FOUND)
+ return()
+ endif()
+
+ foreach(LIBRARY ${${prefix}_LIBRARIES})
+ find_library(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS})
+ if(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND")
+ message(FATAL_ERROR "could not resolve ${LIBRARY}")
+ endif()
+ list(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED})
+ endforeach()
+
+ set(${prefix}_FOUND 1 PARENT_SCOPE)
+ set(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE)
+ set(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE)
+ set(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE)
+
+ message(STATUS " Resolved libraries: ${RESOLVED_LIBRARIES}")
+endfunction()
diff --git a/cmake/FindSecurity.cmake b/cmake/FindSecurity.cmake
new file mode 100644
index 0000000..14a2e2d
--- /dev/null
+++ b/cmake/FindSecurity.cmake
@@ -0,0 +1,28 @@
+# Find Security.framework
+# This will define :
+#
+# SECURITY_FOUND
+# SECURITY_LIBRARIES
+# SECURITY_LDFLAGS
+# SECURITY_HAS_SSLCREATECONTEXT
+#
+
+find_path(SECURITY_INCLUDE_DIR NAMES Security/Security.h)
+find_library(SECURITY_LIBRARIES NAMES Security)
+if(SECURITY_INCLUDE_DIR AND SECURITY_LIBRARIES)
+ if(NOT Security_FIND_QUIETLY)
+ message(STATUS "Found Security ${SECURITY_LIBRARIES}")
+ endif()
+ set(SECURITY_FOUND TRUE)
+ set(SECURITY_LDFLAGS "-framework Security")
+ check_library_exists("${SECURITY_LIBRARIES}" SSLCreateContext "Security/SecureTransport.h" SECURITY_HAS_SSLCREATECONTEXT)
+endif()
+
+if(Security_FIND_REQUIRED AND NOT SECURITY_FOUND)
+ message(FATAL_ERROR "Security not found")
+endif()
+
+mark_as_advanced(
+ SECURITY_INCLUDE_DIR
+ SECURITY_LIBRARIES
+)
diff --git a/cmake/FindStatNsec.cmake b/cmake/FindStatNsec.cmake
new file mode 100644
index 0000000..9dfdf51
--- /dev/null
+++ b/cmake/FindStatNsec.cmake
@@ -0,0 +1,20 @@
+include(FeatureSummary)
+
+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"
+ HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C)
+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
+ 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
+ HAVE_STRUCT_STAT_NSEC LANGUAGE C)
+else()
+ set(HAVE_STRUCT_STAT_NSEC ON )
+endif()
+
+add_feature_info(nanoseconds USE_NSEC "support nanosecond precision file mtimes and ctimes")
diff --git a/cmake/Findfutimens.cmake b/cmake/Findfutimens.cmake
new file mode 100644
index 0000000..3449c9d
--- /dev/null
+++ b/cmake/Findfutimens.cmake
@@ -0,0 +1,14 @@
+include(EnableWarnings)
+
+if(APPLE)
+ # We cannot simply CHECK_FUNCTION_EXISTS on macOS because
+ # MACOSX_DEPLOYMENT_TARGET may be set to a version in the past
+ # that doesn't have futimens. Instead we need to enable warnings
+ # as errors, then check for the symbol existing in `sys/stat.h`,
+ # then reset warnings as errors.
+ enable_warnings(error)
+ check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
+ disable_warnings(error)
+else()
+ check_function_exists(futimens HAVE_FUTIMENS)
+endif()
diff --git a/cmake/FindmbedTLS.cmake b/cmake/FindmbedTLS.cmake
new file mode 100644
index 0000000..a4a5487
--- /dev/null
+++ b/cmake/FindmbedTLS.cmake
@@ -0,0 +1,86 @@
+# - Try to find mbedTLS
+# Once done this will define
+#
+# Read-Only variables
+# MBEDTLS_FOUND - system has mbedTLS
+# MBEDTLS_INCLUDE_DIR - the mbedTLS include directory
+# MBEDTLS_LIBRARY_DIR - the mbedTLS library directory
+# MBEDTLS_LIBRARIES - Link these to use mbedTLS
+# MBEDTLS_LIBRARY - path to mbedTLS library
+# MBEDX509_LIBRARY - path to mbedTLS X.509 library
+# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library
+#
+# Hint
+# MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation.
+
+set(_MBEDTLS_ROOT_HINTS
+ ${MBEDTLS_ROOT_DIR}
+ ENV MBEDTLS_ROOT_DIR)
+
+set(_MBEDTLS_ROOT_HINTS_AND_PATHS
+ HINTS ${_MBEDTLS_ROOT_HINTS}
+ PATHS ${_MBEDTLS_ROOT_PATHS})
+
+find_path(MBEDTLS_INCLUDE_DIR
+ NAMES mbedtls/version.h
+ ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES include)
+
+if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
+ # Already in cache, be silent
+ set(MBEDTLS_FIND_QUIETLY TRUE)
+endif()
+
+find_library(MBEDTLS_LIBRARY
+ NAMES mbedtls libmbedtls
+ ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES library)
+find_library(MBEDX509_LIBRARY
+ NAMES mbedx509 libmbedx509
+ ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES library)
+find_library(MBEDCRYPTO_LIBRARY
+ NAMES mbedcrypto libmbedcrypto
+ ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
+ PATH_SUFFIXES library)
+
+if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
+ set(MBEDTLS_FOUND TRUE)
+endif()
+
+if(MBEDTLS_FOUND)
+ # split mbedTLS into -L and -l linker options, so we can set them for pkg-config
+ get_filename_component(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
+ get_filename_component(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
+ get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
+ get_filename_component(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
+ string(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
+ string(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
+ string(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
+ set(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
+
+ if(NOT MBEDTLS_FIND_QUIETLY)
+ message(STATUS "Found mbedTLS:")
+ file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
+ string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
+ if(MBEDTLSMATCH)
+ string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
+ message(STATUS " version ${MBEDTLS_VERSION}")
+ endif()
+ message(STATUS " TLS: ${MBEDTLS_LIBRARY}")
+ message(STATUS " X509: ${MBEDX509_LIBRARY}")
+ message(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
+ endif()
+else(MBEDTLS_FOUND)
+ if(MBEDTLS_FIND_REQUIRED)
+ message(FATAL_ERROR "Could not find mbedTLS")
+ endif()
+endif()
+
+mark_as_advanced(
+ MBEDTLS_INCLUDE_DIR
+ MBEDTLS_LIBRARY_DIR
+ MBEDTLS_LIBRARIES
+ MBEDTLS_LIBRARY
+ MBEDX509_LIBRARY
+ MBEDCRYPTO_LIBRARY)
diff --git a/cmake/IdeSplitSources.cmake b/cmake/IdeSplitSources.cmake
new file mode 100644
index 0000000..4f928ac
--- /dev/null
+++ b/cmake/IdeSplitSources.cmake
@@ -0,0 +1,22 @@
+# This function splits the sources files up into their appropriate
+# subdirectories. This is especially useful for IDEs like Xcode and
+# Visual Studio, so that you can navigate into the libgit2_tests project,
+# and see the folders within the tests folder (instead of just seeing all
+# source and tests in a single folder.)
+function(IDE_SPLIT_SOURCES target)
+ if(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode)
+ get_target_property(sources ${target} SOURCES)
+ foreach(source ${sources})
+ if(source MATCHES ".*/")
+ string(REPLACE ${PROJECT_SOURCE_DIR}/ "" rel ${source})
+ if(rel)
+ string(REGEX REPLACE "/([^/]*)$" "" rel ${rel})
+ if(rel)
+ string(REPLACE "/" "\\\\" rel ${rel})
+ source_group(${rel} FILES ${source})
+ endif()
+ endif()
+ endif()
+ endforeach()
+ endif()
+endfunction()
diff --git a/cmake/PkgBuildConfig.cmake b/cmake/PkgBuildConfig.cmake
new file mode 100644
index 0000000..c8939e6
--- /dev/null
+++ b/cmake/PkgBuildConfig.cmake
@@ -0,0 +1,77 @@
+# pkg-config file generation
+#
+
+function(pkg_build_config)
+ set(options)
+ set(oneValueArgs NAME DESCRIPTION VERSION FILENAME LIBS_SELF)
+ set(multiValueArgs LIBS PRIVATE_LIBS REQUIRES CFLAGS)
+
+ cmake_parse_arguments(PKGCONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if (NOT DEFINED PKGCONFIG_FILENAME AND DEFINED PKGCONFIG_NAME)
+ set(PKGCONFIG_FILENAME ${PKGCONFIG_NAME})
+ endif()
+ if (NOT DEFINED PKGCONFIG_FILENAME)
+ message(FATAL_ERROR "Missing FILENAME argument")
+ endif()
+ set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${PKGCONFIG_FILENAME}.pc")
+
+ if (NOT DEFINED PKGCONFIG_DESCRIPTION)
+ message(FATAL_ERROR "Missing DESCRIPTION argument")
+ endif()
+
+ if (NOT DEFINED PKGCONFIG_VERSION)
+ message(FATAL_ERROR "Missing VERSION argument")
+ endif()
+
+ # Write .pc "header"
+ file(WRITE "${PKGCONFIG_FILE}"
+ "prefix=\"${CMAKE_INSTALL_PREFIX}\"\n"
+ "libdir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n"
+ "includedir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"\n"
+ "\n"
+ "Name: ${PKGCONFIG_NAME}\n"
+ "Description: ${PKGCONFIG_DESCRIPTION}\n"
+ "Version: ${PKGCONFIG_VERSION}\n"
+ )
+
+ # Prepare Libs
+ if(NOT DEFINED PKGCONFIG_LIBS_SELF)
+ set(PKGCONFIG_LIBS_SELF "${PKGCONFIG_FILE}")
+ endif()
+
+ if(NOT DEFINED PKGCONFIG_LIBS)
+ set(PKGCONFIG_LIBS "-l${PKGCONFIG_LIBS_SELF}")
+ else()
+ list(INSERT PKGCONFIG_LIBS 0 "-l${PKGCONFIG_LIBS_SELF}")
+ endif()
+
+ list(REMOVE_DUPLICATES PKGCONFIG_LIBS)
+ string(REPLACE ";" " " PKGCONFIG_LIBS "${PKGCONFIG_LIBS}")
+ file(APPEND "${PKGCONFIG_FILE}" "Libs: -L\${libdir} ${PKGCONFIG_LIBS}\n")
+
+ # Prepare Libs.private
+ if(DEFINED PKGCONFIG_PRIVATE_LIBS)
+ list(REMOVE_DUPLICATES PKGCONFIG_PRIVATE_LIBS)
+ string(REPLACE ";" " " PKGCONFIG_PRIVATE_LIBS "${PKGCONFIG_PRIVATE_LIBS}")
+ file(APPEND "${PKGCONFIG_FILE}" "Libs.private: ${PKGCONFIG_PRIVATE_LIBS}\n")
+ endif()
+
+ # Prepare Requires.private
+ if(DEFINED PKGCONFIG_REQUIRES)
+ list(REMOVE_DUPLICATES PKGCONFIG_REQUIRES)
+ string(REPLACE ";" " " PKGCONFIG_REQUIRES "${PKGCONFIG_REQUIRES}")
+ file(APPEND "${PKGCONFIG_FILE}" "Requires.private: ${PKGCONFIG_REQUIRES}\n")
+ endif()
+
+ # Prepare Cflags
+ if(DEFINED PKGCONFIG_CFLAGS)
+ string(REPLACE ";" " " PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS}")
+ else()
+ set(PKGCONFIG_CFLAGS "")
+ endif()
+ file(APPEND "${PKGCONFIG_FILE}" "Cflags: -I\${includedir} ${PKGCONFIG_CFLAGS}\n")
+
+ # Install .pc file
+ install(FILES "${PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+endfunction()
diff --git a/cmake/SanitizeBool.cmake b/cmake/SanitizeBool.cmake
new file mode 100644
index 0000000..586c17d
--- /dev/null
+++ b/cmake/SanitizeBool.cmake
@@ -0,0 +1,20 @@
+function(SanitizeBool VAR)
+ string(TOLOWER "${${VAR}}" VALUE)
+ if(VALUE STREQUAL "on")
+ set(${VAR} "ON" PARENT_SCOPE)
+ elseif(VALUE STREQUAL "yes")
+ set(${VAR} "ON" PARENT_SCOPE)
+ elseif(VALUE STREQUAL "true")
+ set(${VAR} "ON" PARENT_SCOPE)
+ elseif(VALUE STREQUAL "1")
+ set(${VAR} "ON" PARENT_SCOPE)
+ elseif(VALUE STREQUAL "off")
+ set(${VAR} "OFF" PARENT_SCOPE)
+ elseif(VALUE STREQUAL "no")
+ set(${VAR} "OFF" PARENT_SCOPE)
+ elseif(VALUE STREQUAL "false")
+ set(${VAR} "OFF" PARENT_SCOPE)
+ elseif(VALUE STREQUAL "0")
+ set(${VAR} "OFF" PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/cmake/SelectGSSAPI.cmake b/cmake/SelectGSSAPI.cmake
new file mode 100644
index 0000000..5bde116
--- /dev/null
+++ b/cmake/SelectGSSAPI.cmake
@@ -0,0 +1,48 @@
+include(SanitizeBool)
+
+# We try to find any packages our backends might use
+find_package(GSSAPI)
+if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ include(FindGSSFramework)
+endif()
+
+if(USE_GSSAPI)
+ # Auto-select GSS backend
+ sanitizebool(USE_GSSAPI)
+ if(USE_GSSAPI STREQUAL ON)
+ if(GSSFRAMEWORK_FOUND)
+ set(USE_GSSAPI "GSS.framework")
+ elseif(GSSAPI_FOUND)
+ set(USE_GSSAPI "gssapi")
+ else()
+ message(FATAL_ERROR "Unable to autodetect a usable GSS backend."
+ "Please pass the backend name explicitly (-DUSE_GSS=backend)")
+ endif()
+ endif()
+
+ # Check that we can find what's required for the selected backend
+ if(USE_GSSAPI STREQUAL "GSS.framework")
+ if(NOT GSSFRAMEWORK_FOUND)
+ message(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found")
+ endif()
+
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSFRAMEWORK_LIBRARIES})
+
+ set(GIT_GSSFRAMEWORK 1)
+ add_feature_info(GSSAPI GIT_GSSFRAMEWORK "GSSAPI support for SPNEGO authentication (${USE_GSSAPI})")
+ elseif(USE_GSSAPI STREQUAL "gssapi")
+ if(NOT GSSAPI_FOUND)
+ message(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found")
+ endif()
+
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSAPI_LIBRARIES})
+
+ set(GIT_GSSAPI 1)
+ add_feature_info(GSSAPI GIT_GSSAPI "GSSAPI support for SPNEGO authentication (${USE_GSSAPI})")
+ else()
+ message(FATAL_ERROR "Asked for backend ${USE_GSSAPI} but it wasn't found")
+ endif()
+else()
+ set(GIT_GSSAPI 0)
+ add_feature_info(GSSAPI NO "GSSAPI support for SPNEGO authentication")
+endif()
diff --git a/cmake/SelectHTTPParser.cmake b/cmake/SelectHTTPParser.cmake
new file mode 100644
index 0000000..955aea3
--- /dev/null
+++ b/cmake/SelectHTTPParser.cmake
@@ -0,0 +1,19 @@
+# Optional external dependency: http-parser
+if(USE_HTTP_PARSER STREQUAL "system")
+ find_package(HTTPParser)
+
+ if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${HTTP_PARSER_LIBRARIES})
+ list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
+ add_feature_info(http-parser ON "http-parser support (system)")
+ else()
+ message(FATAL_ERROR "http-parser support was requested but not found")
+ endif()
+else()
+ message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
+ add_subdirectory("${PROJECT_SOURCE_DIR}/deps/http-parser" "${PROJECT_BINARY_DIR}/deps/http-parser")
+ list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/http-parser")
+ list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:http-parser>")
+ add_feature_info(http-parser ON "http-parser support (bundled)")
+endif()
diff --git a/cmake/SelectHTTPSBackend.cmake b/cmake/SelectHTTPSBackend.cmake
new file mode 100644
index 0000000..d149416
--- /dev/null
+++ b/cmake/SelectHTTPSBackend.cmake
@@ -0,0 +1,143 @@
+include(SanitizeBool)
+
+# We try to find any packages our backends might use
+find_package(OpenSSL)
+find_package(mbedTLS)
+if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ find_package(Security)
+ find_package(CoreFoundation)
+endif()
+
+if(USE_HTTPS)
+ # Auto-select TLS backend
+ sanitizebool(USE_HTTPS)
+ if(USE_HTTPS STREQUAL ON)
+ if(SECURITY_FOUND)
+ if(SECURITY_HAS_SSLCREATECONTEXT)
+ set(USE_HTTPS "SecureTransport")
+ else()
+ message(STATUS "Security framework is too old, falling back to OpenSSL")
+ set(USE_HTTPS "OpenSSL")
+ endif()
+ elseif(WIN32)
+ set(USE_HTTPS "WinHTTP")
+ elseif(OPENSSL_FOUND)
+ set(USE_HTTPS "OpenSSL")
+ elseif(MBEDTLS_FOUND)
+ set(USE_HTTPS "mbedTLS")
+ else()
+ message(FATAL_ERROR "Unable to autodetect a usable HTTPS backend."
+ "Please pass the backend name explicitly (-DUSE_HTTPS=backend)")
+ endif()
+ endif()
+
+ # Check that we can find what's required for the selected backend
+ if(USE_HTTPS STREQUAL "SecureTransport")
+ if(NOT COREFOUNDATION_FOUND)
+ message(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found")
+ endif()
+ if(NOT SECURITY_FOUND)
+ message(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found")
+ endif()
+ if(NOT SECURITY_HAS_SSLCREATECONTEXT)
+ message(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported")
+ endif()
+
+ set(GIT_SECURE_TRANSPORT 1)
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR})
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
+ list(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
+ elseif(USE_HTTPS STREQUAL "OpenSSL")
+ if(NOT OPENSSL_FOUND)
+ message(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found")
+ endif()
+
+ set(GIT_OPENSSL 1)
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR})
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${OPENSSL_LIBRARIES})
+ list(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS})
+ list(APPEND LIBGIT2_PC_REQUIRES "openssl")
+ elseif(USE_HTTPS STREQUAL "mbedTLS")
+ if(NOT MBEDTLS_FOUND)
+ message(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found")
+ endif()
+
+ if(NOT CERT_LOCATION)
+ message(STATUS "Auto-detecting default certificates location")
+ if(EXISTS "/usr/local/opt/openssl/bin/openssl")
+ # Check for an Homebrew installation
+ set(OPENSSL_CMD "/usr/local/opt/openssl/bin/openssl")
+ else()
+ set(OPENSSL_CMD "openssl")
+ endif()
+ execute_process(COMMAND ${OPENSSL_CMD} version -d OUTPUT_VARIABLE OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if(OPENSSL_DIR)
+ string(REGEX REPLACE "^OPENSSLDIR: \"(.*)\"$" "\\1/" OPENSSL_DIR ${OPENSSL_DIR})
+
+ set(OPENSSL_CA_LOCATIONS
+ "ca-bundle.pem" # OpenSUSE Leap 42.1
+ "cert.pem" # Ubuntu 14.04, FreeBSD
+ "certs/ca-certificates.crt" # Ubuntu 16.04
+ "certs/ca.pem" # Debian 7
+ )
+ foreach(SUFFIX IN LISTS OPENSSL_CA_LOCATIONS)
+ set(LOC "${OPENSSL_DIR}${SUFFIX}")
+ if(NOT CERT_LOCATION AND EXISTS "${OPENSSL_DIR}${SUFFIX}")
+ set(CERT_LOCATION ${LOC})
+ endif()
+ endforeach()
+ else()
+ message(FATAL_ERROR "Unable to find OpenSSL executable. Please provide default certificate location via CERT_LOCATION")
+ endif()
+ endif()
+
+ if(CERT_LOCATION)
+ if(NOT EXISTS ${CERT_LOCATION})
+ message(FATAL_ERROR "Cannot use CERT_LOCATION=${CERT_LOCATION} as it doesn't exist")
+ endif()
+ add_feature_info(CERT_LOCATION ON "using certificates from ${CERT_LOCATION}")
+ add_definitions(-DGIT_DEFAULT_CERT_LOCATION="${CERT_LOCATION}")
+ endif()
+
+ set(GIT_MBEDTLS 1)
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES})
+ # mbedTLS has no pkgconfig file, hence we can't require it
+ # https://github.com/ARMmbed/mbedtls/issues/228
+ # For now, pass its link flags as our own
+ list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
+ elseif(USE_HTTPS STREQUAL "Schannel")
+ set(GIT_SCHANNEL 1)
+
+ list(APPEND LIBGIT2_SYSTEM_LIBS "rpcrt4" "crypt32" "ole32" "secur32")
+ list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32" "-lsecur32")
+ elseif(USE_HTTPS STREQUAL "WinHTTP")
+ set(GIT_WINHTTP 1)
+
+ # Since MinGW does not come with headers or an import library for winhttp,
+ # we have to include a private header and generate our own import library
+ if(MINGW)
+ add_subdirectory("${PROJECT_SOURCE_DIR}/deps/winhttp" "${PROJECT_BINARY_DIR}/deps/winhttp")
+ list(APPEND LIBGIT2_SYSTEM_LIBS winhttp)
+ list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/winhttp")
+ else()
+ list(APPEND LIBGIT2_SYSTEM_LIBS "winhttp")
+ list(APPEND LIBGIT2_PC_LIBS "-lwinhttp")
+ endif()
+
+ list(APPEND LIBGIT2_SYSTEM_LIBS "rpcrt4" "crypt32" "ole32" "secur32")
+ list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32" "-lsecur32")
+ elseif(USE_HTTPS STREQUAL "OpenSSL-Dynamic")
+ set(GIT_OPENSSL 1)
+ set(GIT_OPENSSL_DYNAMIC 1)
+ list(APPEND LIBGIT2_SYSTEM_LIBS dl)
+ else()
+ message(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found")
+ endif()
+
+ set(GIT_HTTPS 1)
+ add_feature_info(HTTPS GIT_HTTPS "using ${USE_HTTPS}")
+else()
+ set(GIT_HTTPS 0)
+ add_feature_info(HTTPS NO "")
+endif()
diff --git a/cmake/SelectHashes.cmake b/cmake/SelectHashes.cmake
new file mode 100644
index 0000000..5c007e5
--- /dev/null
+++ b/cmake/SelectHashes.cmake
@@ -0,0 +1,104 @@
+# Select a hash backend
+
+include(SanitizeBool)
+
+# USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF
+sanitizebool(USE_SHA1)
+sanitizebool(USE_SHA256)
+
+# sha1
+
+if(USE_SHA1 STREQUAL ON)
+ SET(USE_SHA1 "CollisionDetection")
+elseif(USE_SHA1 STREQUAL "HTTPS")
+ if(USE_HTTPS STREQUAL "SecureTransport")
+ set(USE_SHA1 "CommonCrypto")
+ elseif(USE_HTTPS STREQUAL "Schannel")
+ set(USE_SHA1 "Win32")
+ elseif(USE_HTTPS STREQUAL "WinHTTP")
+ set(USE_SHA1 "Win32")
+ elseif(USE_HTTPS)
+ set(USE_SHA1 ${USE_HTTPS})
+ else()
+ set(USE_SHA1 "CollisionDetection")
+ endif()
+endif()
+
+if(USE_SHA1 STREQUAL "CollisionDetection")
+ set(GIT_SHA1_COLLISIONDETECT 1)
+elseif(USE_SHA1 STREQUAL "OpenSSL")
+ set(GIT_SHA1_OPENSSL 1)
+elseif(USE_SHA1 STREQUAL "OpenSSL-Dynamic")
+ set(GIT_SHA1_OPENSSL 1)
+ set(GIT_SHA1_OPENSSL_DYNAMIC 1)
+ list(APPEND LIBGIT2_SYSTEM_LIBS dl)
+elseif(USE_SHA1 STREQUAL "CommonCrypto")
+ set(GIT_SHA1_COMMON_CRYPTO 1)
+elseif(USE_SHA1 STREQUAL "mbedTLS")
+ set(GIT_SHA1_MBEDTLS 1)
+elseif(USE_SHA1 STREQUAL "Win32")
+ set(GIT_SHA1_WIN32 1)
+else()
+ message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
+endif()
+
+# sha256
+
+if(USE_SHA256 STREQUAL ON AND USE_HTTPS)
+ SET(USE_SHA256 "HTTPS")
+elseif(USE_SHA256 STREQUAL ON)
+ SET(USE_SHA256 "Builtin")
+endif()
+
+if(USE_SHA256 STREQUAL "HTTPS")
+ if(USE_HTTPS STREQUAL "SecureTransport")
+ set(USE_SHA256 "CommonCrypto")
+ elseif(USE_HTTPS STREQUAL "Schannel")
+ set(USE_SHA256 "Win32")
+ elseif(USE_HTTPS STREQUAL "WinHTTP")
+ set(USE_SHA256 "Win32")
+ elseif(USE_HTTPS)
+ set(USE_SHA256 ${USE_HTTPS})
+ endif()
+endif()
+
+if(USE_SHA256 STREQUAL "Builtin")
+ set(GIT_SHA256_BUILTIN 1)
+elseif(USE_SHA256 STREQUAL "OpenSSL")
+ set(GIT_SHA256_OPENSSL 1)
+elseif(USE_SHA256 STREQUAL "OpenSSL-Dynamic")
+ set(GIT_SHA256_OPENSSL 1)
+ set(GIT_SHA256_OPENSSL_DYNAMIC 1)
+ list(APPEND LIBGIT2_SYSTEM_LIBS dl)
+elseif(USE_SHA256 STREQUAL "CommonCrypto")
+ set(GIT_SHA256_COMMON_CRYPTO 1)
+elseif(USE_SHA256 STREQUAL "mbedTLS")
+ set(GIT_SHA256_MBEDTLS 1)
+elseif(USE_SHA256 STREQUAL "Win32")
+ set(GIT_SHA256_WIN32 1)
+else()
+ message(FATAL_ERROR "Asked for unknown SHA256 backend: ${USE_SHA256}")
+endif()
+
+# add library requirements
+if(USE_SHA1 STREQUAL "OpenSSL" OR USE_SHA256 STREQUAL "OpenSSL")
+ if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ list(APPEND LIBGIT2_PC_LIBS "-lssl")
+ else()
+ list(APPEND LIBGIT2_PC_REQUIRES "openssl")
+ endif()
+endif()
+
+if(USE_SHA1 STREQUAL "mbedTLS" OR USE_SHA256 STREQUAL "mbedTLS")
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES})
+ # mbedTLS has no pkgconfig file, hence we can't require it
+ # https://github.com/ARMmbed/mbedtls/issues/228
+ # For now, pass its link flags as our own
+ list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
+endif()
+
+# notify feature enablement
+
+add_feature_info(SHA1 ON "using ${USE_SHA1}")
+add_feature_info(SHA256 ON "using ${USE_SHA256}")
diff --git a/cmake/SelectRegex.cmake b/cmake/SelectRegex.cmake
new file mode 100644
index 0000000..2a3a91b
--- /dev/null
+++ b/cmake/SelectRegex.cmake
@@ -0,0 +1,51 @@
+# Specify regular expression implementation
+find_package(PCRE)
+
+if(REGEX_BACKEND STREQUAL "")
+ check_symbol_exists(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
+
+ if(HAVE_REGCOMP_L)
+ set(REGEX_BACKEND "regcomp_l")
+ elseif(PCRE_FOUND)
+ set(REGEX_BACKEND "pcre")
+ else()
+ set(REGEX_BACKEND "builtin")
+ endif()
+endif()
+
+if(REGEX_BACKEND STREQUAL "regcomp_l")
+ add_feature_info(regex ON "using system regcomp_l")
+ set(GIT_REGEX_REGCOMP_L 1)
+elseif(REGEX_BACKEND STREQUAL "pcre2")
+ find_package(PCRE2)
+
+ if(NOT PCRE2_FOUND)
+ MESSAGE(FATAL_ERROR "PCRE2 support was requested but not found")
+ endif()
+
+ add_feature_info(regex ON "using system PCRE2")
+ set(GIT_REGEX_PCRE2 1)
+
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS})
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE2_LIBRARIES})
+ list(APPEND LIBGIT2_PC_REQUIRES "libpcre2-8")
+elseif(REGEX_BACKEND STREQUAL "pcre")
+ add_feature_info(regex ON "using system PCRE")
+ set(GIT_REGEX_PCRE 1)
+
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS})
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE_LIBRARIES})
+ list(APPEND LIBGIT2_PC_REQUIRES "libpcre")
+elseif(REGEX_BACKEND STREQUAL "regcomp")
+ add_feature_info(regex ON "using system regcomp")
+ set(GIT_REGEX_REGCOMP 1)
+elseif(REGEX_BACKEND STREQUAL "builtin")
+ add_feature_info(regex ON "using bundled PCRE")
+ set(GIT_REGEX_BUILTIN 1)
+
+ add_subdirectory("${PROJECT_SOURCE_DIR}/deps/pcre" "${PROJECT_BINARY_DIR}/deps/pcre")
+ list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/pcre")
+ list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:pcre>)
+else()
+ message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported")
+endif()
diff --git a/cmake/SelectSSH.cmake b/cmake/SelectSSH.cmake
new file mode 100644
index 0000000..23dfc97
--- /dev/null
+++ b/cmake/SelectSSH.cmake
@@ -0,0 +1,41 @@
+# Optional external dependency: libssh2
+if(USE_SSH)
+ find_pkglibraries(LIBSSH2 libssh2)
+ if(NOT LIBSSH2_FOUND)
+ find_package(LibSSH2)
+ set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
+ get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
+ set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
+ set(LIBSSH2_LDFLAGS "-lssh2")
+ endif()
+
+ if(NOT LIBSSH2_FOUND)
+ message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
+ endif()
+endif()
+
+if(LIBSSH2_FOUND)
+ set(GIT_SSH 1)
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${LIBSSH2_LIBRARIES})
+ list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
+
+ check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
+ if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
+ set(GIT_SSH_MEMORY_CREDENTIALS 1)
+ endif()
+else()
+ message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
+endif()
+
+if(WIN32 AND EMBED_SSH_PATH)
+ file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
+ list(SORT SSH_SRC)
+ list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC})
+
+ list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include")
+ file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
+ set(GIT_SSH 1)
+endif()
+
+add_feature_info(SSH GIT_SSH "SSH transport support")
diff --git a/cmake/SelectXdiff.cmake b/cmake/SelectXdiff.cmake
new file mode 100644
index 0000000..9ab9f3f
--- /dev/null
+++ b/cmake/SelectXdiff.cmake
@@ -0,0 +1,9 @@
+# Optional external dependency: xdiff
+if(USE_XDIFF STREQUAL "system")
+ message(FATAL_ERROR "external/system xdiff is not yet supported")
+else()
+ add_subdirectory("${PROJECT_SOURCE_DIR}/deps/xdiff" "${PROJECT_BINARY_DIR}/deps/xdiff")
+ list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/xdiff")
+ list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:xdiff>")
+ add_feature_info(xdiff ON "xdiff support (bundled)")
+endif()
diff --git a/cmake/SelectZlib.cmake b/cmake/SelectZlib.cmake
new file mode 100644
index 0000000..fb4361a
--- /dev/null
+++ b/cmake/SelectZlib.cmake
@@ -0,0 +1,34 @@
+# Optional external dependency: zlib
+include(SanitizeBool)
+
+SanitizeBool(USE_BUNDLED_ZLIB)
+if(USE_BUNDLED_ZLIB STREQUAL ON)
+ set(USE_BUNDLED_ZLIB "Bundled")
+endif()
+
+if(USE_BUNDLED_ZLIB STREQUAL "OFF")
+ find_package(ZLIB)
+ if(ZLIB_FOUND)
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${ZLIB_LIBRARIES})
+ if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ list(APPEND LIBGIT2_PC_LIBS "-lz")
+ else()
+ list(APPEND LIBGIT2_PC_REQUIRES "zlib")
+ endif()
+ add_feature_info(zlib ON "using system zlib")
+ else()
+ message(STATUS "zlib was not found; using bundled 3rd-party sources." )
+ endif()
+endif()
+if(USE_BUNDLED_ZLIB STREQUAL "Chromium")
+ add_subdirectory("${PROJECT_SOURCE_DIR}/deps/chromium-zlib" "${PROJECT_BINARY_DIR}/deps/chromium-zlib")
+ list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/chromium-zlib")
+ list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:chromium_zlib>)
+ add_feature_info(zlib ON "using (Chromium) bundled zlib")
+elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
+ add_subdirectory("${PROJECT_SOURCE_DIR}/deps/zlib" "${PROJECT_BINARY_DIR}/deps/zlib")
+ list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/zlib")
+ list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:zlib>)
+ add_feature_info(zlib ON "using bundled zlib")
+endif()