summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-09-06 07:38:48 +0200
committerPatrick Steinhardt <ps@pks.im>2017-09-20 15:26:26 +0200
commit8c19969a88c3b6e72564e812537b15cbc0fb4cc0 (patch)
treed108879404ca4980dd9d696631abb58a65ff00b8
parentd8d2f21e24933cddabf30f2d4a4ddf1be0072e56 (diff)
downloadlibgit2-8c19969a88c3b6e72564e812537b15cbc0fb4cc0.tar.gz
cmake: fix static linking for bundled deps
Our bundled deps are being built as simple static libraries which are then linked into the libgit2 library via `TARGET_LINK_LIBRARIES`. While this works for a dynamically built libgit2 library, using this function to link two static libraries does not have the expected outcome of merging those static libraries into one big library. This leads to symbols of our bundled deps being undefined in the resulting libgit2 archive. As we have bumped our minimum CMake version to 2.8.11, we can now easily make use of object libraries for our bundled dependencies. So build instructions are still self-contained inside of the dependency directories and the resulting object libraries can just be added to the LIBGIT2_OBJECTS list, which will cause them to be linked into the final resulting static library. This fixes the issue of undefined symbols.
-rw-r--r--deps/http-parser/CMakeLists.txt2
-rw-r--r--deps/regex/CMakeLists.txt2
-rw-r--r--deps/zlib/CMakeLists.txt2
-rw-r--r--src/CMakeLists.txt6
4 files changed, 6 insertions, 6 deletions
diff --git a/deps/http-parser/CMakeLists.txt b/deps/http-parser/CMakeLists.txt
index 9309841db..77d9de7a3 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 6ef8a270f..141b54c4c 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 ca50d80c4..b0cb7f7ea 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 6b7e0f666..daecc5a84 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -183,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
@@ -196,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
@@ -214,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