Merge pull request #4339 from pks-t/pks/static-linking Static linking for bundled deps
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
diff --git a/.travis.yml b/.travis.yml
index 8bbcb39..08289aa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -31,10 +31,6 @@ matrix:
compiler: gcc
include:
- compiler: gcc
- env: PRECISE=1
- os: linux
- dist: precise
- - compiler: gcc
env: COVERITY=1
os: linux
dist: trusty
diff --git a/CMakeLists.txt b/CMakeLists.txt
index af4c34e..3f360e2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,7 +12,7 @@
# > cmake --build . --target install
PROJECT(libgit2 C)
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
CMAKE_POLICY(SET CMP0015 NEW)
IF (CMAKE_VERSION VERSION_GREATER 3.0)
CMAKE_POLICY(SET CMP0051 NEW)
diff --git a/deps/http-parser/CMakeLists.txt b/deps/http-parser/CMakeLists.txt
index 9309841..77d9de7 100644
--- a/deps/http-parser/CMakeLists.txt
+++ b/deps/http-parser/CMakeLists.txt
@@ -1,3 +1,3 @@
FILE(GLOB SRC_HTTP "*.c" "*.h")
-ADD_LIBRARY(http-parser STATIC ${SRC_HTTP})
+ADD_LIBRARY(http-parser OBJECT ${SRC_HTTP})
diff --git a/deps/regex/CMakeLists.txt b/deps/regex/CMakeLists.txt
index 6ef8a27..141b54c 100644
--- a/deps/regex/CMakeLists.txt
+++ b/deps/regex/CMakeLists.txt
@@ -1,2 +1,2 @@
INCLUDE_DIRECTORIES(".")
-ADD_LIBRARY(regex STATIC "regex.c" "regex.h")
+ADD_LIBRARY(regex OBJECT "regex.c" "regex.h")
diff --git a/deps/zlib/CMakeLists.txt b/deps/zlib/CMakeLists.txt
index ca50d80..b0cb7f7 100644
--- a/deps/zlib/CMakeLists.txt
+++ b/deps/zlib/CMakeLists.txt
@@ -1,4 +1,4 @@
ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
FILE(GLOB SRC_ZLIB "*.c" "*.h")
INCLUDE_DIRECTORIES(".")
-ADD_LIBRARY(zlib STATIC ${SRC_ZLIB})
+ADD_LIBRARY(zlib OBJECT ${SRC_ZLIB})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3392a42..daecc5a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,6 +2,8 @@ IF(DEBUG_POOL)
SET(GIT_DEBUG_POOL 1)
ENDIF()
+SET(LIBGIT2_OBJECTS "")
+
# This variable will contain the libraries we need to put into
# libgit2.pc's Requires.private. That is, what we're linking to or
# what someone who's statically linking us needs to link to.
@@ -181,7 +183,7 @@ ENDIF()
IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/deps/regex" "${CMAKE_BINARY_DIR}/deps/regex")
LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/regex")
- LIST(APPEND LIBGIT2_LIBS regex)
+ LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:regex>)
ENDIF()
# Optional external dependency: http-parser
@@ -194,7 +196,7 @@ ELSE()
MESSAGE(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/deps/http-parser" "${CMAKE_BINARY_DIR}/deps/http-parser")
LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/http-parser")
- LIST(APPEND LIBGIT2_LIBS http-parser)
+ LIST(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:http-parser>")
ENDIF()
# Optional external dependency: zlib
@@ -212,7 +214,7 @@ ELSE()
MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." )
ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/deps/zlib" "${CMAKE_BINARY_DIR}/deps/zlib")
LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/zlib")
- LIST(APPEND LIBGIT2_LIBS zlib)
+ LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:zlib>)
ENDIF()
# Optional external dependency: libssh2
@@ -330,32 +332,28 @@ ENDIF()
CONFIGURE_FILE(features.h.in git2/sys/features.h)
-SET(GIT2INTERNAL_OBJECTS ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_SSH} ${SRC_SHA1})
+SET(LIBGIT2_SOURCES ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_SSH} ${SRC_SHA1})
-IF (CMAKE_VERSION VERSION_GREATER 2.8.7)
- ADD_LIBRARY(git2internal OBJECT ${GIT2INTERNAL_OBJECTS})
- IDE_SPLIT_SOURCES(git2internal)
- SET(GIT2INTERNAL_OBJECTS $<TARGET_OBJECTS:git2internal>)
+ADD_LIBRARY(git2internal OBJECT ${LIBGIT2_SOURCES})
+IDE_SPLIT_SOURCES(git2internal)
+LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:git2internal>)
- IF (${CMAKE_VERSION} VERSION_LESS 2.8.12)
- INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
- ELSE()
- TARGET_INCLUDE_DIRECTORIES(git2internal
- PRIVATE ${LIBGIT2_INCLUDES}
- PUBLIC ${CMAKE_SOURCE_DIR}/include)
- ENDIF()
-ELSE()
+IF (${CMAKE_VERSION} VERSION_LESS 2.8.12)
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
+ELSE()
+ TARGET_INCLUDE_DIRECTORIES(git2internal
+ PRIVATE ${LIBGIT2_INCLUDES}
+ PUBLIC ${CMAKE_SOURCE_DIR}/include)
ENDIF()
-SET(GIT2INTERNAL_OBJECTS ${GIT2INTERNAL_OBJECTS} PARENT_SCOPE)
+SET(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
SET(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
SET(LIBGIT2_LIBS ${LIBGIT2_LIBS} PARENT_SCOPE)
SET(LIBGIT2_LIBDIRS ${LIBGIT2_LIBDIRS} PARENT_SCOPE)
# Compile and link libgit2
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
-ADD_LIBRARY(git2 ${WIN_RC} ${GIT2INTERNAL_OBJECTS})
+ADD_LIBRARY(git2 ${WIN_RC} ${LIBGIT2_OBJECTS})
TARGET_LINK_LIBRARIES(git2 ${LIBGIT2_LIBS})
SET_TARGET_PROPERTIES(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 5aba291..53265cc 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -33,11 +33,13 @@ SET_SOURCE_FILES_PROPERTIES(
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
-ADD_EXECUTABLE(libgit2_clar ${SRC_CLAR} ${SRC_TEST} ${GIT2INTERNAL_OBJECTS})
+ADD_EXECUTABLE(libgit2_clar ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
-IF (${CMAKE_VERSION} VERSION_GREATER 2.8.11)
+IF (${CMAKE_VERSION} VERSION_LESS 2.8.12)
+ # Already handled by a global INCLUDE_DIRECTORY()
+ELSE()
TARGET_INCLUDE_DIRECTORIES(libgit2_clar PRIVATE ../src PUBLIC ../include)
ENDIF()