[vcpkg/scripts/pkgconfig] rewrite pkg-config check for libraries (#11550)

* [vcpkg/scripts/pkgconfig] rewrite pkgconfig check for libraries.

* [vcpkg/scripts/pkgconfig] fix more details.

* [vcpkg/scripts/pkgconfig] smaller improvements

* ws change to check functionallity of script for testing.

* [vcpkg/scripts/pkgconfig] update to latest test version

* Revert "ws change to check functionallity of script for testing."

This reverts commit 26269e9e776009230777d9390465715f2ebac465.

* [nettle] bump control for vcpkg_fixup_pkgconfig test

* [gmp] rerun CI to create new *.pc files

* [gmp/nettle] enable port debug

* [vcpkg/script/pkgconfig] fix path conversion regex for CI

* [CI|OSX] install pkg-config on osx

* [gmp/nettle] disable port debug

* [vcpkg/scripts/pkgconfig] update to latest version of x windows pr

* [zlib] add pkgconfig file

* [zstd] add fixup pkgconfig

* [libpng] add pc file installation

* [bzip2] install pc file and leave a TODO for somebody else ;)

* [bzip2] bump control

* [vcpkg/scripts/pkgconfig] skip checks if pkgconfig cannot be found.
- small bugfix in ignore flags regex

* retry zstd and zlib

* [libpng] retry by adding dl and m to system libraries for osx

* [libpng] add missing vcpkg_fixup_pkgconfig()

* [vcpkg/scripts/pkgconfig] unset var if found. 

fixes checks for other configurations which will be always succesful otherwise

* [libpng] bump control

* [libpng] enable port debug to debug osx regression

* ws change to retrigger osx ci and hopeing that it works

* fix typo

* [libpng] remove -lm flag on apple platforms

* ws change to rerun some ports in ci for good measure after the merge with master

* Re-trigger CI test

* [zstd] add pkgconfig

* [zstd] correct debug link

* [vcpkg/script/pkgconfig] - add more search suffixes for static libs
- add additional debug messages for debuging
- fix unsetting of cache variables hiding issues with debug libraries
- fixed pkgconfig fix in the debug case

* [pcre] add pthread dependency to pcre

* [protobuf] fix pkgconfig

* include quotes around the prefix in the case the prefix path was quoted (fixes some regressions)
add option NOT_STATIC_PKGCONFIG to run pkg-config without the --static argument

* [ignition-msgs5] get rid of a dev warning

* [apr] fix apr regression

* [protobuf] fix protobuf regression

* [sdl1] fix regression due to variable expansion of pkg-config. Use similar regex to the library removal for ignored flags.

* [ignition] fix regression

* remove changes of zlib portfile.

* reset changes in osx ci pipeline

* add DISABLE_PARALLEL_CONFIGURE

Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com>
Co-authored-by: JackBoosY <yuzaiyang@beyondsoft.com>
Co-authored-by: Billy Robert O'Neal <bion@microsoft.com>
This commit is contained in:
Alexander Neumann 2020-07-24 20:39:21 +02:00 committed by GitHub
parent 077c0746be
commit 458c20e94b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 420 additions and 184 deletions

View File

@ -1,5 +1,6 @@
Source: apr
Version: 1.7.0-1
Version: 1.7.0
Port-Version: 2
Homepage: https://apr.apache.org/
Description: The Apache Portable Runtime (APR) is a C library that forms a system portability layer that covers many operating systems.
Supports: !uwp

View File

@ -82,7 +82,7 @@ else()
vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/lib/pkgconfig/apr-1.pc
"-lapr-\${APR_MAJOR_VERSION}" "-lapr-1"
)
vcpkg_fixup_pkgconfig(SYSTEM_LIBRARIES pthread rt dl)
vcpkg_fixup_pkgconfig(SYSTEM_LIBRARIES pthread rt dl uuid crypt)
endif()
# Handle copyright

View File

@ -1,4 +1,4 @@
Source: bzip2
Version: 1.0.6-5
Version: 1.0.6-6
Homepage: http://www.bzip.org/
Description: High-quality data compressor.

11
ports/bzip2/bzip2.pc.in Normal file
View File

@ -0,0 +1,11 @@
prefix=@BZIP2_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Name: bzip2
Description: bzip2
Version: 1.0.6
Requires:
Libs: -L${libdir} -l@bzname@
Cflags: -I${includedir}

View File

@ -1,6 +1,6 @@
include(vcpkg_common_functions)
set(BZIP2_VERSION 1.0.6)
vcpkg_download_distfile(ARCHIVE
set(BZIP2_VERSION 1.0.6) # TODO: Update to 1.0.8
vcpkg_download_distfile(ARCHIVE # TODO: switch to vcpkg_from_git with https://sourceware.org/git/?p=bzip2.git;a=summary
URLS "https://github.com/past-due/bzip2-mirror/releases/download/v${BZIP2_VERSION}/bzip2-${BZIP2_VERSION}.tar.gz"
FILENAME "bzip2-${BZIP2_VERSION}.tar.gz"
SHA512 00ace5438cfa0c577e5f578d8a808613187eff5217c35164ffe044fbafdfec9e98f4192c02a7d67e01e5a5ccced630583ad1003c37697219b0f147343a3fdd12)
@ -14,7 +14,7 @@ vcpkg_extract_source_archive_ex(
fix-windows-include.patch
)
file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
@ -27,17 +27,25 @@ vcpkg_configure_cmake(
vcpkg_install_cmake()
vcpkg_copy_pdbs()
file(READ ${CURRENT_PACKAGES_DIR}/include/bzlib.h BZLIB_H)
file(READ "${CURRENT_PACKAGES_DIR}/include/bzlib.h" BZLIB_H)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
string(REPLACE "defined(BZ_IMPORT)" "0" BZLIB_H "${BZLIB_H}")
else()
string(REPLACE "defined(BZ_IMPORT)" "1" BZLIB_H "${BZLIB_H}")
endif()
file(WRITE ${CURRENT_PACKAGES_DIR}/include/bzlib.h "${BZLIB_H}")
file(WRITE "${CURRENT_PACKAGES_DIR}/include/bzlib.h" "${BZLIB_H}")
file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/bzip2)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/bzip2/LICENSE ${CURRENT_PACKAGES_DIR}/share/bzip2/copyright)
file(COPY "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/bzip2")
file(RENAME "${CURRENT_PACKAGES_DIR}/share/bzip2/LICENSE" "${CURRENT_PACKAGES_DIR}/share/bzip2/copyright")
file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})
file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_test_cmake(PACKAGE_NAME BZip2 MODULE)
set(BZIP2_PREFIX "${CURRENT_INSTALLED_DIR}")
set(bzname bz2)
configure_file("${CMAKE_CURRENT_LIST_DIR}/bzip2.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/bzip2.pc" @ONLY)
set(BZIP2_PREFIX "${CURRENT_INSTALLED_DIR}/debug")
set(bzname bz2d)
configure_file("${CMAKE_CURRENT_LIST_DIR}/bzip2.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/bzip2.pc" @ONLY)
vcpkg_fixup_pkgconfig()

View File

@ -1,5 +1,5 @@
Source: gmp
Version: 6.2.0-1
Version: 6.2.0-2
Homepage: https://gmplib.org/
Description: The GNU Multiple Precision Arithmetic Library
Build-Depends: vs-yasm (windows)

View File

@ -1,3 +1,4 @@
Source: ignition-modularscripts
Version: 2020-05-16
Port-Version: 1
Description: Vcpkg helpers to package ignition libraries

View File

@ -38,7 +38,10 @@ function(ignition_modular_build_library NAME MAJOR_VERSION SOURCE_PATH CMAKE_PAC
# Make pkg-config files relocatable
if(NOT IML_DISABLE_PKGCONFIG_INSTALL)
vcpkg_fixup_pkgconfig()
if(VCPKG_TARGET_IS_LINUX)
set(SYSTEM_LIBRARIES SYSTEM_LIBRARIES pthread)
endif()
vcpkg_fixup_pkgconfig(${SYSTEM_LIBRARIES})
else()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/lib/pkgconfig
${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig)

View File

@ -1,5 +1,6 @@
Source: ignition-msgs5
Version: 5.1.0
Port-Version: 1
Build-Depends: ignition-modularscripts, ignition-cmake2, ignition-math6, protobuf, tinyxml2
Description: Middleware protobuf messages for robotics
Supports: !(arm|linux|uwp)

View File

@ -17,4 +17,4 @@ ignition_modular_library(NAME msgs
"01-protobuf.patch")
# Restore old path
set(ENV{PATH} ${path_backup})
set(ENV{PATH} "${path_backup}")

View File

@ -1,5 +1,5 @@
Source: libpng
Version: 1.6.37-9
Version: 1.6.37-10
Build-Depends: zlib
Homepage: https://github.com/glennrp/libpng
Description: libpng is a library implementing an interface for reading and writing PNG (Portable Network Graphics) format files.

View File

@ -0,0 +1,47 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6f85d17ef..8de0eb299 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -814,20 +814,31 @@ endif()
# Only do this on Windows for Cygwin - the files don't make much sense outside
# of a UNIX look-alike.
if(NOT WIN32 OR CYGWIN OR MINGW)
- set(prefix ${CMAKE_INSTALL_PREFIX})
- set(exec_prefix ${CMAKE_INSTALL_PREFIX})
- set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
- set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
- set(LIBS "-lz -lm")
+ set(LIBS "-lz")
+ if(NOT APPLE)
+ string(APPEND LIBS " -lm")
+ endif()
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
- ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
- create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc)
-
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
- ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
create_symlink(libpng-config FILE ${PNGLIB_NAME}-config)
+else()
+ if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
+ set(LIBS "-lzlibd")
+ else()
+ set(LIBS "-lzlib")
+ endif()
endif()
+set(prefix ${CMAKE_INSTALL_PREFIX})
+set(exec_prefix ${CMAKE_INSTALL_PREFIX})
+set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
+set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
+create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
+
# SET UP LINKS
if(PNG_SHARED)
set_target_properties(png PROPERTIES

View File

@ -0,0 +1,24 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6599e1d7d..c0bb2fad2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -894,13 +894,13 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3)
install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5)
# Install pkg-config files
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
- DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
- DESTINATION bin)
+ DESTINATION tools/libpng)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
- DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
- DESTINATION bin)
+ DESTINATION tools/libpng)
endif()

View File

@ -14,16 +14,13 @@ if ("apng" IN_LIST FEATURES)
FILENAME "${LIBPNG_APG_PATCH_NAME}.gz"
SHA512 226adcb3a8c60f2267fe2976ab531329ae43c2603dab4d0cf8f16217d64069936b879f3d6516b75d259c47d6f5c5b1f24f887602206c8e46abde0fb7f5c7946b
)
vcpkg_find_acquire_program(7Z)
vcpkg_execute_required_process(
COMMAND ${7Z} x ${LIBPNG_APNG_PATCH_ARCHIVE} -aoa
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/src
LOGNAME extract-patch.log
)
endif()
set(APNG_EXTRA_PATCH ${LIBPNG_APG_PATCH_PATH})
set(LIBPNG_APNG_OPTION "-DPNG_PREFIX=a")
endif()
@ -37,6 +34,8 @@ vcpkg_from_github(
PATCHES
use_abort.patch
cmake.patch
pkgconfig.patch
pkgconfig.2.patch
${APNG_EXTRA_PATCH}
)
@ -62,6 +61,7 @@ vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
-DPNG_MAN_DIR=share/${PORT}/man
${LIBPNG_APNG_OPTION}
${LIBPNG_HARDWARE_OPTIMIZATIONS_OPTION}
${LD_VERSION_SCRIPT_OPTION}
@ -71,15 +71,51 @@ vcpkg_configure_cmake(
-DPNG_TESTS=OFF
-DSKIP_INSTALL_PROGRAMS=ON
-DSKIP_INSTALL_EXECUTABLES=ON
-DSKIP_INSTALL_FILES=ON
-DSKIP_INSTALL_FILES=OFF
OPTIONS_DEBUG
-DSKIP_INSTALL_HEADERS=ON
)
vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/libpng)
set(_file "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libpng16.pc")
if(EXISTS ${_file})
file(READ "${_file}" _contents)
if(VCPKG_TARGET_IS_WINDOWS)
string(REGEX REPLACE "-lpng16(d)?" "-llibpng16d" _contents "${_contents}")
else()
string(REGEX REPLACE "-lpng16(d)?" "-lpng16d" _contents "${_contents}")
endif()
string(REPLACE "-lzlib" "-lzlibd" _contents "${_contents}")
file(WRITE "${_file}" "${_contents}")
endif()
set(_file "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libpng.pc")
if(EXISTS ${_file})
file(READ "${_file}" _contents)
if(VCPKG_TARGET_IS_WINDOWS)
string(REGEX REPLACE "-lpng16(d)?" "-llibpng16d" _contents "${_contents}")
else()
string(REGEX REPLACE "-lpng16(d)?" "-lpng16d" _contents "${_contents}")
endif()
string(REPLACE "-lzlib" "-lzlibd" _contents "${_contents}")
file(WRITE "${_file}" "${_contents}")
endif()
if(VCPKG_TARGET_IS_WINDOWS)
set(_file "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libpng16.pc")
if(EXISTS ${_file})
file(READ "${_file}" _contents)
string(REPLACE "-lpng16" "-llibpng16" _contents "${_contents}")
file(WRITE "${_file}" "${_contents}")
endif()
set(_file "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libpng.pc")
if(EXISTS ${_file})
file(READ "${_file}" _contents)
string(REPLACE "-lpng16" "-llibpng16" _contents "${_contents}")
file(WRITE "${_file}" "${_contents}")
endif()
endif()
vcpkg_fixup_pkgconfig()
vcpkg_copy_pdbs()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

View File

@ -1,5 +1,5 @@
Source: nettle
Version: 3.5.1-1
Version: 3.5.1-2
Homepage: https://git.lysator.liu.se/nettle/nettle
Description: Nettle is a low-level cryptographic library that is designed to fit easily in more or less any context: In crypto toolkits for object-oriented languages (C++, Python, Pike, ...), in applications like LSH or GNUPG, or even in kernel space.
Build-Depends: gmp, vs-yasm (windows)

View File

@ -1,5 +1,6 @@
Source: ompl
Version: 1.4.2-4
Version: 1.4.2
Port-Version: 5
Homepage: https://bitbucket.org/ompl
Description: The Open Motion Planning Library, consists of many state-of-the-art sampling-based motion planning algorithms
Build-Depends: boost-dynamic-bitset, boost-filesystem, boost-graph, boost-odeint, boost-program-options, boost-serialization, boost-system, boost-test, boost-ublas, boost-timer, eigen3

View File

@ -29,6 +29,7 @@ file(WRITE ${SOURCE_PATH}/CMakeLists.txt "${_contents}")
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
DISABLE_PARALLEL_CONFIGURE
OPTIONS
-DOMPL_VERSIONED_INSTALL=OFF
-DOMPL_REGISTRATION=OFF

View File

@ -1,5 +1,5 @@
Source: pcre
Version: 8.44
Port-Version: 5
Port-Version: 6
Homepage: https://www.pcre.org/
Description: Perl Compatible Regular Expressions

View File

@ -110,7 +110,7 @@ if(VCPKG_TARGET_IS_WINDOWS)
file(WRITE ${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libpcreposix.pc ${LIBPCREPOSIX.PC})
endif()
vcpkg_fixup_pkgconfig()
vcpkg_fixup_pkgconfig(SYSTEM_LIBRARIES pthread)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)

View File

@ -1,5 +1,6 @@
Source: protobuf
Version: 3.12.3
Port-Version: 1
Homepage: https://github.com/google/protobuf
Description: Protocol Buffers - Google's data interchange format

View File

@ -122,3 +122,15 @@ endif()
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
vcpkg_copy_pdbs()
set(packages protobuf protobuf-lite)
foreach(_package IN LISTS packages)
set(_file ${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/${_package}.pc)
if(EXISTS "${_file}")
vcpkg_replace_string(${_file} "-l${_package}" "-l${_package}d")
endif()
endforeach()
if(NOT VCPKG_TARGET_IS_WINDOWS)
set(SYSTEM_LIBRARIES SYSTEM_LIBRARIES pthread)
endif()
vcpkg_fixup_pkgconfig(${SYSTEM_LIBRARIES})

View File

@ -1,4 +1,5 @@
Source: sdl1
Version: 1.2.15-11
Version: 1.2.15
Port-Version: 12
Homepage: https://www.libsdl.org
Description: Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.

View File

@ -58,7 +58,9 @@ else()
)
vcpkg_install_make()
vcpkg_fixup_pkgconfig(IGNORE_FLAGS -Wl,-rpath,\${libdir} SYSTEM_LIBRARIES -lm -ldl -lpthread)
vcpkg_fixup_pkgconfig(IGNORE_FLAGS -Wl,-rpath,${CURRENT_PACKAGES_DIR}/lib/pkgconfig/../../lib
-Wl,-rpath,${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/../../lib
SYSTEM_LIBRARIES pthread)
file(GLOB SDL1_TOOLS "${CURRENT_PACKAGES_DIR}/bin/*")
foreach (SDL1_TOOL ${SDL1_TOOLS})

View File

@ -129,5 +129,5 @@ endif()
# Windows system libs
if(VCPKG_TARGET_IS_WINDOWS)
list(APPEND VCPKG_SYSTEM_LIBRARIES wsock32)
list(APPEND VCPKG_SYSTEM_LIBRARIES ws2_32)
list(APPEND VCPKG_SYSTEM_LIBRARIES Ws2_32)
endif()

View File

@ -8,6 +8,8 @@
## [RELEASE_FILES <PATHS>...]
## [DEBUG_FILES <PATHS>...]
## [SYSTEM_LIBRARIES <NAMES>...]
## [IGNORE_FLAGS <FLAGS>]
## [SKIP_CHECK]
## )
## ```
##
@ -20,10 +22,6 @@
## Specifies a list of files to apply the fixes for debug paths.
## Defaults to every *.pc file in the folder ${CURRENT_PACKAGES_DIR}/debug/
##
## ### SYSTEM_PACKAGES
## If the *.pc file contains system packages outside vcpkg these need to be listed here.
## Since vcpkg checks the existence of all required packages within vcpkg.
##
## ### SYSTEM_LIBRARIES
## If the *.pc file contains system libraries outside vcpkg these need to be listed here.
## VCPKG checks every -l flag for the existence of the required library within vcpkg.
@ -31,172 +29,237 @@
## ### IGNORE_FLAGS
## If the *.pc file contains flags in the lib field which are not libraries. These can be listed here
##
## ### SKIP_CHECK
## Skips the library checks in vcpkg_fixup_pkgconfig. Only use if the script itself has unhandled cases.
##
## ## Notes
## Still work in progress. If there are more cases which can be handled here feel free to add them
##
## ## Examples
##
## Just call vcpkg_fixup_pkgconfig() after any install step which installs *.pc files.
function(vcpkg_fixup_pkgconfig_check_libraries _config _contents_var _system_libs _system_packages _ignore_flags)
set(CMAKE_FIND_LIBRARY_SUFFIXES_BACKUP ${CMAKE_FIND_LIBRARY_SUFFIXES})
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll.a;.a")
#message(STATUS "Checking configuration: ${_config}")
function(vcpkg_fixup_pkgconfig_check_files pkg_cfg_cmd _file _config _system_libs _ignore_flags)
# Setup pkg-config paths
if(CMAKE_HOST_WIN32)
# Those replacements are probably only necessary since we use pkg-config from msys
string(REPLACE " " "\ " _VCPKG_INSTALLED_PKGCONF "${CURRENT_INSTALLED_DIR}")
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_INSTALLED_PKGCONF "${_VCPKG_INSTALLED_PKGCONF}")
string(REPLACE "\\" "/" _VCPKG_INSTALLED_PKGCONF "${_VCPKG_INSTALLED_PKGCONF}")
string(REPLACE " " "\ " _VCPKG_PACKAGES_PKGCONF "${CURRENT_PACKAGES_DIR}")
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_PACKAGES_PKGCONF "${_VCPKG_PACKAGES_PKGCONF}")
string(REPLACE "\\" "/" _VCPKG_PACKAGES_PKGCONF "${_VCPKG_PACKAGES_PKGCONF}")
else()
set(_VCPKG_INSTALLED_PKGCONF "${CURRENT_INSTALLED_DIR}")
set(_VCPKG_PACKAGES_PKGCONF "${CURRENT_PACKAGES_DIR}")
endif()
set(PATH_SUFFIX_DEBUG /debug)
set(PKGCONFIG_INSTALLED_DIR "${_VCPKG_INSTALLED_PKGCONF}${PATH_SUFFIX_${_config}}/lib/pkgconfig")
set(PKGCONFIG_INSTALLED_SHARE_DIR "${_VCPKG_INSTALLED_PKGCONF}/share/pkgconfig")
set(PKGCONFIG_PACKAGES_DIR "${_VCPKG_PACKAGES_PKGCONF}${PATH_SUFFIX_${_config}}/lib/pkgconfig")
set(PKGCONFIG_PACKAGES_SHARE_DIR "${_VCPKG_PACKAGES_PKGCONF}/share/pkgconfig")
if(ENV{PKG_CONFIG_PATH})
set(BACKUP_ENV_PKG_CONFIG_PATH_${_config} $ENV{PKG_CONFIG_PATH})
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}:${PKGCONFIG_INSTALLED_SHARE_DIR}:${PKGCONFIG_PACKAGES_DIR}:${PKGCONFIG_PACKAGES_SHARE_DIR}:$ENV{PKG_CONFIG_PATH}")
else()
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}:${PKGCONFIG_INSTALLED_SHARE_DIR}:${PKGCONFIG_PACKAGES_DIR}:${PKGCONFIG_PACKAGES_SHARE_DIR}")
endif()
# First make sure everything is ok with the package and its deps
get_filename_component(_package_name "${_file}" NAME_WLE)
debug_message("Checking package (${_config}): ${_package_name}")
execute_process(COMMAND "${pkg_cfg_cmd}" --print-errors --exists ${_package_name}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
RESULT_VARIABLE _pkg_error_var
OUTPUT_VARIABLE _pkg_output
ERROR_VARIABLE _pkg_error_out
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _pkg_error_var EQUAL 0)
message(STATUS "pkg_cfg_cmd call with:${pkg_cfg_cmd} --exists ${_package_name} failed")
message(STATUS "ENV{PKG_CONFIG_PATH}:$ENV{PKG_CONFIG_PATH}")
message(STATUS "pkg-config call failed with error code:${_pkg_error_var}")
message(STATUS "pkg-config output:${_pkg_output}")
message(FATAL_ERROR "pkg-config error output:${_pkg_error_out}")
else()
debug_message("pkg-config returned:${_pkg_error_var}")
debug_message("pkg-config output:${_pkg_output}")
debug_message("pkg-config error output:${_pkg_error_out}")
endif()
# Get all required libs. --static means we get all libraries required for static linkage
# which is the worst case and includes the case without --static
# This retests already tested *.pc files since pkg-config will recursivly search for
# required packages and add there link flags to the one being tested
# as such NOT_STATIC_PKGCONFIG might be used to deactivate the --static arg to pkg-config
execute_process(COMMAND "${pkg_cfg_cmd}" --print-errors ${PKGCONFIG_STATIC} --libs ${_package_name}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
RESULT_VARIABLE _pkg_error_var
OUTPUT_VARIABLE _pkg_libs_output
ERROR_VARIABLE _pkg_error_out
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _pkg_error_var EQUAL 0)
message(STATUS "pkg_cfg_cmd call with:${pkg_cfg_cmd} --libs ${_package_name} failed")
message(STATUS "pkg-config call failed with error code:${_pkg_error_var}")
message(STATUS "pkg-config output:${_pkg_libs_output}")
message(FATAL_ERROR "pkg-config error output:${_pkg_error_out}")
else()
debug_message("pkg-config returned:${_pkg_error_var}")
debug_message("pkg-config output:${_pkg_libs_output}")
debug_message("pkg-config error output:${_pkg_error_out}")
endif()
execute_process(COMMAND "${pkg_cfg_cmd}" --print-errors --static --libs-only-L ${_package_name}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
RESULT_VARIABLE _pkg_error_var
OUTPUT_VARIABLE _pkg_lib_paths_output
ERROR_VARIABLE _pkg_error_out
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _pkg_error_var EQUAL 0)
message(STATUS "pkg_cfg_cmd call with:${pkg_cfg_cmd} --libs-only-L ${_package_name} failed")
message(STATUS "pkg-config call failed with error code:${_pkg_error_var}")
message(STATUS "pkg-config output:${_pkg_lib_paths_output}")
message(FATAL_ERROR "pkg-config error output:${_pkg_error_out}")
else()
debug_message("pkg-config returned:${_pkg_error_var}")
debug_message("pkg-config output:${_pkg_lib_paths_output}")
debug_message("pkg-config error output:${_pkg_error_out}")
endif()
string(REPLACE "\\ " "##" _pkg_lib_paths_output "${_pkg_lib_paths_output}") # Whitespace path protection
string(REGEX REPLACE "(^[\t ]*|[\t ]+)-L" ";" _pkg_lib_paths_output "${_pkg_lib_paths_output}")
debug_message("-L LIST TRANSFORMATION:'${_pkg_lib_paths_output}'")
string(REGEX REPLACE "^[\t ]*;" "" _pkg_lib_paths_output "${_pkg_lib_paths_output}")
string(REPLACE "##" "\\ " _pkg_lib_paths_output "${_pkg_lib_paths_output}")
list(REMOVE_DUPLICATES _pkg_lib_paths_output) # We don't care about linker order and repeats
## Remove search paths from LIBS
foreach(_search_path IN LISTS _pkg_lib_paths_output)
debug_message("REMOVING:'${_search_path}'")
debug_message("FROM:'${_pkg_libs_output}'")
string(REGEX REPLACE "(^[\t ]*|[\t ]+|;[\t ]*)-L${_search_path}([\t ]+|[\t ]*$)" ";" _pkg_libs_output "${_pkg_libs_output}") # Remove search paths from libs
endforeach()
debug_message("LIBS AFTER -L<path> REMOVAL:'${_pkg_libs_output}'")
#Make the remaining libs a proper CMake List
string(REPLACE "\\ " "##" _pkg_libs_output "${_pkg_libs_output}") # Whitespace path protection
string(REGEX REPLACE "(^[\t ]*|[\t ]+)-l" ";-l" _pkg_libs_output "${_pkg_libs_output}")
string(REGEX REPLACE "[\t ]*(-pthreads?)" ";\\1" _pkg_libs_output "${_pkg_libs_output}") # handle pthread without -l here (makes a lot of problems otherwise)
string(REGEX REPLACE "^[\t ]*;[\t ]*" "" _pkg_libs_output "${_pkg_libs_output}")
string(REPLACE "##" "\\ " _pkg_libs_output "${_pkg_libs_output}")
#Windows path transformations
if(CMAKE_HOST_WIN32)
string(REGEX REPLACE "(^|;)/([a-zA-Z])/" "\\1\\2:/" _pkg_lib_paths_output "${_pkg_lib_paths_output}")
string(REGEX REPLACE " /([a-zA-Z])/" ";\\1:/" _pkg_libs_output "${_pkg_libs_output}")
string(REGEX REPLACE "-l/([a-zA-Z])/" "-l\\1:/" _pkg_libs_output "${_pkg_libs_output}")
debug_message("pkg-config output lib paths after replacement (cmake style):${_pkg_lib_paths_output}")
debug_message("pkg-config output lib after replacement (cmake style):${_pkg_libs_output}")
endif()
if("${_config}" STREQUAL "DEBUG")
set(prefix "${CURRENT_INSTALLED_DIR}/debug/")
set(libprefix "${CURRENT_INSTALLED_DIR}/debug/lib/")
set(installprefix "${CURRENT_PACKAGES_DIR}/debug/")
set(installlibprefix "${CURRENT_PACKAGES_DIR}/debug/lib/")
set(lib_suffixes d _d _debug)
set(lib_suffixes d _d _debug -s -sd _s _sd -static -staticd _static _staticd)
elseif("${_config}" STREQUAL "RELEASE")
set(prefix "${CURRENT_INSTALLED_DIR}")
set(libprefix "${CURRENT_INSTALLED_DIR}/lib/")
set(installprefix "${CURRENT_PACKAGES_DIR}/")
set(installlibprefix "${CURRENT_PACKAGES_DIR}/lib/")
set(lib_suffixes "")
set(lib_suffixes -s _s -static _static)
else()
message(FATAL_ERROR "Unknown configuration in vcpkg_fixup_pkgconfig_check_libraries!")
endif()
debug_message("Default library search paths: ${libprefix} --- ${installlibprefix} --- ${PKG_LIB_SEARCH_PATH}")
set(_contents "${${_contents_var}}")
#message(STATUS "Contents: ${_contents}")
set(_system_lib_normalized)
foreach(_system_lib ${_system_libs})
string(REPLACE "-l" "" _system_lib "${_system_lib}")
list(APPEND _system_lib_normalized "${_system_lib}")
debug_message("IGNORED FLAGS:'${_ignore_flags}'")
debug_message("BEFORE IGNORE FLAGS REMOVAL: ${_pkg_libs_output}")
foreach(_ignore IN LISTS _ignore_flags) # Remove ignore with whitespace
debug_message("REMOVING FLAG:'${_ignore}'")
string(REGEX REPLACE "(^[\t ]*|;[\t ]*|[\t ]+)${_ignore}([\t ]+|[\t ]*;|[\t ]*$)" "\\2" _pkg_libs_output "${_pkg_libs_output}")
debug_message("AFTER REMOVAL: ${_pkg_libs_output}")
endforeach()
## Extra libraries:
string(REGEX MATCH "Libs:[^\n#]+" _libs "${_contents}")
#message(STATUS "LIB LINE: ${_libs}")
# The path to the library is either quoted and can not contain a quote or it is unqouted and cannot contain a single unescaped space
string(REGEX REPLACE "Libs:" "" _libs_list_tmp "${_libs}")
string(REGEX REPLACE [[[\t ]+(-(l|L)?("[^"]+"|(\\ |[^ ]+)+))]] ";\\1" _libs_list_tmp "${_libs_list_tmp}")
string(REGEX REPLACE ";?[\t ]*;[\t ]*" ";" _pkg_libs_output "${_pkg_libs_output}") # Double ;; and Whitespace before/after ; removal
string(REGEX MATCH "Libs.private:[^\n#]+" _libs_private "${_contents}")
string(REGEX REPLACE "Libs.private:" "" _libs_private_list_tmp "${_libs_private}")
string(REGEX REPLACE [[[\t ]+(-(l|L)?("[^"]+"|(\\ |[^ ]+)+))]] ";\\1" _libs_private_list_tmp "${_libs_private_list_tmp}")
#message(STATUS "Found libraries: ${_libs_list_tmp}")
#message(STATUS "Found private libraries: ${_libs_private_list_tmp}")
list(APPEND _all_libs "${_libs_list_tmp}" "${_libs_private_list_tmp}")
list(REMOVE_DUPLICATES _all_libs)
foreach(_lib ${_all_libs})
string(REGEX REPLACE "(^[\t ]+|[\t ]+$)" "" _lib "${_lib}") # Remove whitespaces at begin & end
if( "x${_lib}x" STREQUAL "xx") #Empty String
continue()
endif()
unset(CHECK_LIB CACHE)
unset(NO_CHECK_LIB)
#message(STATUS "CHECKING: x${_lib}z")
if("${_lib}" MATCHES "^-L((\\ |[^ ]+)+)$")
debug_message("Search path for libraries (unused): ${CMAKE_MATCH_1}") # not used yet we assume everything can be found in libprefix
continue()
elseif("${_lib}" MATCHES [[^-l("[^"]+"|(\\ |[^ ]+)+)$]] )
set(_libname ${CMAKE_MATCH_1})
debug_message("Searching for library: ${_libname}")
#debug_message("System libraries: ${_system_libs}")
foreach(_system_lib ${_system_libs})
string(REPLACE "^[\t ]*-l" "" _libname_norm "${_libname}")
string(REGEX REPLACE "[\t ]+$" "" _libname_norm "${_libname_norm}")
#debug_message("${_libname_norm} vs ${_system_lib}")
if("${_libname_norm}" MATCHES "${_system_lib}" OR "-l${_libname_norm}" MATCHES "${_system_lib}")
set(NO_CHECK_LIB ON)
debug_message("${_libname} is SYSTEM_LIBRARY")
break()
endif()
debug_message("SYSTEM LIBRARIES:'${_system_libs}'")
debug_message("LIBRARIES in PC:'${_pkg_libs_output}'")
foreach(_system_lib IN LISTS _system_libs) # Remove system libs with whitespace
debug_message("REMOVING:'${_system_lib}'")
debug_message("FROM:'${_pkg_libs_output}'")
string(REGEX REPLACE "(^[\t ]*|;[\t ]*|[\t ]+)(-l?)${_system_lib}([\t ]+|[\t ]*;|[\t ]*$)" "\\3" _pkg_libs_output "${_pkg_libs_output}")
string(REGEX REPLACE "(^[\t ]*|;[\t ]*|[\t ]+)${_system_lib}([\t ]+|[\t ]*;|[\t ]*$)" "\\2" _pkg_libs_output "${_pkg_libs_output}")
string(TOLOWER "${_system_lib}" _system_lib_lower)
string(REGEX REPLACE "(^[\t ]*|;[\t ]*|[\t ]+)(-l?)${_system_lib_lower}([\t ]+|[\t ]*;|[\t ]*$)" "\\3" _pkg_libs_output "${_pkg_libs_output}")
string(REGEX REPLACE "(^[\t ]*|;[\t ]*|[\t ]+)${_system_lib_lower}([\t ]+|[\t ]*;|[\t ]*$)" "\\2" _pkg_libs_output "${_pkg_libs_output}")
debug_message("AFTER REMOVAL:'${_pkg_libs_output}'")
endforeach()
if(NO_CHECK_LIB)
break()
list(REMOVE_DUPLICATES _pkg_libs_output) # We don't care about linker order and repeats
string(REGEX REPLACE ";?[\t ]*;[\t ]*" ";" _pkg_libs_output "${_pkg_libs_output}") # Double ;; and Whitespace before/after ; removal
debug_message("Library search paths:${_pkg_lib_paths_output}")
debug_message("Libraries to search:${_pkg_libs_output}")
set(CMAKE_FIND_LIBRARY_SUFFIXES_BACKUP ${CMAKE_FIND_LIBRARY_SUFFIXES})
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a)
foreach(_lib IN LISTS _pkg_libs_output)
if(EXISTS "${_lib}" OR "x${_lib}x" STREQUAL "xx" ) # eat; all ok _lib is a fullpath to a library or empty
continue()
elseif (_lib MATCHES "^-l(.+)$")
debug_message("Library match: CMAKE_MATCH_1:${CMAKE_MATCH_1}")
set(_libname "${CMAKE_MATCH_1}")
if(EXISTS "${_libname}")
debug_message("${_libname} detected as an existing full path!")
continue() # fullpath in -l argument and exists; all ok
endif()
#debug_message("Searching for library ${_libname} in ${libprefix}")
if(EXISTS "${_libname}") #full path
set(CHECK_LIB_${_libname} "${_libname}" CACHE INTERNAL FORCE)
debug_message("CHECK_LIB_${_libname}_${_config} before: ${CHECK_LIB_${_libname}_${_config}}")
find_library(CHECK_LIB_${_libname}_${_config} NAMES ${_libname} PATHS ${_pkg_lib_paths_output} "${CURRENT_INSTALLED_DIR}${PATH_SUFFIX_${_config}}/lib" NO_DEFAULT_PATH)
debug_message("CHECK_LIB_${_libname}_${_config} after: ${CHECK_LIB_${_libname}_${_config}}")
if(CHECK_LIB_${_libname}_${_config})
unset(CHECK_LIB_${_libname}_${_config} CACHE) # need to unset or else other configurations will not check correctly
debug_message("CHECK_LIB_${_libname}_${_config} after unset: ${CHECK_LIB_${_libname}_${_config}}")
continue() # found library; all ok
endif()
find_library(CHECK_LIB_${_libname} NAMES "${_libname}" PATHS "${libprefix}" "${installlibprefix}" "${PKG_LIB_SEARCH_PATH}" NO_DEFAULT_PATH)
if(NOT CHECK_LIB_${_libname} AND "${_config}" STREQUAL "DEBUG")
#message(STATUS "Unable to locate ${_libname}. Trying with debug suffix")
foreach(_lib_suffix ${lib_suffixes})
debug_message("Searching with additional suffixes: '${lib_suffixes}'")
foreach(_lib_suffix IN LISTS lib_suffixes)
string(REPLACE ".dll.a|.a|.lib|.so" "" _name_without_extension "${_libname}")
find_library(CHECK_LIB_${_libname} NAMES ${_name_without_extension}${_lib_suffix} PATHS "${libprefix}" "${installlibprefix}" "${PKG_LIB_SEARCH_PATH}")
if(CHECK_LIB_${_libname})
message(FATAL_ERROR "Found ${CHECK_LIB_${_libname}} with additional debug suffix! Please correct the *.pc file!")
string(REGEX REPLACE "(-l${_name_without_extension})(\.dll\.a|\.a|\.lib|\.so)" "\\1${_lib_suffix}\\2" _contents ${_contents})
set(search_name ${_name_without_extension}${_lib_suffix})
debug_message("Search name: '${search_name}'")
debug_message("CHECK_LIB_${search_name}_${_config} before: ${CHECK_LIB_${search_name}_${_config}}")
debug_message("Search paths:'${_pkg_lib_paths_output}' '${CURRENT_INSTALLED_DIR}${PATH_SUFFIX_${_config}}/lib'")
find_library(CHECK_LIB_${search_name}_${_config} NAMES ${search_name} PATHS ${_pkg_lib_paths_output} "${CURRENT_INSTALLED_DIR}${PATH_SUFFIX_${_config}}/lib" NO_DEFAULT_PATH)
debug_message("CHECK_LIB_${search_name}_${_config} after: ${CHECK_LIB_${search_name}_${_config}}")
if(CHECK_LIB_${search_name}_${_config})
message(FATAL_ERROR "Found ${CHECK_LIB_${search_name}_${_config}} with additional '${_lib_suffix}' suffix! Please correct the *.pc file!")
unset(CHECK_LIB_${search_name}_${_config} CACHE) # need to unset or else other configurations will not check correctly
endif()
endforeach()
if(NOT CHECK_LIB_${_libname})
message(FATAL_ERROR "Library ${_libname} was not found! If it is a system library use the SYSTEM_LIBRARIES parameter for the vcpkg_fixup_pkgconfig call! Otherwise, corret the *.pc file")
endif()
elseif(NOT CHECK_LIB_${_libname})
message(FATAL_ERROR "Library ${_libname} was not found! If it is a system library use the SYSTEM_LIBRARIES parameter for the vcpkg_fixup_pkgconfig call! Otherwise, corret the *.pc file")
# Reaching here means error!
message(STATUS "CHECK_LIB_${_libname}_${_config}:${CHECK_LIB_${_libname}_${_config}}")
message(FATAL_ERROR "Library \"${_libname}\" was not found! If it is a system library use the SYSTEM_LIBRARIES parameter for the vcpkg_fixup_pkgconfig call! Otherwise, correct the *.pc file")
else ()
debug_message("Found ${_libname} at ${CHECK_LIB_${_libname}}")
message(FATAL_ERROR "Unhandled string \"${_lib}\" was found! If it is a system library use the SYSTEM_LIBRARIES parameter for the vcpkg_fixup_pkgconfig call! Otherwise, correct the *.pc file or add the case to vcpkg_fixup_pkgconfig")
endif()
else()
#handle special cases
if(_lib STREQUAL "-pthread" OR _lib STREQUAL "-pthreads")
# Replace with VCPKG version?
#VCPKG should probably rename one of the pthread versions to avoid linking against system pthread?
# set(PTHREAD_SUFFIX )
# if("${_config}" STREQUAL "DEBUG")
# file(GLOB PTHREAD_LIB "${CURRENT_INSTALLED_DIR}/debug/lib/${VCPKG_TARGET_STATIC_LIBRARY_PREFIX}pthread*C3d.*")
# elseif("${_config}" STREQUAL "RELEASE")
# file(GLOB PTHREAD_LIB "${CURRENT_INSTALLED_DIR}/lib/${VCPKG_TARGET_STATIC_LIBRARY_PREFIX}pthread*C3.*")
# endif()
# get_filename_component(PTHREAD_LIB "${PTHREAD_LIB}" NAME_WE)
# string(REPLACE "Libs: -pthread" "Libs: -L\${libdir} -l${PTHREAD_LIB}" _contents ${_contents})
elseif(_lib STREQUAL _ignore_flags)
message(STATUS "${_lib} found in *.pc file and ignored!")
else()
message(FATAL_ERROR "Found ${_lib} and no rule to analyse the flag! Please check the *.pc file")
endif()
endif()
unset(CHECK_LIB_${_libname} CACHE)
unset(NO_CHECK_LIB)
endforeach()
## Packages:
string(REGEX MATCH "Requires:[^\n#]+" _pkg_list_tmp "${_contents}")
string(REGEX REPLACE "Requires:[\t ]" "" _pkg_list_tmp "${_pkg_list_tmp}")
string(REGEX REPLACE "[\t ]*,[\t ]*" ";" _pkg_list_tmp "${_pkg_list_tmp}")
string(REGEX REPLACE "[\t ]*(>|=)+[\t ]*([0-9]+|\\.)+" "" _pkg_list_tmp "${_pkg_list_tmp}")
string(REGEX REPLACE " " ";" _pkg_list_tmp "${_pkg_list_tmp}")
string(REGEX MATCH "Requires.private:[^\n#]+" _pkg_private_list_tmp "${_contents}")
string(REGEX REPLACE "Requires.private:[\t ]" "" _pkg_private_list_tmp "${_pkg_private_list_tmp}")
string(REGEX REPLACE "[\t ]*,[\t ]*" ";" _pkg_private_list_tmp "${_pkg_private_list_tmp}")
string(REGEX REPLACE "[\t ]*(>|=)+[\t ]*([0-9]+|\\.)+" " " _pkg_private_list_tmp "${_pkg_private_list_tmp}")
string(REGEX REPLACE "[\t ]+" ";" _pkg_private_list_tmp "${_pkg_private_list_tmp}")
debug_message("Required packages: ${_pkg_list_tmp}")
debug_message("Required private packages: ${_pkg_private_list_tmp}")
#message(STATUS "System packages: ${_system_packages}")
foreach(_package ${_pkg_list_tmp} ${_pkg_private_list_tmp})
debug_message("Searching for package: ${_package}")
set(PKG_CHECK ON)
if(NOT "${_system_packages}" STREQUAL "")
#message(STATUS "Checking ${_package} for SYSTEM PACKAGE: ${_system_packages}")
if("${_system_packages}" MATCHES "${_package}" )
debug_message("Package ${_package} is SYSTEM PACKAGE!")
set(PKG_CHECK OFF)
endif()
endif()
if(PKG_CHECK AND NOT (EXISTS "${libprefix}/pkgconfig/${_package}.pc" OR EXISTS "${installlibprefix}/pkgconfig/${_package}.pc" OR EXISTS "${PKG_LIB_SEARCH_PATH}/pkgconfig/${_package}.pc"))
message(FATAL_ERROR "Package ${_package} not found! If it is a system package add it to the SYSTEM_PACKAGES parameter for the vcpkg_fixup_pkgconfig call! Otherwise, corret the *.pc file")
else()
debug_message("Found package ${_package}!")
endif()
endforeach()
## Push modifications up in scope
set(${_contents_var} "${_contents}" PARENT_SCOPE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BACKUP})
endfunction()
function(vcpkg_fixup_pkgconfig)
cmake_parse_arguments(_vfpkg "" "" "RELEASE_FILES;DEBUG_FILES;SYSTEM_LIBRARIES;SYSTEM_PACKAGES;IGNORE_FLAGS" ${ARGN})
cmake_parse_arguments(_vfpkg "SKIP_CHECK;NOT_STATIC_PKGCONFIG" "" "RELEASE_FILES;DEBUG_FILES;SYSTEM_LIBRARIES;SYSTEM_PACKAGES;IGNORE_FLAGS" ${ARGN})
# Note about SYSTEM_PACKAGES: pkg-config requires all packages mentioned in pc files to exists. Otherwise pkg-config will fail to find the pkg.
# As such naming any SYSTEM_PACKAGES is damned to fail which is why it is not mentioned in the docs at the beginning.
if(VCPKG_SYSTEM_LIBRARIES)
list(APPEND _vfpkg_SYSTEM_LIBRARIES ${VCPKG_SYSTEM_LIBRARIES})
endif()
if(_vfpkg_NOT_STATIC_PKGCONFIG)
set(PKGCONFIG_STATIC)
else()
set(PKGCONFIG_STATIC --static)
endif()
message(STATUS "Fixing pkgconfig")
if(_vfpkg_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "vcpkg_fixup_pkgconfig was passed extra arguments: ${_vfct_UNPARSED_ARGUMENTS}")
@ -212,6 +275,19 @@ function(vcpkg_fixup_pkgconfig)
list(FILTER _vfpkg_DEBUG_FILES INCLUDE REGEX "${CURRENT_PACKAGES_DIR}/debug/")
endif()
if(NOT PKGCONFIG)
find_program(PKGCONFIG pkg-config PATHS "bin" "/usr/bin" "/usr/local/Cellar/pkg-config/0.29.2_3" REQUIRED)
if(NOT PKGCONFIG AND CMAKE_HOST_WIN32)
vcpkg_acquire_msys(MSYS_ROOT PACKAGES pkg-config)
find_program(PKGCONFIG pkg-config PATHS "${MSYS_ROOT}/usr/bin" REQUIRED)
endif()
debug_message("Using pkg-config from: ${PKGCONFIG}")
if(NOT PKGCONFIG AND NOT _vfpkg_SKIP_CHECK)
message(WARNING "Unable to find pkg-config to validate *.pc files. Skipping checkes!")
set(_vfpkg_SKIP_CHECK TRUE)
endif()
endif()
#Absolute Unix like paths
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_PACKAGES_DIR "${CURRENT_PACKAGES_DIR}")
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_INSTALLED_DIR "${CURRENT_INSTALLED_DIR}")
@ -223,19 +299,24 @@ function(vcpkg_fixup_pkgconfig)
get_filename_component(PKG_LIB_SEARCH_PATH "${_file}" DIRECTORY)
file(RELATIVE_PATH RELATIVE_PC_PATH "${PKG_LIB_SEARCH_PATH}" "${CURRENT_PACKAGES_DIR}")
string(REGEX REPLACE "/$" "" RELATIVE_PC_PATH "${RELATIVE_PC_PATH}")
string(REGEX REPLACE "/pkgconfig/?" "" PKG_LIB_SEARCH_PATH "${PKG_LIB_SEARCH_PATH}")
#Correct *.pc file
file(READ "${_file}" _contents)
string(REPLACE "${CURRENT_PACKAGES_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "${CURRENT_INSTALLED_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "${_VCPKG_PACKAGES_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "${_VCPKG_INSTALLED_DIR}" "\${prefix}" _contents "${_contents}")
string(REGEX REPLACE "^prefix=(\\\\)?\\\${prefix}" "prefix=\${pcfiledir}/${RELATIVE_PC_PATH}" _contents "${_contents}") # make pc file relocatable
vcpkg_fixup_pkgconfig_check_libraries("RELEASE" _contents "${_vfpkg_SYSTEM_LIBRARIES}" "${_vfpkg_SYSTEM_PACKAGES}" "${_vfpkg_IGNORE_FLAGS}")
string(REGEX REPLACE "^prefix=(\")?(\\\\)?\\\${prefix}(\")?" "prefix=\${pcfiledir}/${RELATIVE_PC_PATH}" _contents "${_contents}") # make pc file relocatable
string(REGEX REPLACE "[\n]prefix=(\")?(\\\\)?\\\${prefix}(\")?" "\nprefix=\${pcfiledir}/${RELATIVE_PC_PATH}" _contents "${_contents}") # make pc file relocatable
file(WRITE "${_file}" "${_contents}")
unset(PKG_LIB_SEARCH_PATH)
endforeach()
if(NOT _vfpkg_SKIP_CHECK) # The check can only run after all files have been corrected!
foreach(_file ${_vfpkg_RELEASE_FILES})
vcpkg_fixup_pkgconfig_check_files("${PKGCONFIG}" "${_file}" "RELEASE" "${_vfpkg_SYSTEM_LIBRARIES}" "${_vfpkg_IGNORE_FLAGS}")
endforeach()
endif()
message(STATUS "Fixing pkgconfig - debug")
debug_message("Files: ${_vfpkg_DEBUG_FILES}")
foreach(_file ${_vfpkg_DEBUG_FILES})
@ -244,24 +325,29 @@ function(vcpkg_fixup_pkgconfig)
file(RELATIVE_PATH RELATIVE_PC_PATH "${PKG_LIB_SEARCH_PATH}" "${CURRENT_PACKAGES_DIR}/debug/")
string(REGEX REPLACE "/$" "" RELATIVE_PC_PATH "${RELATIVE_PC_PATH}")
string(REGEX REPLACE "/pkgconfig/?" "" PKG_LIB_SEARCH_PATH "${PKG_LIB_SEARCH_PATH}")
#Correct *.pc file
file(READ "${_file}" _contents)
string(REPLACE "${CURRENT_PACKAGES_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "${CURRENT_INSTALLED_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "${_VCPKG_PACKAGES_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "${_VCPKG_INSTALLED_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "debug/include" "../include" _contents "${_contents}")
string(REPLACE "\${prefix}/include" "\${prefix}/../include" _contents "${_contents}")
string(REPLACE "debug/share" "../share" _contents "${_contents}")
string(REPLACE "\${prefix}/share" "\${prefix}/../share" _contents "${_contents}")
string(REPLACE "debug/lib" "lib" _contents "${_contents}") # the prefix will contain the debug keyword
string(REGEX REPLACE "^prefix=(\\\\)?\\\${prefix}(/debug)?" "prefix=\${pcfiledir}/${RELATIVE_PC_PATH}" _contents "${_contents}") # make pc file relocatable
string(REGEX REPLACE "^prefix=(\")?(\\\\)?\\\${prefix}(/debug)?(\")?" "prefix=\${pcfiledir}/${RELATIVE_PC_PATH}" _contents "${_contents}") # make pc file relocatable
string(REGEX REPLACE "[\n]prefix=(\")?(\\\\)?\\\${prefix}(/debug)?(\")?" "\nprefix=\${pcfiledir}/${RELATIVE_PC_PATH}" _contents "${_contents}") # make pc file relocatable
string(REPLACE "\${prefix}/debug" "\${prefix}" _contents "${_contents}") # replace remaining debug paths if they exist.
vcpkg_fixup_pkgconfig_check_libraries("DEBUG" _contents "${_vfpkg_SYSTEM_LIBRARIES}" "${_vfpkg_SYSTEM_PACKAGES}" "${_vfpkg_IGNORE_FLAGS}")
file(WRITE "${_file}" "${_contents}")
unset(PKG_LIB_SEARCH_PATH)
endforeach()
if(NOT _vfpkg_SKIP_CHECK) # The check can only run after all files have been corrected!
foreach(_file ${_vfpkg_DEBUG_FILES})
vcpkg_fixup_pkgconfig_check_files("${PKGCONFIG}" "${_file}" "DEBUG" "${_vfpkg_SYSTEM_LIBRARIES}" "${_vfpkg_IGNORE_FLAGS}")
endforeach()
endif()
message(STATUS "Fixing pkgconfig --- finished")
set(VCPKG_FIXUP_PKGCONFIG_CALLED TRUE CACHE INTERNAL "See below" FORCE)