diff options
| author | Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> | 2020-11-25 21:06:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-25 12:06:25 -0800 |
| commit | e2ec3b25e372041a1be75065c7f9cb421a155d0a (patch) | |
| tree | 496a86ee346d859a8e438fc12a17ae0a2bdca915 /scripts | |
| parent | 54c63514a6d012d1385f93a863d1d7eb4c03c9a2 (diff) | |
| download | vcpkg-e2ec3b25e372041a1be75065c7f9cb421a155d0a.tar.gz vcpkg-e2ec3b25e372041a1be75065c7f9cb421a155d0a.zip | |
[vcpkg_fixup_cmake_targets] Add NO_PREFIX_CORRECTION (#12215)
* [vcpkg/scripts/fixup_cmake] add option NO_PREFIX_CORRECTION to not apply the
* add a bit of explanation why the prefix correction might be incorrect.
* apply the if only around the import prefix changes
* Update scripts/cmake/vcpkg_fixup_cmake_targets.cmake
Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/cmake/vcpkg_fixup_cmake_targets.cmake | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/scripts/cmake/vcpkg_fixup_cmake_targets.cmake b/scripts/cmake/vcpkg_fixup_cmake_targets.cmake index 7e4432e84..31bf9351b 100644 --- a/scripts/cmake/vcpkg_fixup_cmake_targets.cmake +++ b/scripts/cmake/vcpkg_fixup_cmake_targets.cmake @@ -27,6 +27,11 @@ ## Passing this option disable such behavior, as it is convenient for ports that install ## more than one CMake package configuration file. ## +## ### NO_PREFIX_CORRECTION +## Disables the correction of_IMPORT_PREFIX done by vcpkg due to moving the targets. +## Currently the correction does not take into account how the files are moved and applies +## I rather simply correction which in some cases will yield the wrong results. +## ## ## Notes ## Transform all `/debug/<CONFIG_PATH>/*targets-debug.cmake` files and move them to `/<TARGET_PATH>`. ## Removes all `/debug/<CONFIG_PATH>/*targets.cmake` and `/debug/<CONFIG_PATH>/*config.cmake`. @@ -44,7 +49,7 @@ ## * [nlohmann-json](https://github.com/Microsoft/vcpkg/blob/master/ports/nlohmann-json/portfile.cmake) function(vcpkg_fixup_cmake_targets) # parse parameters such that semicolons in options arguments to COMMAND don't get erased - cmake_parse_arguments(PARSE_ARGV 0 _vfct "DO_NOT_DELETE_PARENT_CONFIG_PATH" "CONFIG_PATH;TARGET_PATH" "") + cmake_parse_arguments(PARSE_ARGV 0 _vfct "DO_NOT_DELETE_PARENT_CONFIG_PATH" "CONFIG_PATH;TARGET_PATH;NO_PREFIX_CORRECTION" "") if(_vfct_UNPARSED_ARGUMENTS) message(FATAL_ERROR "vcpkg_fixup_cmake_targets was passed extra arguments: ${_vfct_UNPARSED_ARGUMENTS}") @@ -160,21 +165,40 @@ function(vcpkg_fixup_cmake_targets) #Fix ${_IMPORT_PREFIX} in cmake generated targets and configs; #Since those can be renamed we have to check in every *.cmake file(GLOB_RECURSE MAIN_CMAKES "${RELEASE_SHARE}/*.cmake") + foreach(MAIN_CMAKE IN LISTS MAIN_CMAKES) file(READ ${MAIN_CMAKE} _contents) - string(REGEX REPLACE - "get_filename_component\\(_IMPORT_PREFIX \"\\\${CMAKE_CURRENT_LIST_FILE}\" PATH\\)(\nget_filename_component\\(_IMPORT_PREFIX \"\\\${_IMPORT_PREFIX}\" PATH\\))*" - "get_filename_component(_IMPORT_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)\nget_filename_component(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)\nget_filename_component(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)" - _contents "${_contents}") # see #1044 for details why this replacement is necessary. See #4782 why it must be a regex. - string(REGEX REPLACE - "get_filename_component\\(PACKAGE_PREFIX_DIR \"\\\${CMAKE_CURRENT_LIST_DIR}/\\.\\./(\\.\\./)*\" ABSOLUTE\\)" - "get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/../../\" ABSOLUTE)" - _contents "${_contents}") - string(REGEX REPLACE - "get_filename_component\\(PACKAGE_PREFIX_DIR \"\\\${CMAKE_CURRENT_LIST_DIR}/\\.\\.((\\\\|/)\\.\\.)*\" ABSOLUTE\\)" - "get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/../../\" ABSOLUTE)" - _contents "${_contents}") # This is a meson-related workaround, see https://github.com/mesonbuild/meson/issues/6955 + #This correction is not correct for all cases. To make it correct for all cases it needs to consider + #original folder deepness to CURRENT_PACKAGES_DIR in comparison to the moved to folder deepness which + #is always at least (>=) 2, e.g. share/${PORT}. Currently the code assumes it is always 2 although + #this requirement is only true for the *Config.cmake. The targets are not required to be in the same + #folder as the *Config.cmake! + if(NOT _vfct_NO_PREFIX_CORRECTION) + string(REGEX REPLACE + "get_filename_component\\(_IMPORT_PREFIX \"\\\${CMAKE_CURRENT_LIST_FILE}\" PATH\\)(\nget_filename_component\\(_IMPORT_PREFIX \"\\\${_IMPORT_PREFIX}\" PATH\\))*" + "get_filename_component(_IMPORT_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)\nget_filename_component(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)\nget_filename_component(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)" + _contents "${_contents}") # see #1044 for details why this replacement is necessary. See #4782 why it must be a regex. + string(REGEX REPLACE + "get_filename_component\\(PACKAGE_PREFIX_DIR \"\\\${CMAKE_CURRENT_LIST_DIR}/\\.\\./(\\.\\./)*\" ABSOLUTE\\)" + "get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/../../\" ABSOLUTE)" + _contents "${_contents}") + string(REGEX REPLACE + "get_filename_component\\(PACKAGE_PREFIX_DIR \"\\\${CMAKE_CURRENT_LIST_DIR}/\\.\\.((\\\\|/)\\.\\.)*\" ABSOLUTE\\)" + "get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/../../\" ABSOLUTE)" + _contents "${_contents}") # This is a meson-related workaround, see https://github.com/mesonbuild/meson/issues/6955 + endif() + #Fix wrongly absolute paths to install dir with the correct dir using ${_IMPORT_PREFIX} + #This happens if vcpkg built libraries are directly linked to a target instead of using + #an imported target for it. We could add more logic here to identify defect target files. + #Since the replacement here in a multi config build always requires a generator expression + #in front of the absoulte path to ${CURRENT_INSTALLED_DIR}. So the match should always be at + #least >:${CURRENT_INSTALLED_DIR}. + #In general the following generator expressions should be there: + #\$<\$<CONFIG:DEBUG>:${CURRENT_INSTALLED_DIR}/debug/lib/somelib> + #and/or + #\$<\$<NOT:\$<CONFIG:DEBUG>>:${CURRENT_INSTALLED_DIR}/lib/somelib> + #with ${CURRENT_INSTALLED_DIR} being fully expanded string(REPLACE "${CURRENT_INSTALLED_DIR}" [[${_IMPORT_PREFIX}]] _contents "${_contents}") file(WRITE ${MAIN_CMAKE} "${_contents}") endforeach() |
