mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-28 14:02:57 +00:00

MSYS/MinGW uses winsock but obviously doesn't set _MSC_VER. Use _WIN32 to decide whether to use winsock or BSD headers. Also remove these headers from src/transport_git.c altogether, as they are not needed. MSYS is very conservative, so we have to tell it that we don't care about versions of Windows lower than WindowsXP. We also need to tell CMake to add ws2_32 to the libraries list and we shouldn't add the -fPIC option, to MSYS because it complains that it does it anyway. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
124 lines
3.6 KiB
CMake
124 lines
3.6 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 "include/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
|
|
INCLUDE_DIRECTORIES(src include)
|
|
IF (NOT WIN32)
|
|
FIND_PACKAGE(ZLIB)
|
|
ENDIF()
|
|
|
|
IF (ZLIB_FOUND)
|
|
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
|
|
LINK_LIBRARIES(${ZLIB_LIBRARIES})
|
|
ELSE (ZLIB_FOUND)
|
|
INCLUDE_DIRECTORIES(deps/zlib)
|
|
ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
|
|
FILE(GLOB SRC_ZLIB deps/zlib/*.c)
|
|
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)
|
|
OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF)
|
|
|
|
# Platform specific compilation flags
|
|
IF (MSVC)
|
|
SET(CMAKE_C_FLAGS "/W4 /WX /nologo /Zi")
|
|
# TODO: bring back /RTC1 /RTCc
|
|
SET(CMAKE_C_FLAGS_DEBUG "/Od /DEBUG /MTd")
|
|
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
|
|
ELSE ()
|
|
SET(CMAKE_C_FLAGS "-Wall -Wextra")
|
|
IF (NOT MINGW) # MinGW always does PIC and complains if we tell it to
|
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
|
ENDIF ()
|
|
SET(CMAKE_C_FLAGS_DEBUG "-g -O0")
|
|
SET(CMAKE_C_FLAGS_RELEASE "-O2")
|
|
ENDIF()
|
|
|
|
# Build Debug by default
|
|
IF (NOT CMAKE_BUILD_TYPE)
|
|
SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
|
ENDIF ()
|
|
|
|
IF (THREADSAFE)
|
|
IF (NOT WIN32)
|
|
find_package(Threads REQUIRED)
|
|
ENDIF()
|
|
|
|
ADD_DEFINITIONS(-DGIT_THREADS)
|
|
ENDIF()
|
|
|
|
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
|
|
|
|
# Collect sourcefiles
|
|
FILE(GLOB SRC_H include/git2/*.h)
|
|
|
|
# On Windows use specific platform sources
|
|
IF (WIN32 AND NOT CYGWIN)
|
|
ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_LIB)
|
|
FILE(GLOB SRC src/*.c src/win32/*.c)
|
|
ELSE()
|
|
FILE(GLOB SRC src/*.c src/unix/*.c)
|
|
ENDIF ()
|
|
|
|
# Compile and link libgit2
|
|
ADD_LIBRARY(git2 ${SRC} ${SRC_ZLIB})
|
|
|
|
IF (WIN32)
|
|
TARGET_LINK_LIBRARIES(git2 ws2_32)
|
|
ENDIF ()
|
|
|
|
TARGET_LINK_LIBRARIES(git2 ${CMAKE_THREAD_LIBS_INIT})
|
|
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 include/git2 DESTINATION ${INSTALL_INC} )
|
|
INSTALL(FILES include/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}\")
|
|
|
|
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_TEST} ${SRC_ZLIB})
|
|
TARGET_LINK_LIBRARIES(libgit2_test ${CMAKE_THREAD_LIBS_INIT})
|
|
|
|
ENABLE_TESTING()
|
|
ADD_TEST(libgit2_test libgit2_test)
|
|
ENDIF ()
|