8000 Merge pull request #4642 from pks-t/pks/cmake-resolve-pkgconfig · libgit2/libgit2@f9cf9a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9cf9a0

Browse files
authored
Merge pull request #4642 from pks-t/pks/cmake-resolve-pkgconfig
cmake: resolve libraries found by pkg-config
2 parents 0a19c15 + 8ab470f commit f9cf9a0

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ INCLUDE(CheckFunctionExists)
2929
INCLUDE(CheckSymbolExists)
3030
INCLUDE(CheckStructHasMember)
3131
INCLUDE(AddCFlagIfSupported)
32-
INCLUDE(FindPkgConfig)
32+
INCLUDE(FindPkgLibraries)
3333
INCLUDE(FindThreads)
3434
INCLUDE(FindStatNsec)
3535
INCLUDE(IdeSplitSources)

cmake/Modules/FindPkgLibraries.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
INCLUDE(FindPkgConfig)
2+
3+
# This function will find and set up a pkg-config based module.
4+
# If a pc-file was found, it will resolve library paths to
5+
# absolute paths. Furthermore, the function will automatically
6+
# fall back to use static libraries in case no dynamic libraries
7+
# were found.
8+
FUNCTION(FIND_PKGLIBRARIES prefix package)
9+
PKG_CHECK_MODULES(${prefix} ${package})
10+
IF(NOT ${prefix}_FOUND)
11+
RETURN()
12+
ENDIF()
13+
14+
FOREACH(LIBRARY ${${prefix}_LIBRARIES})
15+
FIND_LIBRARY(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS})
16+
IF(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND")
17+
MESSAGE(FATAL_ERROR "could not resolve ${LIBRARY}")
18+
ENDIF()
19+
LIST(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED})
20+
ENDFOREACH(LIBRARY)
21+
22+
SET(${prefix}_FOUND 1 PARENT_SCOPE)
23+
SET(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE)
24+
SET(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE)
25+
SET(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE)
26+
27+
MESSAGE(STATUS " Resolved libraries: ${RESOLVED_LIBRARIES}")
28+
ENDFUNCTION()

examples/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
21
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
32

43
FILE(GLOB_RECURSE SRC_EXAMPLE_GIT2 network/*.c network/*.h common.?)

src/CMakeLists.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ SET(LIBGIT2_INCLUDES
1717
"${libgit2_SOURCE_DIR}/src"
1818
"${libgit2_SOURCE_DIR}/include")
1919
SET(LIBGIT2_LIBS "")
20-
SET(LIBGIT2_LIBDIRS "")
2120

2221
# Installation paths
2322
#
@@ -109,7 +108,6 @@ IF (WIN32 AND WINHTTP)
109108
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/winhttp" "${libgit2_BINARY_DIR}/deps/winhttp")
110109
LIST(APPEND LIBGIT2_LIBS winhttp)
111110
LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/winhttp")
112-
LIST(APPEND LIBGIT2_LIBDIRS ${LIBWINHTTP_PATH})
113111
ELSE()
114112
LIST(APPEND LIBGIT2_LIBS "winhttp")
115113
LIST(APPEND LIBGIT2_PC_LIBS "-lwinhttp")
@@ -119,13 +117,11 @@ IF (WIN32 AND WINHTTP)
119117
LIST(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32")
120118
ELSE ()
121119
IF (CURL)
122-
PKG_CHECK_MODULES(CURL libcurl)
120+
FIND_PKGLIBRARIES(CURL libcurl)
123121
ENDIF ()
124-
125122
IF (CURL_FOUND)
126123
SET(GIT_CURL 1)
127124
LIST(APPEND LIBGIT2_INCLUDES ${CURL_INCLUDE_DIRS})
128-
LIST(APPEND LIBGIT2_LIBDIRS ${CURL_LIBRARY_DIRS})
129125
LIST(APPEND LIBGIT2_LIBS ${CURL_LIBRARIES})
130126
LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
131127
ENDIF()
@@ -340,15 +336,13 @@ ENDIF()
340336

341337
# Optional external dependency: libssh2
342338
IF (USE_SSH)
343-
PKG_CHECK_MODULES(LIBSSH2 libssh2)
339+
FIND_PKGLIBRARIES(LIBSSH2 libssh2)
344340
ENDIF()
345341
IF (LIBSSH2_FOUND)
346342
SET(GIT_SSH 1)
347343
LIST(APPEND LIBGIT2_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
348344
LIST(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES})
349-
LIST(APPEND LIBGIT2_LIBDIRS ${LIBSSH2_LIBRARY_DIRS})
350345
LIST(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
351-
#SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${LIBSSH2_LDFLAGS}")
352346

353347
CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
354348
IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS)
@@ -462,7 +456,6 @@ ENDIF()
462456
SET(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
463457
SET(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
464458
SET(LIBGIT2_LIBS ${LIBGIT2_LIBS} PARENT_SCOPE)
465-
SET(LIBGIT2_LIBDIRS ${LIBGIT2_LIBDIRS} PARENT_SCOPE)
466459

467460
IF(XCODE_VERSION)
468461
# This is required for Xcode to actually link the libgit2 library
@@ -472,7 +465,6 @@ IF(XCODE_VERSION)
472465
ENDIF()
473466

474467
# Compile and link libgit2
475-
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
476468
ADD_LIBRARY(git2 ${WIN_RC} ${LIBGIT2_OBJECTS})
477469
TARGET_LINK_LIBRARIES(git2 ${LIBGIT2_LIBS})
478470

tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ SET_SOURCE_FILES_PROPERTIES(
3131
${CLAR_PATH}/clar.c
3232
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
3333

34-
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
3534
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
3635

3736
ADD_EXECUTABLE(libgit2_clar ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})

0 commit comments

Comments
 (0)
0