Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[scripts] add new function vcpkg_fixup_pkgconfig #9861

Merged
merged 12 commits into from
Apr 28, 2020
1 change: 1 addition & 0 deletions scripts/cmake/vcpkg_common_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ include(vcpkg_execute_build_process)
include(vcpkg_fail_port_install)
include(vcpkg_find_acquire_program)
include(vcpkg_fixup_cmake_targets)
include(vcpkg_fixup_pkgconfig)
include(vcpkg_from_github)
include(vcpkg_from_gitlab)
include(vcpkg_from_bitbucket)
Expand Down
49 changes: 49 additions & 0 deletions scripts/cmake/vcpkg_fixup_pkgconfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#.rst:
# .. command:: vcpkg_fixup_pkgconfig
#
# Tries to fix the paths found in *.pc files

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note: we use a different comment style, which is extracted into .md files via docs/regenerate.ps1. See some other helpers like vcpkg_configure_cmake() for examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed but still not sure if its 100% correct.

function(vcpkg_fixup_pkgconfig)
cmake_parse_arguments(_vfpkg "" "" "RELEASE_FILES;DEBUG_FILES" ${ARGN})

message(STATUS "Fixing pkgconfig")
if(_vfpkg_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "vcpkg_fixup_pkgconfig was passed extra arguments: ${_vfct_UNPARSED_ARGUMENTS}")
endif()

if(NOT _vfpkg_RELEASE_FILES)
file(GLOB_RECURSE _vfpkg_RELEASE_FILES "${CURRENT_PACKAGES_DIR}/**/*.pc")
list(FILTER _vfpkg_RELEASE_FILES EXCLUDE REGEX "${CURRENT_PACKAGES_DIR}/debug/")
endif()

if(NOT _vfpkg_DEBUG_FILES)
file(GLOB_RECURSE _vfpkg_DEBUG_FILES "${CURRENT_PACKAGES_DIR}/debug/**/*.pc")
list(FILTER _vfpkg_DEBUG_FILES INCLUDE REGEX "${CURRENT_PACKAGES_DIR}/debug/")
endif()

message(STATUS "Fixing pkgconfig - release")
message(STATUS "Files: ${_vfpkg_RELEASE_FILES}")
foreach(_file ${_vfpkg_RELEASE_FILES})
file(READ "${_file}" _contents)
string(REPLACE "${CURRENT_PACKAGES_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "${CURRENT_INSTALLED_DIR}" "\${prefix}" _contents "${_contents}")
string(REGEX REPLACE "^prefix=\\\${prefix}" "prefix=${CURRENT_INSTALLED_DIR}" _contents "${_contents}")
file(WRITE "${_file}" "${_contents}")
endforeach()

message(STATUS "Fixing pkgconfig - debug")
message(STATUS "Files: ${_vfpkg_DEBUG_FILES}")
foreach(_file ${_vfpkg_DEBUG_FILES})
file(READ "${_file}" _contents)
string(REPLACE "${CURRENT_PACKAGES_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "${CURRENT_INSTALLED_DIR}" "\${prefix}" _contents "${_contents}")
string(REPLACE "debug/include" "../include" _contents "${_contents}")
string(REPLACE "debug/share" "../share" _contents "${_contents}")
string(REPLACE "debug/lib" "lib" _contents "${_contents}") # the prefix will contain the debug keyword
string(REGEX REPLACE "^prefix=\\\${prefix}" "prefix=${CURRENT_INSTALLED_DIR}" _contents "${_contents}")
file(WRITE "${_file}" "${_contents}")
endforeach()
message(STATUS "Fixing pkgconfig --- finished")
endfunction()