Commit 8e31cc25 by Patrick Steinhardt

cmake: keep track of libraries and includes via lists

Later on, we will move detection of required libraries, library
directories as well as include directories into a separate
CMakeLists.txt file inside of the source directory. Obviously, we want
to avoid duplication here regarding these parameters.

To prepare for the split, put the parameters into three variables
LIBGIT2_LIBS, LIBGIT2_LIBDIRS and LIBGIT2_INCLUDES, tracking the
required libraries, linking directory as well as include directories.
These variables can later be exported into the parent scope from inside
of the source build instructions, making them readily available for the
other subdirectories.
parent dd332e2a
...@@ -128,6 +128,10 @@ SET(LIBGIT2_PC_REQUIRES "") ...@@ -128,6 +128,10 @@ SET(LIBGIT2_PC_REQUIRES "")
# pc file. # pc file.
SET(LIBGIT2_PC_LIBS "") SET(LIBGIT2_PC_LIBS "")
SET(LIBGIT2_INCLUDES "")
SET(LIBGIT2_LIBS "")
SET(LIBGIT2_LIBDIRS "")
# Installation paths # Installation paths
# #
SET(BIN_INSTALL_DIR bin CACHE PATH "Where to install binaries to.") SET(BIN_INSTALL_DIR bin CACHE PATH "Where to install binaries to.")
...@@ -218,11 +222,10 @@ IF (SECURITY_FOUND) ...@@ -218,11 +222,10 @@ IF (SECURITY_FOUND)
IF (HAVE_NEWER_SECURITY) IF (HAVE_NEWER_SECURITY)
MESSAGE("-- Found Security ${SECURITY_DIRS}") MESSAGE("-- Found Security ${SECURITY_DIRS}")
LIST(APPEND LIBGIT2_PC_LIBS "-framework Security") LIST(APPEND LIBGIT2_PC_LIBS "-framework Security")
LIST(APPEND LIBGIT2_LIBS ${SECURITY_DIRS})
ELSE() ELSE()
MESSAGE("-- Security framework is too old, falling back to OpenSSL") MESSAGE("-- Security framework is too old, falling back to OpenSSL")
SET(SECURITY_FOUND "NO") SET(SECURITY_FOUND "NO")
SET(SECURITY_DIRS "")
SET(SECURITY_DIR "")
SET(USE_OPENSSL "ON") SET(USE_OPENSSL "ON")
ENDIF() ENDIF()
ENDIF() ENDIF()
...@@ -230,12 +233,13 @@ ENDIF() ...@@ -230,12 +233,13 @@ ENDIF()
IF (COREFOUNDATION_FOUND) IF (COREFOUNDATION_FOUND)
MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_DIRS}") MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_DIRS}")
LIST(APPEND LIBGIT2_PC_LIBS "-framework CoreFoundation") LIST(APPEND LIBGIT2_PC_LIBS "-framework CoreFoundation")
LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_DIRS})
ENDIF() ENDIF()
IF (WIN32 AND EMBED_SSH_PATH) IF (WIN32 AND EMBED_SSH_PATH)
FILE(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c") FILE(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
INCLUDE_DIRECTORIES("${EMBED_SSH_PATH}/include") LIST(APPEND LIBGIT2_INCLUDES "${EMBED_SSH_PATH}/include")
FILE(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"") FILE(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
SET(GIT_SSH 1) SET(GIT_SSH 1)
ENDIF() ENDIF()
...@@ -273,11 +277,11 @@ IF (WIN32 AND WINHTTP) ...@@ -273,11 +277,11 @@ IF (WIN32 AND WINHTTP)
PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a
) )
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/deps/winhttp") LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/winhttp")
LINK_DIRECTORIES(${LIBWINHTTP_PATH}) LIST(APPEND LIBGIT2_LIBDIRS ${LIBWINHTTP_PATH})
ENDIF () ENDIF ()
LINK_LIBRARIES(winhttp rpcrt4 crypt32 ole32) LIST(APPEND LIBGIT2_LIBS "winhttp" "rpcrt4" "crypt32" "ole32")
LIST(APPEND LIBGIT2_PC_LIBS "-lwinhttp" "-lrpcrt4" "-lcrypt32" "-lole32") LIST(APPEND LIBGIT2_PC_LIBS "-lwinhttp" "-lrpcrt4" "-lcrypt32" "-lole32")
ELSE () ELSE ()
IF (CURL) IF (CURL)
...@@ -290,9 +294,9 @@ ELSE () ...@@ -290,9 +294,9 @@ ELSE ()
IF (CURL_FOUND) IF (CURL_FOUND)
SET(GIT_CURL 1) SET(GIT_CURL 1)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS}) LIST(APPEND LIBGIT2_INCLUDES ${CURL_INCLUDE_DIRS})
LINK_DIRECTORIES(${CURL_LIBRARY_DIRS}) LIST(APPEND LIBGIT2_LIBDIRS ${CURL_LIBRARY_DIRS})
LINK_LIBRARIES(${CURL_LIBRARIES}) LIST(APPEND LIBGIT2_LIBS ${CURL_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS}) LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
ENDIF() ENDIF()
ENDIF() ENDIF()
...@@ -327,35 +331,36 @@ ENDIF() ...@@ -327,35 +331,36 @@ ENDIF()
# Include POSIX regex when it is required # Include POSIX regex when it is required
IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/deps/regex") LIST(APPEND LBIGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/regex")
SET(SRC_REGEX "${CMAKE_SOURCE_DIR}/deps/regex/regex.c") SET(SRC_REGEX "${CMAKE_SOURCE_DIR}/deps/regex/regex.c")
ENDIF() ENDIF()
# Optional external dependency: http-parser # Optional external dependency: http-parser
FIND_PACKAGE(HTTP_Parser) FIND_PACKAGE(HTTP_Parser)
IF (USE_EXT_HTTP_PARSER AND HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2) IF (USE_EXT_HTTP_PARSER AND HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
INCLUDE_DIRECTORIES(${HTTP_PARSER_INCLUDE_DIRS}) LIST(APPEND LIBGIT2_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
LINK_LIBRARIES(${HTTP_PARSER_LIBRARIES}) LIST(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser") LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
ELSE() ELSE()
MESSAGE(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.") MESSAGE(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/deps/http-parser") LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/http-parser")
FILE(GLOB SRC_HTTP "${CMAKE_SOURCE_DIR}/deps/http-parser/*.c" "${CMAKE_SOURCE_DIR}/deps/http-parser/*.h") FILE(GLOB SRC_HTTP "${CMAKE_SOURCE_DIR}/deps/http-parser/*.c" "${CMAKE_SOURCE_DIR}/deps/http-parser/*.h")
ENDIF() ENDIF()
# Optional external dependency: zlib # Optional external dependency: zlib
FIND_PACKAGE(ZLIB) FIND_PACKAGE(ZLIB)
IF (ZLIB_FOUND) IF (ZLIB_FOUND)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS}) LIST(APPEND LIBGIT2_INCLUDES ${ZLIB_INCLUDE_DIRS})
LINK_LIBRARIES(${ZLIB_LIBRARIES}) LIST(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES})
IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
LIST(APPEND LIBGIT2_LIBS "z")
LIST(APPEND LIBGIT2_PC_LIBS "-lz") LIST(APPEND LIBGIT2_PC_LIBS "-lz")
ELSE() ELSE()
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib") SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
ENDIF() ENDIF()
ELSE() ELSE()
MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." ) MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." )
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/deps/zlib") LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/zlib")
ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP) ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
FILE(GLOB SRC_ZLIB "${CMAKE_SOURCE_DIR}/deps/zlib/*.c" "${CMAKE_SOURCE_DIR}/deps/zlib/*.h") FILE(GLOB SRC_ZLIB "${CMAKE_SOURCE_DIR}/deps/zlib/*.c" "${CMAKE_SOURCE_DIR}/deps/zlib/*.h")
ENDIF() ENDIF()
...@@ -366,11 +371,11 @@ IF (USE_SSH) ...@@ -366,11 +371,11 @@ IF (USE_SSH)
ENDIF() ENDIF()
IF (LIBSSH2_FOUND) IF (LIBSSH2_FOUND)
SET(GIT_SSH 1) SET(GIT_SSH 1)
INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIRS}) LIST(APPEND LIBGIT2_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBSSH2_LIBRARY_DIRS}) LIST(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES})
LIST(APPEND LIBGIT2_LIBDIRS ${LIBSSH2_LIBRARY_DIRS})
LIST(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS}) LIST(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
#SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${LIBSSH2_LDFLAGS}") #SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${LIBSSH2_LDFLAGS}")
SET(SSH_LIBRARIES ${LIBSSH2_LIBRARIES})
CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS) CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS) IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS)
...@@ -386,6 +391,7 @@ IF (USE_GSSAPI) ...@@ -386,6 +391,7 @@ IF (USE_GSSAPI)
ENDIF() ENDIF()
IF (GSSAPI_FOUND) IF (GSSAPI_FOUND)
SET(GIT_GSSAPI 1) SET(GIT_GSSAPI 1)
LIST(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES})
ENDIF() ENDIF()
# Optional external dependency: iconv # Optional external dependency: iconv
...@@ -394,7 +400,8 @@ IF (USE_ICONV) ...@@ -394,7 +400,8 @@ IF (USE_ICONV)
ENDIF() ENDIF()
IF (ICONV_FOUND) IF (ICONV_FOUND)
SET(GIT_USE_ICONV 1) SET(GIT_USE_ICONV 1)
INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR}) LIST(APPEND LIBGIT2_INCLUDES ${ICONV_INCLUDE_DIR})
LIST(APPEND LIBGIT2_LIBS ${ICONV_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES}) LIST(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
ENDIF() ENDIF()
...@@ -551,14 +558,14 @@ ENDIF() ...@@ -551,14 +558,14 @@ ENDIF()
IF (SECURITY_FOUND) IF (SECURITY_FOUND)
SET(GIT_SECURE_TRANSPORT 1) SET(GIT_SECURE_TRANSPORT 1)
SET(GIT_HTTPS 1) SET(GIT_HTTPS 1)
INCLUDE_DIRECTORIES(${SECURITY_INCLUDE_DIR}) LIST(APPEND LIBGIT2_INCLUDES ${SECURITY_INCLUDE_DIR})
ENDIF () ENDIF ()
IF (OPENSSL_FOUND) IF (OPENSSL_FOUND)
SET(GIT_OPENSSL 1) SET(GIT_OPENSSL 1)
SET(GIT_HTTPS 1) SET(GIT_HTTPS 1)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) LIST(APPEND LIBGIT2_INCLUDES ${OPENSSL_INCLUDE_DIR})
SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES}) LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES})
ENDIF() ENDIF()
...@@ -614,32 +621,31 @@ ELSE() ...@@ -614,32 +621,31 @@ ELSE()
ENDIF() ENDIF()
CONFIGURE_FILE(src/features.h.in git2/sys/features.h) CONFIGURE_FILE(src/features.h.in git2/sys/features.h)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
SET(GIT2INTERNAL_OBJECTS ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1}) SET(GIT2INTERNAL_OBJECTS ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1})
LIST(APPEND LIBGIT2_INCLUDES ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_SOURCE_DIR}/src" "${CMAKE_SOURCE_DIR}/include")
IF (CMAKE_VERSION VERSION_GREATER 2.8.7) IF (CMAKE_VERSION VERSION_GREATER 2.8.7)
ADD_LIBRARY(git2internal OBJECT ${GIT2INTERNAL_OBJECTS}) ADD_LIBRARY(git2internal OBJECT ${GIT2INTERNAL_OBJECTS})
IDE_SPLIT_SOURCES(git2internal) IDE_SPLIT_SOURCES(git2internal)
SET(GIT2INTERNAL_OBJECTS $<TARGET_OBJECTS:git2internal>) SET(GIT2INTERNAL_OBJECTS $<TARGET_OBJECTS:git2internal>)
IF (${CMAKE_VERSION} VERSION_LESS 2.8.12) IF (${CMAKE_VERSION} VERSION_LESS 2.8.12)
INCLUDE_DIRECTORIES(src include) INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
ELSE() ELSE()
TARGET_INCLUDE_DIRECTORIES(git2internal PRIVATE src PUBLIC include) TARGET_INCLUDE_DIRECTORIES(git2internal
PRIVATE ${LIBGIT2_INCLUDES}
PUBLIC ${CMAKE_SOURCE_DIR}/include)
ENDIF() ENDIF()
ELSE() ELSE()
INCLUDE_DIRECTORIES(src include) INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
ENDIF() ENDIF()
# Compile and link libgit2 # Compile and link libgit2
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
ADD_LIBRARY(git2 ${WIN_RC} ${GIT2INTERNAL_OBJECTS}) ADD_LIBRARY(git2 ${WIN_RC} ${GIT2INTERNAL_OBJECTS})
TARGET_LINK_LIBRARIES(git2 ${SECURITY_DIRS}) TARGET_LINK_LIBRARIES(git2 ${LIBGIT2_LIBS})
TARGET_LINK_LIBRARIES(git2 ${COREFOUNDATION_DIRS})
TARGET_LINK_LIBRARIES(git2 ${SSL_LIBRARIES})
TARGET_LINK_LIBRARIES(git2 ${SSH_LIBRARIES})
TARGET_LINK_LIBRARIES(git2 ${GSSAPI_LIBRARIES})
TARGET_LINK_LIBRARIES(git2 ${ICONV_LIBRARIES})
TARGET_OS_LIBRARIES(git2) TARGET_OS_LIBRARIES(git2)
# Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240) # Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240)
......
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
FILE(GLOB_RECURSE SRC_EXAMPLE_GIT2 network/*.c network/*.h) FILE(GLOB_RECURSE SRC_EXAMPLE_GIT2 network/*.c network/*.h)
ADD_EXECUTABLE(cgit2 ${SRC_EXAMPLE_GIT2}) ADD_EXECUTABLE(cgit2 ${SRC_EXAMPLE_GIT2})
IF(WIN32 OR ANDROID) IF(WIN32 OR ANDROID)
......
...@@ -30,6 +30,9 @@ SET_SOURCE_FILES_PROPERTIES( ...@@ -30,6 +30,9 @@ SET_SOURCE_FILES_PROPERTIES(
${CLAR_PATH}/clar.c ${CLAR_PATH}/clar.c
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite) PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
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} ${GIT2INTERNAL_OBJECTS})
SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
...@@ -38,13 +41,7 @@ IF (${CMAKE_VERSION} VERSION_GREATER 2.8.11) ...@@ -38,13 +41,7 @@ IF (${CMAKE_VERSION} VERSION_GREATER 2.8.11)
TARGET_INCLUDE_DIRECTORIES(libgit2_clar PRIVATE ../src PUBLIC ../include) TARGET_INCLUDE_DIRECTORIES(libgit2_clar PRIVATE ../src PUBLIC ../include)
ENDIF() ENDIF()
TARGET_LINK_LIBRARIES(libgit2_clar ${COREFOUNDATION_DIRS}) TARGET_LINK_LIBRARIES(libgit2_clar ${LIBGIT2_LIBS})
TARGET_LINK_LIBRARIES(libgit2_clar ${SECURITY_DIRS})
TARGET_LINK_LIBRARIES(libgit2_clar ${SSL_LIBRARIES})
TARGET_LINK_LIBRARIES(libgit2_clar ${SSH_LIBRARIES})
TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES})
TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES})
TARGET_OS_LIBRARIES(libgit2_clar)
IDE_SPLIT_SOURCES(libgit2_clar) IDE_SPLIT_SOURCES(libgit2_clar)
IF (MSVC_IDE) IF (MSVC_IDE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment