Commit fd2d11a17846530ba6907394fd63ada90feb5750

Carlos Martín Nieto 2015-06-28T13:57:06

CMake: treat the ld flags as a list These are treated as a list by CMake itself, which means that treating them as a simple string can put semicolons in our ld command-line if we have libraries which are not installed on the standard locations. Treat the variable as a CMake list and replace it with the space-delimited list just before writing it out to our pc file.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index eb56dfe..5c55ddd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -100,12 +100,14 @@ FUNCTION(TARGET_OS_LIBRARIES target)
 		TARGET_LINK_LIBRARIES(${target} ws2_32)
 	ELSEIF(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
 		TARGET_LINK_LIBRARIES(${target} socket nsl)
-		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lsocket -lnsl" PARENT_SCOPE)
+		LIST(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
+		SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
 	ENDIF()
 	CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_LIBRT)
 	IF(NEED_LIBRT)
 		TARGET_LINK_LIBRARIES(${target} rt)
-		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lrt" PARENT_SCOPE)
+		LIST(APPEND LIBGIT2_PC_LIBS "-lrt")
+		SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE)
 	ENDIF()
 
 	IF(THREADSAFE)
@@ -151,12 +153,12 @@ INCLUDE_DIRECTORIES(src include)
 
 IF (SECURITY_FOUND)
   MESSAGE("-- Found Security ${SECURITY_DIRS}")
-  SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -framework Security")
+  LIST(APPEND LIBGIT2_PC_LIBS "-framework Security")
 ENDIF()
 
 IF (COREFOUNDATION_FOUND)
   MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_DIRS}")
-  SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -framework CoreFoundation")
+  LIST(APPEND LIBGIT2_PC_LIBS "-framework CoreFoundation")
 ENDIF()
 
 
@@ -212,14 +214,14 @@ ELSE ()
 		ADD_DEFINITIONS(-DGIT_CURL)
 		INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
 		LINK_LIBRARIES(${CURL_LIBRARIES})
-		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${CURL_LDFLAGS}")
+		LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
 	ENDIF()
 
 	FIND_PACKAGE(HTTP_Parser)
 	IF (HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
 		INCLUDE_DIRECTORIES(${HTTP_PARSER_INCLUDE_DIRS})
 		LINK_LIBRARIES(${HTTP_PARSER_LIBRARIES})
-		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lhttp_parser")
+		LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
 	ELSE()
 		MESSAGE(STATUS "http-parser was not found or is too old; using bundled 3rd-party sources.")
 		INCLUDE_DIRECTORIES(deps/http-parser)
@@ -236,7 +238,7 @@ ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
 ELSEIF (OPENSSL_FOUND AND NOT SHA1_TYPE STREQUAL "builtin")
 	ADD_DEFINITIONS(-DOPENSSL_SHA1)
 	IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
-		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lssl")
+		LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
 	ELSE()
 		SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl")
 	ENDIF ()
@@ -261,7 +263,7 @@ IF (ZLIB_FOUND)
 	INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
 	LINK_LIBRARIES(${ZLIB_LIBRARIES})
 	IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
-		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lz")
+		LIST(APPEND LIBGIT2_PC_LIBS "-lz")
 	ELSE()
 		SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
 	ENDIF()
@@ -280,7 +282,8 @@ IF (LIBSSH2_FOUND)
 	ADD_DEFINITIONS(-DGIT_SSH)
 	INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIRS})
 	LINK_DIRECTORIES(${LIBSSH2_LIBRARY_DIRS})
-	SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${LIBSSH2_LDFLAGS}")
+	LIST(APPEND 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 "" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
@@ -306,7 +309,7 @@ ENDIF()
 IF (ICONV_FOUND)
 	ADD_DEFINITIONS(-DGIT_USE_ICONV)
 	INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
-	SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${ICONV_LIBRARIES}")
+	LIST(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
 ENDIF()
 
 # Platform specific compilation flags
@@ -511,6 +514,7 @@ IF (SONAME)
 		SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
 	ENDIF()
 ENDIF()
+STRING(REPLACE ";" " " LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS}")
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libgit2.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc @ONLY)
 
 IF (MSVC_IDE)