mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 07:33:25 +00:00

Unfortunately previous commit was only a partial fix, because it broke SQLite support on platforms w/o pkg-config, e.g. Windows. To be honest I just forgot about messy Windows. Now if there is no pkg-config, then user must provide two variables: SQLITE3_INCLUDE_DIRS and SQLITE3_LIBRARIES if (s)he wants to use SQLite backend. These variables are added to cmake-gui for her/his convenience unless they are set by FindPkgConfig module. pkg-config should work also now in Cygwin.
128 lines
4.2 KiB
CMake
128 lines
4.2 KiB
CMake
# CMake build script for the libgit2 project
|
|
#
|
|
# Building (out of source build):
|
|
# > mkdir build && cd build
|
|
# > cmake .. [-DSETTINGS=VALUE]
|
|
# > cmake --build .
|
|
#
|
|
# Testing:
|
|
# > ctest -V
|
|
#
|
|
# Install:
|
|
# > cmake --build . --target install
|
|
|
|
PROJECT(libgit2 C)
|
|
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
|
|
|
FILE(STRINGS "src/git2.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}")
|
|
|
|
# Find required dependencies
|
|
FIND_PACKAGE(ZLIB REQUIRED)
|
|
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR} src)
|
|
|
|
# Try finding openssl
|
|
FIND_PACKAGE(OpenSSL)
|
|
IF (OPENSSL_CRYPTO_LIBRARIES)
|
|
SET(SHA1_TYPE "openssl" CACHE STRING "Which SHA1 implementation to use: builtin, ppc, openssl")
|
|
ELSEIF ()
|
|
SET(SHA1_TYPE "builtin" CACHE STRING "Which SHA1 implementation to use: builtin, ppc")
|
|
ENDIF ()
|
|
|
|
INCLUDE(FindPkgConfig)
|
|
|
|
# Show SQLite3 settings in GUI (if they won't be found out)
|
|
SET(SQLITE3_INCLUDE_DIRS "" CACHE PATH "SQLite include directory")
|
|
SET(SQLITE3_LIBRARIES "" CACHE FILEPATH "SQLite library")
|
|
|
|
# Are SQLite3 variables already set up? (poor Windows/no pkg-config/no sqlite3.pc)
|
|
IF (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
|
|
SET(SQLITE3_FOUND 1)
|
|
ENDIF ()
|
|
|
|
# Try to find SQLite3 via pkg-config
|
|
IF (PKG_CONFIG_FOUND AND NOT SQLITE3_FOUND)
|
|
pkg_check_modules(SQLITE3 sqlite3)
|
|
ENDIF ()
|
|
|
|
# Compile SQLite backend if SQLite3 is available
|
|
IF (SQLITE3_FOUND)
|
|
ADD_DEFINITIONS(-DGIT2_SQLITE_BACKEND)
|
|
INCLUDE_DIRECTORIES(${SQLITE3_INCLUDE_DIRS})
|
|
ENDIF ()
|
|
|
|
# Installation paths
|
|
SET(INSTALL_BIN bin CACHE PATH "Where to install binaries to.")
|
|
SET(INSTALL_LIB lib CACHE PATH "Where to install libraries to.")
|
|
SET(INSTALL_INC include CACHE PATH "Where to install headers to.")
|
|
|
|
# Build options
|
|
OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
|
|
OPTION (BUILD_TESTS "Build Tests" ON)
|
|
|
|
# Build Release by default
|
|
IF (NOT CMAKE_BUILD_TYPE)
|
|
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
|
ENDIF ()
|
|
|
|
# Collect sourcefiles
|
|
FILE(GLOB SRC src/*.c src/backends/*.c)
|
|
FILE(GLOB SRC_SHA1 src/block-sha1/*.c)
|
|
FILE(GLOB SRC_PLAT src/unix/*.c)
|
|
FILE(GLOB SRC_H src/git/*.h)
|
|
|
|
# On Windows use specific platform sources
|
|
IF (WIN32 AND NOT CYGWIN)
|
|
ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_LIB -DZLIB_WINAPI)
|
|
FILE(GLOB SRC_PLAT src/win32/*.c)
|
|
IF (MINGW)
|
|
SET(PTHREAD_LIBRARY pthread)
|
|
ENDIF ()
|
|
ENDIF ()
|
|
|
|
# Specify sha1 implementation
|
|
IF (SHA1_TYPE STREQUAL "ppc")
|
|
ADD_DEFINITIONS(-DPPC_SHA1)
|
|
FILE(GLOB SRC_SHA1 src/ppc/*.c)
|
|
ELSEIF (SHA1_TYPE STREQUAL "openssl")
|
|
ADD_DEFINITIONS(-DOPENSSL_SHA1)
|
|
SET (SRC_SHA1)
|
|
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
|
|
SET (LIB_SHA1 ${OPENSSL_CRYPTO_LIBRARIES})
|
|
ENDIF ()
|
|
|
|
# Compile and link libgit2
|
|
ADD_LIBRARY(git2 ${SRC} ${SRC_PLAT} ${SRC_SHA1})
|
|
TARGET_LINK_LIBRARIES(git2 ${ZLIB_LIBRARY} ${LIB_SHA1} ${PTHREAD_LIBRARY} ${SQLITE3_LIBRARIES})
|
|
SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
|
|
SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_VERSION_MAJOR})
|
|
|
|
# Install
|
|
INSTALL(TARGETS git2
|
|
RUNTIME DESTINATION ${INSTALL_BIN}
|
|
LIBRARY DESTINATION ${INSTALL_LIB}
|
|
ARCHIVE DESTINATION ${INSTALL_LIB}
|
|
)
|
|
INSTALL(DIRECTORY src/git2 DESTINATION ${INSTALL_INC} )
|
|
INSTALL(FILES src/git2.h DESTINATION ${INSTALL_INC} )
|
|
|
|
# Tests
|
|
IF (BUILD_TESTS)
|
|
SET(TEST_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources" CACHE PATH "Path to test resources.")
|
|
ADD_DEFINITIONS(-DTEST_RESOURCES=\"${TEST_RESOURCES}\")
|
|
|
|
ENABLE_TESTING()
|
|
INCLUDE_DIRECTORIES(tests)
|
|
|
|
FILE(GLOB SRC_TEST tests/t??-*.c)
|
|
|
|
ADD_EXECUTABLE(libgit2_test tests/test_main.c tests/test_lib.c tests/test_helpers.c ${SRC} ${SRC_PLAT} ${SRC_SHA1} ${SRC_TEST})
|
|
TARGET_LINK_LIBRARIES(libgit2_test ${ZLIB_LIBRARY} ${LIB_SHA1} ${PTHREAD_LIBRARY} ${SQLITE3_LIBRARIES})
|
|
|
|
ADD_TEST(libgit2_test libgit2_test)
|
|
ENDIF ()
|