Skip to content

Commit c7c5f2c

Browse files
authored
Merge pull request libgit2#4339 from pks-t/pks/static-linking
Static linking for bundled deps
2 parents 524c1d3 + 366f413 commit c7c5f2c

File tree

7 files changed

+24
-28
lines changed

7 files changed

+24
-28
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ matrix:
3030
- os: osx
3131
compiler: gcc
3232
include:
33-
- compiler: gcc
34-
env: PRECISE=1
35-
os: linux
36-
dist: precise
3733
- compiler: gcc
3834
env: COVERITY=1
3935
os: linux

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# > cmake --build . --target install
1313

1414
PROJECT(libgit2 C)
15-
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
15+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
1616
CMAKE_POLICY(SET CMP0015 NEW)
1717
IF (CMAKE_VERSION VERSION_GREATER 3.0)
1818
CMAKE_POLICY(SET CMP0051 NEW)

deps/http-parser/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
FILE(GLOB SRC_HTTP "*.c" "*.h")
22

3-
ADD_LIBRARY(http-parser STATIC ${SRC_HTTP})
3+
ADD_LIBRARY(http-parser OBJECT ${SRC_HTTP})

deps/regex/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
INCLUDE_DIRECTORIES(".")
2-
ADD_LIBRARY(regex STATIC "regex.c" "regex.h")
2+
ADD_LIBRARY(regex OBJECT "regex.c" "regex.h")

deps/zlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
22
FILE(GLOB SRC_ZLIB "*.c" "*.h")
33
INCLUDE_DIRECTORIES(".")
4-
ADD_LIBRARY(zlib STATIC ${SRC_ZLIB})
4+
ADD_LIBRARY(zlib OBJECT ${SRC_ZLIB})

src/CMakeLists.txt

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ IF(DEBUG_POOL)
22
SET(GIT_DEBUG_POOL 1)
33
ENDIF()
44

5+
SET(LIBGIT2_OBJECTS "")
6+
57
# This variable will contain the libraries we need to put into
68
# libgit2.pc's Requires.private. That is, what we're linking to or
79
# what someone who's statically linking us needs to link to.
@@ -181,7 +183,7 @@ ENDIF()
181183
IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
182184
ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/deps/regex" "${CMAKE_BINARY_DIR}/deps/regex")
183185
LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/regex")
184-
LIST(APPEND LIBGIT2_LIBS regex)
186+
LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:regex>)
185187
ENDIF()
186188

187189
# Optional external dependency: http-parser
@@ -194,7 +196,7 @@ ELSE()
194196
MESSAGE(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
195197
ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/deps/http-parser" "${CMAKE_BINARY_DIR}/deps/http-parser")
196198
LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/http-parser")
197-
LIST(APPEND LIBGIT2_LIBS http-parser)
199+
LIST(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:http-parser>")
198200
ENDIF()
199201

200202
# Optional external dependency: zlib
@@ -212,7 +214,7 @@ ELSE()
212214
MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." )
213215
ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/deps/zlib" "${CMAKE_BINARY_DIR}/deps/zlib")
214216
LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/zlib")
215-
LIST(APPEND LIBGIT2_LIBS zlib)
217+
LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:zlib>)
216218
ENDIF()
217219

218220
# Optional external dependency: libssh2
@@ -330,32 +332,28 @@ ENDIF()
330332

331333
CONFIGURE_FILE(features.h.in git2/sys/features.h)
332334

333-
SET(GIT2INTERNAL_OBJECTS ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_SSH} ${SRC_SHA1})
335+
SET(LIBGIT2_SOURCES ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_SSH} ${SRC_SHA1})
334336

335-
IF (CMAKE_VERSION VERSION_GREATER 2.8.7)
336-
ADD_LIBRARY(git2internal OBJECT ${GIT2INTERNAL_OBJECTS})
337-
IDE_SPLIT_SOURCES(git2internal)
338-
SET(GIT2INTERNAL_OBJECTS $<TARGET_OBJECTS:git2internal>)
337+
ADD_LIBRARY(git2internal OBJECT ${LIBGIT2_SOURCES})
338+
IDE_SPLIT_SOURCES(git2internal)
339+
LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:git2internal>)
339340

340-
IF (${CMAKE_VERSION} VERSION_LESS 2.8.12)
341-
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
342-
ELSE()
343-
TARGET_INCLUDE_DIRECTORIES(git2internal
344-
PRIVATE ${LIBGIT2_INCLUDES}
345-
PUBLIC ${CMAKE_SOURCE_DIR}/include)
346-
ENDIF()
347-
ELSE()
341+
IF (${CMAKE_VERSION} VERSION_LESS 2.8.12)
348342
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
343+
ELSE()
344+
TARGET_INCLUDE_DIRECTORIES(git2internal
345+
PRIVATE ${LIBGIT2_INCLUDES}
346+
PUBLIC ${CMAKE_SOURCE_DIR}/include)
349347
ENDIF()
350348

351-
SET(GIT2INTERNAL_OBJECTS ${GIT2INTERNAL_OBJECTS} PARENT_SCOPE)
349+
SET(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
352350
SET(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
353351
SET(LIBGIT2_LIBS ${LIBGIT2_LIBS} PARENT_SCOPE)
354352
SET(LIBGIT2_LIBDIRS ${LIBGIT2_LIBDIRS} PARENT_SCOPE)
355353

356354
# Compile and link libgit2
357355
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
358-
ADD_LIBRARY(git2 ${WIN_RC} ${GIT2INTERNAL_OBJECTS})
356+
ADD_LIBRARY(git2 ${WIN_RC} ${LIBGIT2_OBJECTS})
359357
TARGET_LINK_LIBRARIES(git2 ${LIBGIT2_LIBS})
360358

361359
SET_TARGET_PROPERTIES(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

tests/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ SET_SOURCE_FILES_PROPERTIES(
3333
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
3434
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
3535

36-
ADD_EXECUTABLE(libgit2_clar ${SRC_CLAR} ${SRC_TEST} ${GIT2INTERNAL_OBJECTS})
36+
ADD_EXECUTABLE(libgit2_clar ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
3737

3838
SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
3939

40-
IF (${CMAKE_VERSION} VERSION_GREATER 2.8.11)
40+
IF (${CMAKE_VERSION} VERSION_LESS 2.8.12)
41+
# Already handled by a global INCLUDE_DIRECTORY()
42+
ELSE()
4143
TARGET_INCLUDE_DIRECTORIES(libgit2_clar PRIVATE ../src PUBLIC ../include)
4244
ENDIF()
4345

0 commit comments

Comments
 (0)