diff options
| author | Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> | 2020-07-24 20:39:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-24 11:39:21 -0700 |
| commit | 458c20e94b9f558b523f187ce403bd062e131cdb (patch) | |
| tree | 20fd042b01a4c1090d7cb239dc17da0d9e97b02b /scripts/cmake | |
| parent | 077c0746be3773fdd443af52cbe5c3cc26379a15 (diff) | |
| download | vcpkg-458c20e94b9f558b523f187ce403bd062e131cdb.tar.gz vcpkg-458c20e94b9f558b523f187ce403bd062e131cdb.zip | |
[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>
Diffstat (limited to 'scripts/cmake')
| -rw-r--r-- | scripts/cmake/vcpkg_common_definitions.cmake | 2 | ||||
| -rw-r--r-- | scripts/cmake/vcpkg_fixup_pkgconfig.cmake | 388 |
2 files changed, 238 insertions, 152 deletions
diff --git a/scripts/cmake/vcpkg_common_definitions.cmake b/scripts/cmake/vcpkg_common_definitions.cmake index ee6f34849..4ea0a361d 100644 --- a/scripts/cmake/vcpkg_common_definitions.cmake +++ b/scripts/cmake/vcpkg_common_definitions.cmake @@ -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() diff --git a/scripts/cmake/vcpkg_fixup_pkgconfig.cmake b/scripts/cmake/vcpkg_fixup_pkgconfig.cmake index 6acb51360..6b840afe2 100644 --- a/scripts/cmake/vcpkg_fixup_pkgconfig.cmake +++ b/scripts/cmake/vcpkg_fixup_pkgconfig.cmake @@ -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}") + 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() + list(REMOVE_DUPLICATES _pkg_libs_output) # We don't care about linker order and repeats - #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 + 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("[^"]+"|(\\ |[^ ]+)+)$]] ) - 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() - endforeach() - if(NO_CHECK_LIB) - break() + 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}) - 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}) - 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") + 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}") + 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() - 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") - else() - debug_message("Found ${_libname} at ${CHECK_LIB_${_libname}}") - 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() + endforeach() + # 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 () + 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() - 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,7 +275,20 @@ function(vcpkg_fixup_pkgconfig) list(FILTER _vfpkg_DEBUG_FILES INCLUDE REGEX "${CURRENT_PACKAGES_DIR}/debug/") endif() - #Absolute Unix like paths + 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(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}") + 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. 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) |
