Blame CMakeLists.txt

Packit ae9e2a
# CMake build script for the libgit2 project
Packit ae9e2a
#
Packit ae9e2a
# Building (out of source build):
Packit ae9e2a
# > mkdir build && cd build
Packit ae9e2a
# > cmake .. [-DSETTINGS=VALUE]
Packit ae9e2a
# > cmake --build .
Packit ae9e2a
#
Packit ae9e2a
# Testing:
Packit ae9e2a
# > ctest -V
Packit ae9e2a
#
Packit ae9e2a
# Install:
Packit ae9e2a
# > cmake --build . --target install
Packit ae9e2a
Packit ae9e2a
PROJECT(libgit2 C)
Packit ae9e2a
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
Packit ae9e2a
CMAKE_POLICY(SET CMP0015 NEW)
Packit ae9e2a
Packit ae9e2a
# Add find modules to the path
Packit ae9e2a
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
Packit ae9e2a
Packit ae9e2a
INCLUDE(CheckLibraryExists)
Packit ae9e2a
INCLUDE(CheckFunctionExists)
Packit ae9e2a
INCLUDE(CheckSymbolExists)
Packit ae9e2a
INCLUDE(CheckStructHasMember)
Packit ae9e2a
INCLUDE(AddCFlagIfSupported)
Packit ae9e2a
INCLUDE(FindPkgConfig)
Packit ae9e2a
Packit ae9e2a
# Build options
Packit ae9e2a
#
Packit ae9e2a
OPTION( SONAME				"Set the (SO)VERSION of the target"		ON  )
Packit ae9e2a
OPTION( BUILD_SHARED_LIBS	"Build Shared Library (OFF for Static)"	ON  )
Packit ae9e2a
OPTION( THREADSAFE			"Build libgit2 as threadsafe"			ON )
Packit ae9e2a
OPTION( BUILD_CLAR			"Build Tests using the Clar suite"		ON  )
Packit ae9e2a
OPTION( BUILD_EXAMPLES		"Build library usage example apps"		OFF )
Packit ae9e2a
OPTION( TAGS				"Generate tags"							OFF )
Packit ae9e2a
OPTION( PROFILE				"Generate profiling information"		OFF )
Packit ae9e2a
OPTION( ENABLE_TRACE		"Enables tracing support"				OFF )
Packit ae9e2a
OPTION( LIBGIT2_FILENAME	"Name of the produced binary"			OFF )
Packit ae9e2a
Packit ae9e2a
OPTION( USE_SHA1DC			"Use SHA-1 with collision detection"	OFF )
Packit ae9e2a
OPTION( USE_ICONV			"Link with and use iconv library" 		OFF )
Packit ae9e2a
OPTION( USE_SSH				"Link with libssh to enable SSH support" ON )
Packit ae9e2a
OPTION( USE_GSSAPI			"Link with libgssapi for SPNEGO auth"   OFF )
Packit ae9e2a
OPTION( VALGRIND			"Configure build for valgrind"			OFF )
Packit ae9e2a
OPTION( CURL			"Use curl for HTTP if available" ON)
Packit ae9e2a
OPTION( DEBUG_POOL			"Enable debug pool allocator"			OFF )
Packit ae9e2a
Packit ae9e2a
IF(DEBUG_POOL)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_DEBUG_POOL)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Packit ae9e2a
	SET( USE_ICONV ON )
Packit ae9e2a
	FIND_PACKAGE(Security)
Packit ae9e2a
	FIND_PACKAGE(CoreFoundation REQUIRED)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF(MSVC)
Packit ae9e2a
	# This option is only available when building with MSVC. By default, libgit2
Packit ae9e2a
	# is build using the cdecl calling convention, which is useful if you're
Packit ae9e2a
	# writing C. However, the CLR and Win32 API both expect stdcall.
Packit ae9e2a
	#
Packit ae9e2a
	# If you are writing a CLR program and want to link to libgit2, you'll want
Packit ae9e2a
	# to turn this on by invoking CMake with the "-DSTDCALL=ON" argument.
Packit ae9e2a
	OPTION( STDCALL			"Build libgit2 with the __stdcall convention"	OFF  )
Packit ae9e2a
Packit ae9e2a
	# This option must match the settings used in your program, in particular if you
Packit ae9e2a
	# are linking statically
Packit ae9e2a
	OPTION( STATIC_CRT		"Link the static CRT libraries"	ON  )
Packit ae9e2a
Packit ae9e2a
	# If you want to embed a copy of libssh2 into libgit2, pass a
Packit ae9e2a
	# path to libssh2
Packit ae9e2a
	OPTION( EMBED_SSH_PATH		"Path to libssh2 to embed (Windows)" OFF )
Packit ae9e2a
Packit ae9e2a
	ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)
Packit ae9e2a
	ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
Packit ae9e2a
	ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
Packit ae9e2a
IF(WIN32)
Packit ae9e2a
	# By default, libgit2 is built with WinHTTP.  To use the built-in
Packit ae9e2a
	# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
Packit ae9e2a
	OPTION(	WINHTTP			"Use Win32 WinHTTP routines"	ON	)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF(MSVC)
Packit ae9e2a
	# Enable MSVC CRTDBG memory leak reporting when in debug mode.
Packit ae9e2a
	OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Packit ae9e2a
	OPTION( USE_OPENSSL                     "Link with and use openssl library"             ON )
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
Packit ae9e2a
	HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
Packit ae9e2a
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
Packit ae9e2a
	HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C)
Packit ae9e2a
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h
Packit ae9e2a
	HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C)
Packit ae9e2a
Packit ae9e2a
IF (HAVE_STRUCT_STAT_ST_MTIM)
Packit ae9e2a
	CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
Packit ae9e2a
		HAVE_STRUCT_STAT_NSEC LANGUAGE C)
Packit ae9e2a
ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC)
Packit ae9e2a
	CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h
Packit ae9e2a
		HAVE_STRUCT_STAT_NSEC LANGUAGE C)
Packit ae9e2a
ELSE ()
Packit ae9e2a
	SET( HAVE_STRUCT_STAT_NSEC ON )
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF (HAVE_STRUCT_STAT_NSEC OR WIN32)
Packit ae9e2a
	OPTION( USE_NSEC		"Care about sub-second file mtimes and ctimes"	ON  )
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# This variable will contain the libraries we need to put into
Packit ae9e2a
# libgit2.pc's Requires.private. That is, what we're linking to or
Packit ae9e2a
# what someone who's statically linking us needs to link to.
Packit ae9e2a
SET(LIBGIT2_PC_REQUIRES "")
Packit ae9e2a
# This will be set later if we use the system's http-parser library or
Packit ae9e2a
# use iconv (OSX) and will be written to the Libs.private field in the
Packit ae9e2a
# pc file.
Packit ae9e2a
SET(LIBGIT2_PC_LIBS "")
Packit ae9e2a
Packit ae9e2a
# Installation paths
Packit ae9e2a
#
Packit ae9e2a
SET(BIN_INSTALL_DIR bin CACHE PATH "Where to install binaries to.")
Packit ae9e2a
SET(LIB_INSTALL_DIR lib CACHE PATH "Where to install libraries to.")
Packit ae9e2a
SET(INCLUDE_INSTALL_DIR include CACHE PATH "Where to install headers to.")
Packit ae9e2a
Packit ae9e2a
# Set a couple variables to be substituted inside the .pc file.
Packit ae9e2a
# We can't just use LIB_INSTALL_DIR in the .pc file, as passing them as absolue
Packit ae9e2a
# or relative paths is both valid and supported by cmake.
Packit ae9e2a
SET (PKGCONFIG_PREFIX ${CMAKE_INSTALL_PREFIX})
Packit ae9e2a
Packit ae9e2a
IF(IS_ABSOLUTE ${LIB_INSTALL_DIR})
Packit ae9e2a
  SET (PKGCONFIG_LIBDIR ${LIB_INSTALL_DIR})
Packit ae9e2a
ELSE(IS_ABSOLUTE ${LIB_INSTALL_DIR})
Packit ae9e2a
  SET (PKGCONFIG_LIBDIR "\${prefix}/${LIB_INSTALL_DIR}")
Packit ae9e2a
ENDIF (IS_ABSOLUTE ${LIB_INSTALL_DIR})
Packit ae9e2a
Packit ae9e2a
IF(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR})
Packit ae9e2a
  SET (PKGCONFIG_INCLUDEDIR ${INCLUDE_INSTALL_DIR})
Packit ae9e2a
ELSE(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR})
Packit ae9e2a
  SET (PKGCONFIG_INCLUDEDIR "\${prefix}/${INCLUDE_INSTALL_DIR}")
Packit ae9e2a
ENDIF(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR})
Packit ae9e2a
Packit ae9e2a
FUNCTION(TARGET_OS_LIBRARIES target)
Packit ae9e2a
	IF(WIN32)
Packit ae9e2a
		TARGET_LINK_LIBRARIES(${target} ws2_32)
Packit ae9e2a
	ELSEIF(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
Packit ae9e2a
		TARGET_LINK_LIBRARIES(${target} socket nsl)
Packit ae9e2a
		LIST(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
Packit ae9e2a
		SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
Packit ae9e2a
	ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Haiku")
Packit ae9e2a
		TARGET_LINK_LIBRARIES(${target} network)
Packit ae9e2a
		LIST(APPEND LIBGIT2_PC_LIBS "-lnetwork")
Packit ae9e2a
		SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
Packit ae9e2a
	ENDIF()
Packit ae9e2a
	CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_LIBRT)
Packit ae9e2a
	IF(NEED_LIBRT)
Packit ae9e2a
		TARGET_LINK_LIBRARIES(${target} rt)
Packit ae9e2a
		LIST(APPEND LIBGIT2_PC_LIBS "-lrt")
Packit ae9e2a
		SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
Packit ae9e2a
	ENDIF()
Packit ae9e2a
Packit ae9e2a
	IF(THREADSAFE)
Packit ae9e2a
		TARGET_LINK_LIBRARIES(${target} ${CMAKE_THREAD_LIBS_INIT})
Packit ae9e2a
		LIST(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
Packit ae9e2a
		SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
Packit ae9e2a
	ENDIF()
Packit ae9e2a
ENDFUNCTION()
Packit ae9e2a
Packit ae9e2a
# This function splits the sources files up into their appropriate
Packit ae9e2a
# subdirectories.  This is especially useful for IDEs like Xcode and
Packit ae9e2a
# Visual Studio, so that you can navigate into the libgit2_clar project,
Packit ae9e2a
# and see the folders within the tests folder (instead of just seeing all
Packit ae9e2a
# source and tests in a single folder.)
Packit ae9e2a
FUNCTION(IDE_SPLIT_SOURCES target)
Packit ae9e2a
	IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode)
Packit ae9e2a
		GET_TARGET_PROPERTY(sources ${target} SOURCES)
Packit ae9e2a
		FOREACH(source ${sources})
Packit ae9e2a
			IF(source MATCHES ".*/")
Packit ae9e2a
				STRING(REPLACE ${CMAKE_CURRENT_SOURCE_DIR}/ "" rel ${source})
Packit ae9e2a
				IF(rel)
Packit ae9e2a
					STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel})
Packit ae9e2a
					IF(rel)
Packit ae9e2a
						STRING(REPLACE "/" "\\\\" rel ${rel})
Packit ae9e2a
						SOURCE_GROUP(${rel} FILES ${source})
Packit ae9e2a
					ENDIF()
Packit ae9e2a
				ENDIF()
Packit ae9e2a
			ENDIF()
Packit ae9e2a
		ENDFOREACH()
Packit ae9e2a
	ENDIF()
Packit ae9e2a
ENDFUNCTION()
Packit ae9e2a
Packit ae9e2a
FILE(STRINGS "include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$")
Packit ae9e2a
Packit ae9e2a
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}")
Packit ae9e2a
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR  "${GIT2_HEADER}")
Packit ae9e2a
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}")
Packit ae9e2a
SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}")
Packit ae9e2a
Packit ae9e2a
FILE(STRINGS "include/git2/version.h" GIT2_HEADER_SOVERSION REGEX "^#define LIBGIT2_SOVERSION [0-9]+$")
Packit ae9e2a
STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION ([0-9]+)$" "\\1" LIBGIT2_SOVERSION "${GIT2_HEADER_SOVERSION}")
Packit ae9e2a
Packit ae9e2a
# Find required dependencies
Packit ae9e2a
INCLUDE_DIRECTORIES(src include)
Packit ae9e2a
Packit ae9e2a
IF (SECURITY_FOUND)
Packit ae9e2a
  # OS X 10.7 and older do not have some functions we use, fall back to OpenSSL there
Packit ae9e2a
  CHECK_LIBRARY_EXISTS("${SECURITY_DIRS}" SSLCreateContext "Security/SecureTransport.h" HAVE_NEWER_SECURITY)
Packit ae9e2a
  IF (HAVE_NEWER_SECURITY)
Packit ae9e2a
    MESSAGE("-- Found Security ${SECURITY_DIRS}")
Packit ae9e2a
    LIST(APPEND LIBGIT2_PC_LIBS "-framework Security")
Packit ae9e2a
  ELSE()
Packit ae9e2a
    MESSAGE("-- Security framework is too old, falling back to OpenSSL")
Packit ae9e2a
    SET(SECURITY_FOUND "NO")
Packit ae9e2a
    SET(SECURITY_DIRS "")
Packit ae9e2a
    SET(SECURITY_DIR "")
Packit ae9e2a
    SET(USE_OPENSSL "ON")
Packit ae9e2a
  ENDIF()
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF (COREFOUNDATION_FOUND)
Packit ae9e2a
  MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_DIRS}")
Packit ae9e2a
  LIST(APPEND LIBGIT2_PC_LIBS "-framework CoreFoundation")
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
Packit ae9e2a
IF (WIN32 AND EMBED_SSH_PATH)
Packit ae9e2a
	FILE(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
Packit ae9e2a
	INCLUDE_DIRECTORIES("${EMBED_SSH_PATH}/include")
Packit ae9e2a
	FILE(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_SSH)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF (WIN32 AND WINHTTP)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_WINHTTP)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_HTTPS)
Packit ae9e2a
Packit ae9e2a
	# Since MinGW does not come with headers or an import library for winhttp,
Packit ae9e2a
	# we have to include a private header and generate our own import library
Packit ae9e2a
	IF (MINGW)
Packit ae9e2a
		FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH)
Packit ae9e2a
		IF (NOT DLLTOOL)
Packit ae9e2a
			MESSAGE(FATAL_ERROR "Could not find dlltool command")
Packit ae9e2a
		ENDIF ()
Packit ae9e2a
Packit ae9e2a
		SET(LIBWINHTTP_PATH "${CMAKE_CURRENT_BINARY_DIR}/deps/winhttp")
Packit ae9e2a
		FILE(MAKE_DIRECTORY ${LIBWINHTTP_PATH})
Packit ae9e2a
Packit ae9e2a
		IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
Packit ae9e2a
			set(WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR}/deps/winhttp/winhttp64.def")
Packit ae9e2a
		ELSE()
Packit ae9e2a
			set(WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR}/deps/winhttp/winhttp.def")
Packit ae9e2a
		ENDIF()
Packit ae9e2a
Packit ae9e2a
		ADD_CUSTOM_COMMAND(
Packit ae9e2a
			OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a
Packit ae9e2a
			COMMAND ${DLLTOOL} -d ${WINHTTP_DEF} -k -D winhttp.dll -l libwinhttp.a
Packit ae9e2a
			DEPENDS ${WINHTTP_DEF}
Packit ae9e2a
			WORKING_DIRECTORY ${LIBWINHTTP_PATH}
Packit ae9e2a
		)
Packit ae9e2a
Packit ae9e2a
		SET_SOURCE_FILES_PROPERTIES(
Packit ae9e2a
			${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c
Packit ae9e2a
			PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a
Packit ae9e2a
		)
Packit ae9e2a
Packit ae9e2a
		INCLUDE_DIRECTORIES(deps/winhttp)
Packit ae9e2a
		LINK_DIRECTORIES(${LIBWINHTTP_PATH})
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
Packit ae9e2a
	LINK_LIBRARIES(winhttp rpcrt4 crypt32 ole32)
Packit ae9e2a
	LIST(APPEND LIBGIT2_PC_LIBS "-lwinhttp" "-lrpcrt4" "-lcrypt32" "-lole32")
Packit ae9e2a
ELSE ()
Packit ae9e2a
	IF (CURL)
Packit ae9e2a
		PKG_CHECK_MODULES(CURL libcurl)
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
Packit ae9e2a
	IF (NOT AMIGA AND USE_OPENSSL)
Packit ae9e2a
		FIND_PACKAGE(OpenSSL)
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
Packit ae9e2a
	IF (CURL_FOUND)
Packit ae9e2a
		ADD_DEFINITIONS(-DGIT_CURL)
Packit ae9e2a
		INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
Packit ae9e2a
		LINK_DIRECTORIES(${CURL_LIBRARY_DIRS})
Packit ae9e2a
		LINK_LIBRARIES(${CURL_LIBRARIES})
Packit ae9e2a
		LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
Packit ae9e2a
	ENDIF()
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Specify sha1 implementation
Packit ae9e2a
IF (USE_SHA1DC)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_SHA1_COLLISIONDETECT)
Packit ae9e2a
	ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1)
Packit ae9e2a
	ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
Packit ae9e2a
	ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
Packit ae9e2a
	FILE(GLOB SRC_SHA1 src/hash/hash_collisiondetect.c src/hash/sha1dc/*)
Packit ae9e2a
ELSEIF (WIN32 AND NOT MINGW)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_SHA1_WIN32)
Packit ae9e2a
	FILE(GLOB SRC_SHA1 src/hash/hash_win32.c)
Packit ae9e2a
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_SHA1_COMMON_CRYPTO)
Packit ae9e2a
ELSEIF (OPENSSL_FOUND)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_SHA1_OPENSSL)
Packit ae9e2a
	IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
Packit ae9e2a
		LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
Packit ae9e2a
	ELSE()
Packit ae9e2a
		SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl")
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
ELSE()
Packit ae9e2a
	FILE(GLOB SRC_SHA1 src/hash/hash_generic.c)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Enable tracing
Packit ae9e2a
IF (ENABLE_TRACE STREQUAL "ON")
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_TRACE)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Include POSIX regex when it is required
Packit ae9e2a
IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
Packit ae9e2a
	INCLUDE_DIRECTORIES(deps/regex)
Packit ae9e2a
	SET(SRC_REGEX deps/regex/regex.c)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Optional external dependency: http-parser
Packit ae9e2a
FIND_PACKAGE(HTTP_Parser)
Packit ae9e2a
IF (HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
Packit ae9e2a
	INCLUDE_DIRECTORIES(${HTTP_PARSER_INCLUDE_DIRS})
Packit ae9e2a
	LINK_LIBRARIES(${HTTP_PARSER_LIBRARIES})
Packit ae9e2a
	LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
Packit ae9e2a
ELSE()
Packit ae9e2a
	MESSAGE(STATUS "http-parser version 2 was not found; using bundled 3rd-party sources.")
Packit ae9e2a
	INCLUDE_DIRECTORIES(deps/http-parser)
Packit ae9e2a
	FILE(GLOB SRC_HTTP deps/http-parser/*.c deps/http-parser/*.h)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Optional external dependency: zlib
Packit ae9e2a
FIND_PACKAGE(ZLIB)
Packit ae9e2a
IF (ZLIB_FOUND)
Packit ae9e2a
	INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
Packit ae9e2a
	LINK_LIBRARIES(${ZLIB_LIBRARIES})
Packit ae9e2a
	IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
Packit ae9e2a
		LIST(APPEND LIBGIT2_PC_LIBS "-lz")
Packit ae9e2a
	ELSE()
Packit ae9e2a
		SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
Packit ae9e2a
	ENDIF()
Packit ae9e2a
ELSE()
Packit ae9e2a
	MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." )
Packit ae9e2a
	INCLUDE_DIRECTORIES(deps/zlib)
Packit ae9e2a
	ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
Packit ae9e2a
	FILE(GLOB SRC_ZLIB deps/zlib/*.c deps/zlib/*.h)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Optional external dependency: libssh2
Packit ae9e2a
IF (USE_SSH)
Packit ae9e2a
	PKG_CHECK_MODULES(LIBSSH2 libssh2)
Packit ae9e2a
ENDIF()
Packit ae9e2a
IF (LIBSSH2_FOUND)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_SSH)
Packit ae9e2a
	INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIRS})
Packit ae9e2a
	LINK_DIRECTORIES(${LIBSSH2_LIBRARY_DIRS})
Packit ae9e2a
	LIST(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
Packit ae9e2a
	#SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${LIBSSH2_LDFLAGS}")
Packit ae9e2a
	SET(SSH_LIBRARIES ${LIBSSH2_LIBRARIES})
Packit ae9e2a
Packit ae9e2a
	CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
Packit ae9e2a
	IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS)
Packit ae9e2a
		ADD_DEFINITIONS(-DGIT_SSH_MEMORY_CREDENTIALS)
Packit ae9e2a
	ENDIF()
Packit ae9e2a
ELSE()
Packit ae9e2a
	MESSAGE(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Optional external dependency: libgssapi
Packit ae9e2a
IF (USE_GSSAPI)
Packit ae9e2a
	FIND_PACKAGE(GSSAPI)
Packit ae9e2a
ENDIF()
Packit ae9e2a
IF (GSSAPI_FOUND)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_GSSAPI)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Optional external dependency: iconv
Packit ae9e2a
IF (USE_ICONV)
Packit ae9e2a
	FIND_PACKAGE(Iconv)
Packit ae9e2a
ENDIF()
Packit ae9e2a
IF (ICONV_FOUND)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_USE_ICONV)
Packit ae9e2a
	INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
Packit ae9e2a
	LIST(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Platform specific compilation flags
Packit ae9e2a
IF (MSVC)
Packit ae9e2a
Packit ae9e2a
	STRING(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
Packit ae9e2a
Packit ae9e2a
	# /GF - String pooling
Packit ae9e2a
	# /MP - Parallel build
Packit ae9e2a
	SET(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}")
Packit ae9e2a
Packit ae9e2a
	IF (STDCALL)
Packit ae9e2a
		# /Gz - stdcall calling convention
Packit ae9e2a
		SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gz")
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
Packit ae9e2a
	IF (STATIC_CRT)
Packit ae9e2a
		SET(CRT_FLAG_DEBUG "/MTd")
Packit ae9e2a
		SET(CRT_FLAG_RELEASE "/MT")
Packit ae9e2a
	ELSE()
Packit ae9e2a
		SET(CRT_FLAG_DEBUG "/MDd")
Packit ae9e2a
		SET(CRT_FLAG_RELEASE "/MD")
Packit ae9e2a
	ENDIF()
Packit ae9e2a
Packit ae9e2a
	IF (MSVC_CRTDBG)
Packit ae9e2a
		SET(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG} /DGIT_MSVC_CRTDBG")
Packit ae9e2a
		SET(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib")
Packit ae9e2a
	ENDIF()
Packit ae9e2a
Packit ae9e2a
	# /Zi - Create debugging information
Packit ae9e2a
	# /Od - Disable optimization
Packit ae9e2a
	# /D_DEBUG - #define _DEBUG
Packit ae9e2a
	# /MTd - Statically link the multithreaded debug version of the CRT
Packit ae9e2a
	# /MDd - Dynamically link the multithreaded debug version of the CRT
Packit ae9e2a
	# /RTC1 - Run time checks
Packit ae9e2a
	SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}")
Packit ae9e2a
Packit ae9e2a
	# /DNDEBUG - Disables asserts
Packit ae9e2a
	# /MT - Statically link the multithreaded release version of the CRT
Packit ae9e2a
	# /MD - Dynamically link the multithreaded release version of the CRT
Packit ae9e2a
	# /O2 - Optimize for speed
Packit ae9e2a
	# /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off)
Packit ae9e2a
	# /GL - Link time code generation (whole program optimization)
Packit ae9e2a
	# /Gy - Function-level linking
Packit ae9e2a
	SET(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
Packit ae9e2a
Packit ae9e2a
	# /Oy- - Disable frame pointer omission (FPO)
Packit ae9e2a
	SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}")
Packit ae9e2a
Packit ae9e2a
	# /O1 - Optimize for size
Packit ae9e2a
	SET(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
Packit ae9e2a
Packit ae9e2a
	# /DYNAMICBASE - Address space load randomization (ASLR)
Packit ae9e2a
	# /NXCOMPAT - Data execution prevention (DEP)
Packit ae9e2a
	# /LARGEADDRESSAWARE - >2GB user address space on x86
Packit ae9e2a
	# /VERSION - Embed version information in PE header
Packit ae9e2a
	SET(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}")
Packit ae9e2a
Packit ae9e2a
	# /DEBUG - Create a PDB
Packit ae9e2a
	# /LTCG - Link time code generation (whole program optimization)
Packit ae9e2a
	# /OPT:REF /OPT:ICF - Fold out duplicate code at link step
Packit ae9e2a
	# /INCREMENTAL:NO - Required to use /LTCG
Packit ae9e2a
	# /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug)
Packit ae9e2a
	SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
Packit ae9e2a
	SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
Packit ae9e2a
	SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup")
Packit ae9e2a
	SET(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
Packit ae9e2a
Packit ae9e2a
	# Same linker settings for DLL as EXE
Packit ae9e2a
	SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
Packit ae9e2a
	SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
Packit ae9e2a
	SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
Packit ae9e2a
	SET(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
Packit ae9e2a
	SET(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}")
Packit ae9e2a
Packit ae9e2a
	SET(WIN_RC "src/win32/git2.rc")
Packit ae9e2a
ELSE ()
Packit ae9e2a
	SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
Packit ae9e2a
Packit ae9e2a
	ADD_C_FLAG_IF_SUPPORTED(-Wall)
Packit ae9e2a
	ADD_C_FLAG_IF_SUPPORTED(-Wextra)
Packit ae9e2a
Packit ae9e2a
	IF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
Packit ae9e2a
		SET(CMAKE_C_FLAGS "-std=c99 -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
Packit ae9e2a
	ENDIF()
Packit ae9e2a
Packit Service ea8d5e
	SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
Packit ae9e2a
Packit ae9e2a
	IF (MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to
Packit ae9e2a
		STRING(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
Packit ae9e2a
	ELSEIF (BUILD_SHARED_LIBS)
Packit ae9e2a
		ADD_C_FLAG_IF_SUPPORTED(-fvisibility=hidden)
Packit ae9e2a
Packit ae9e2a
		SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
Packit ae9e2a
	IF (MINGW)
Packit ae9e2a
		# MinGW >= 3.14 uses the C99-style stdio functions
Packit ae9e2a
		# automatically, but forks like mingw-w64 still want
Packit ae9e2a
		# us to define this in order to use them
Packit ae9e2a
		ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1)
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
Packit ae9e2a
	ADD_C_FLAG_IF_SUPPORTED(-Wdocumentation)
Packit ae9e2a
	ADD_C_FLAG_IF_SUPPORTED(-Wno-missing-field-initializers)
Packit Service b87dbd
	ADD_C_FLAG_IF_SUPPORTED(-Wstrict-aliasing=2)
Packit ae9e2a
	ADD_C_FLAG_IF_SUPPORTED(-Wstrict-prototypes)
Packit ae9e2a
	ADD_C_FLAG_IF_SUPPORTED(-Wdeclaration-after-statement)
Packit ae9e2a
	ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-const-variable)
Packit ae9e2a
	ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-function)
Packit ae9e2a
Packit ae9e2a
	IF (APPLE) # Apple deprecated OpenSSL
Packit ae9e2a
		ADD_C_FLAG_IF_SUPPORTED(-Wno-deprecated-declarations)
Packit ae9e2a
	ENDIF()
Packit ae9e2a
Packit ae9e2a
	IF (PROFILE)
Packit ae9e2a
		SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")
Packit ae9e2a
		SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}")
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
CHECK_SYMBOL_EXISTS(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
Packit ae9e2a
IF (HAVE_REGCOMP_L)
Packit ae9e2a
	ADD_DEFINITIONS(-DHAVE_REGCOMP_L)
Packit ae9e2a
ENDIF ()
Packit ae9e2a
Packit ae9e2a
CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS)
Packit ae9e2a
IF (HAVE_FUTIMENS)
Packit ae9e2a
	ADD_DEFINITIONS(-DHAVE_FUTIMENS)
Packit ae9e2a
ENDIF ()
Packit ae9e2a
Packit ae9e2a
CHECK_FUNCTION_EXISTS(qsort_r HAVE_QSORT_R)
Packit ae9e2a
IF (HAVE_QSORT_R)
Packit ae9e2a
	ADD_DEFINITIONS(-DHAVE_QSORT_R)
Packit ae9e2a
ENDIF ()
Packit ae9e2a
Packit ae9e2a
CHECK_FUNCTION_EXISTS(qsort_s HAVE_QSORT_S)
Packit ae9e2a
IF (HAVE_QSORT_S)
Packit ae9e2a
	ADD_DEFINITIONS(-DHAVE_QSORT_S)
Packit ae9e2a
ENDIF ()
Packit ae9e2a
Packit ae9e2a
IF( NOT CMAKE_CONFIGURATION_TYPES )
Packit ae9e2a
	# Build Debug by default
Packit ae9e2a
	IF (NOT CMAKE_BUILD_TYPE)
Packit ae9e2a
		SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
ELSE()
Packit ae9e2a
	# Using a multi-configuration generator eg MSVC or Xcode
Packit ae9e2a
	# that uses CMAKE_CONFIGURATION_TYPES and not CMAKE_BUILD_TYPE
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF (SECURITY_FOUND)
Packit ae9e2a
  ADD_DEFINITIONS(-DGIT_SECURE_TRANSPORT)
Packit ae9e2a
  ADD_DEFINITIONS(-DGIT_HTTPS)
Packit ae9e2a
  INCLUDE_DIRECTORIES(${SECURITY_INCLUDE_DIR})
Packit ae9e2a
ENDIF ()
Packit ae9e2a
Packit ae9e2a
IF (OPENSSL_FOUND)
Packit ae9e2a
  ADD_DEFINITIONS(-DGIT_OPENSSL)
Packit ae9e2a
  ADD_DEFINITIONS(-DGIT_HTTPS)
Packit ae9e2a
  INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
Packit ae9e2a
  SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
Packit ae9e2a
Packit ae9e2a
IF (THREADSAFE)
Packit ae9e2a
	IF (NOT WIN32)
Packit ae9e2a
		FIND_PACKAGE(Threads REQUIRED)
Packit ae9e2a
	ENDIF()
Packit ae9e2a
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_THREADS)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF (USE_NSEC)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_USE_NSEC)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IF (HAVE_STRUCT_STAT_ST_MTIM)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_USE_STAT_MTIM)
Packit ae9e2a
ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_USE_STAT_MTIMESPEC)
Packit ae9e2a
ELSEIF (HAVE_STRUCT_STAT_ST_MTIME_NSEC)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_USE_STAT_MTIME_NSEC)
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
Packit ae9e2a
Packit ae9e2a
# Collect sourcefiles
Packit ae9e2a
FILE(GLOB SRC_H include/git2.h include/git2/*.h include/git2/sys/*.h)
Packit ae9e2a
Packit ae9e2a
# On Windows use specific platform sources
Packit ae9e2a
IF (WIN32 AND NOT CYGWIN)
Packit ae9e2a
	ADD_DEFINITIONS(-DWIN32 -D_WIN32_WINNT=0x0501)
Packit ae9e2a
	FILE(GLOB SRC_OS src/win32/*.c src/win32/*.h)
Packit ae9e2a
ELSEIF (AMIGA)
Packit ae9e2a
	ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP)
Packit ae9e2a
ELSE()
Packit ae9e2a
	IF (VALGRIND)
Packit ae9e2a
		ADD_DEFINITIONS(-DNO_MMAP)
Packit ae9e2a
	ENDIF()
Packit ae9e2a
	FILE(GLOB SRC_OS src/unix/*.c src/unix/*.h)
Packit ae9e2a
ENDIF()
Packit ae9e2a
FILE(GLOB SRC_GIT2 src/*.c src/*.h src/transports/*.c src/transports/*.h src/xdiff/*.c src/xdiff/*.h)
Packit ae9e2a
Packit ae9e2a
# Determine architecture of the machine
Packit ae9e2a
IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_ARCH_64)
Packit ae9e2a
ELSEIF (CMAKE_SIZEOF_VOID_P EQUAL 4)
Packit ae9e2a
	ADD_DEFINITIONS(-DGIT_ARCH_32)
Packit ae9e2a
ELSEIF (CMAKE_SIZEOF_VOID_P)
Packit ae9e2a
	MESSAGE(FATAL_ERROR "Unsupported architecture (pointer size is ${CMAKE_SIZEOF_VOID_P} bytes)")
Packit ae9e2a
ELSE()
Packit ae9e2a
	MESSAGE(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)")
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
# Compile and link libgit2
Packit ae9e2a
ADD_LIBRARY(git2 ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1} ${WIN_RC})
Packit ae9e2a
TARGET_LINK_LIBRARIES(git2 ${SECURITY_DIRS})
Packit ae9e2a
TARGET_LINK_LIBRARIES(git2 ${COREFOUNDATION_DIRS})
Packit ae9e2a
TARGET_LINK_LIBRARIES(git2 ${SSL_LIBRARIES})
Packit ae9e2a
TARGET_LINK_LIBRARIES(git2 ${SSH_LIBRARIES})
Packit ae9e2a
TARGET_LINK_LIBRARIES(git2 ${GSSAPI_LIBRARIES})
Packit ae9e2a
TARGET_LINK_LIBRARIES(git2 ${ICONV_LIBRARIES})
Packit ae9e2a
TARGET_OS_LIBRARIES(git2)
Packit ae9e2a
Packit ae9e2a
# Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240)
Packit ae9e2a
# Win64+MSVC+static libs = linker error
Packit ae9e2a
IF(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS)
Packit ae9e2a
  SET_TARGET_PROPERTIES(git2 PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64")
Packit ae9e2a
ENDIF()
Packit ae9e2a
Packit ae9e2a
IDE_SPLIT_SOURCES(git2)
Packit ae9e2a
Packit ae9e2a
IF (SONAME)
Packit ae9e2a
	SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
Packit ae9e2a
	SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_SOVERSION})
Packit ae9e2a
	IF (LIBGIT2_FILENAME)
Packit ae9e2a
		ADD_DEFINITIONS(-DLIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
Packit ae9e2a
		SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
Packit ae9e2a
	ELSEIF (DEFINED LIBGIT2_PREFIX)
Packit ae9e2a
		SET_TARGET_PROPERTIES(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}")
Packit ae9e2a
	ENDIF()
Packit ae9e2a
ENDIF()
Packit ae9e2a
STRING(REPLACE ";" " " LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS}")
Packit ae9e2a
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libgit2.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc @ONLY)
Packit ae9e2a
Packit ae9e2a
IF (MSVC_IDE)
Packit ae9e2a
   # Precompiled headers
Packit ae9e2a
   SET_TARGET_PROPERTIES(git2 PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
Packit ae9e2a
   SET_SOURCE_FILES_PROPERTIES(src/win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h")
Packit ae9e2a
ENDIF ()
Packit ae9e2a
Packit ae9e2a
# Install
Packit ae9e2a
INSTALL(TARGETS git2
Packit ae9e2a
	RUNTIME DESTINATION ${BIN_INSTALL_DIR}
Packit ae9e2a
	LIBRARY DESTINATION ${LIB_INSTALL_DIR}
Packit ae9e2a
	ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
Packit ae9e2a
)
Packit ae9e2a
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
Packit ae9e2a
INSTALL(DIRECTORY include/git2 DESTINATION ${INCLUDE_INSTALL_DIR} )
Packit ae9e2a
INSTALL(FILES include/git2.h DESTINATION ${INCLUDE_INSTALL_DIR} )
Packit ae9e2a
Packit ae9e2a
# Tests
Packit ae9e2a
IF (BUILD_CLAR)
Packit ae9e2a
	FIND_PACKAGE(PythonInterp)
Packit ae9e2a
Packit ae9e2a
	IF(NOT PYTHONINTERP_FOUND)
Packit ae9e2a
	  MESSAGE(FATAL_ERROR "Could not find a python interpeter, which is needed to build the tests. "
Packit ae9e2a
	    "Make sure python is available, or pass -DBUILD_CLAR=OFF to skip building the tests")
Packit ae9e2a
	ENDIF()
Packit ae9e2a
Packit ae9e2a
	SET(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/")
Packit ae9e2a
	SET(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests")
Packit ae9e2a
	SET(CLAR_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources" CACHE PATH "Path to test resources.")
Packit ae9e2a
	ADD_DEFINITIONS(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
Packit ae9e2a
	ADD_DEFINITIONS(-DCLAR_RESOURCES=\"${TEST_RESOURCES}\")
Packit ae9e2a
	ADD_DEFINITIONS(-DCLAR_TMPDIR=\"libgit2_tests\")
Packit ae9e2a
Packit ae9e2a
	INCLUDE_DIRECTORIES(${CLAR_PATH})
Packit ae9e2a
	FILE(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
Packit ae9e2a
	SET(SRC_CLAR "${CLAR_PATH}/main.c" "${CLAR_PATH}/clar_libgit2.c" "${CLAR_PATH}/clar_libgit2_trace.c" "${CLAR_PATH}/clar_libgit2_timer.c" "${CLAR_PATH}/clar.c")
Packit ae9e2a
Packit ae9e2a
	ADD_CUSTOM_COMMAND(
Packit ae9e2a
		OUTPUT ${CLAR_PATH}/clar.suite
Packit ae9e2a
		COMMAND ${PYTHON_EXECUTABLE} generate.py -f -xonline -xstress -xperf .
Packit ae9e2a
		DEPENDS ${SRC_TEST}
Packit ae9e2a
		WORKING_DIRECTORY ${CLAR_PATH}
Packit ae9e2a
	)
Packit ae9e2a
Packit ae9e2a
	SET_SOURCE_FILES_PROPERTIES(
Packit ae9e2a
		${CLAR_PATH}/clar.c
Packit ae9e2a
		PROPERTIES OBJECT_DEPENDS ${CLAR_PATH}/clar.suite)
Packit ae9e2a
Packit ae9e2a
	ADD_EXECUTABLE(libgit2_clar ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_CLAR} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1})
Packit ae9e2a
Packit ae9e2a
	TARGET_LINK_LIBRARIES(libgit2_clar ${COREFOUNDATION_DIRS})
Packit ae9e2a
	TARGET_LINK_LIBRARIES(libgit2_clar ${SECURITY_DIRS})
Packit ae9e2a
	TARGET_LINK_LIBRARIES(libgit2_clar ${SSL_LIBRARIES})
Packit ae9e2a
	TARGET_LINK_LIBRARIES(libgit2_clar ${SSH_LIBRARIES})
Packit ae9e2a
	TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES})
Packit ae9e2a
	TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES})
Packit ae9e2a
	TARGET_OS_LIBRARIES(libgit2_clar)
Packit ae9e2a
	IDE_SPLIT_SOURCES(libgit2_clar)
Packit ae9e2a
Packit ae9e2a
	IF (MSVC_IDE)
Packit ae9e2a
		# Precompiled headers
Packit ae9e2a
		SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
Packit ae9e2a
	ENABLE_TESTING()
Packit ae9e2a
Packit ae9e2a
	ADD_TEST(offline   libgit2_clar -v -xonline)
Packit Service b87dbd
	ADD_TEST(online    libgit2_clar -v -sonline)
Packit Service b87dbd
	ADD_TEST(gitdaemon libgit2_clar -v -sonline::push)
Packit Service b87dbd
	ADD_TEST(ssh       libgit2_clar -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths)
Packit Service b87dbd
	ADD_TEST(proxy     libgit2_clar -v -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request)
Packit ae9e2a
ENDIF ()
Packit ae9e2a
Packit ae9e2a
IF (TAGS)
Packit ae9e2a
	FIND_PROGRAM(CTAGS ctags)
Packit ae9e2a
	IF (NOT CTAGS)
Packit ae9e2a
		MESSAGE(FATAL_ERROR "Could not find ctags command")
Packit ae9e2a
	ENDIF ()
Packit ae9e2a
Packit ae9e2a
	FILE(GLOB_RECURSE SRC_ALL *.[ch])
Packit ae9e2a
Packit ae9e2a
	ADD_CUSTOM_COMMAND(
Packit ae9e2a
		OUTPUT tags
Packit ae9e2a
		COMMAND ${CTAGS} -a ${SRC_ALL}
Packit ae9e2a
		DEPENDS ${SRC_ALL}
Packit ae9e2a
	)
Packit ae9e2a
	ADD_CUSTOM_TARGET(
Packit ae9e2a
		do_tags ALL
Packit ae9e2a
		DEPENDS tags
Packit ae9e2a
	)
Packit ae9e2a
ENDIF ()
Packit ae9e2a
Packit ae9e2a
IF (BUILD_EXAMPLES)
Packit ae9e2a
	ADD_SUBDIRECTORY(examples)
Packit ae9e2a
ENDIF ()