From 77967a62284322e01aa714d94202c58586db0860 Mon Sep 17 00:00:00 2001 From: Phoebe <20694052+PhoebeHui@users.noreply.github.com> Date: Thu, 9 Dec 2021 14:24:16 -0800 Subject: [PATCH] [vcpkg-cmake-config] fix up cmake_current_packages_dir (#20439) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [vcpkg-cmake-config] fix up cmake_current_packages_dir * Small changes * Address the review suggestion * Update ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake * Update the baseline version * Address the review suggestions * Address the review suggestions * fix up VCPKG_IMPORT_PREFIX if the file being modified at a deep subpath * Fix regressions * Remove out of date comments about multiconfig generators that are no longer relevant, fix spelling errors, and avoid calculating relative paths for the definition of VCPKG_IMPORT_PREFIX when not used. * Fix version database. Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com> Co-authored-by: Billy Robert O'Neal III --- ports/vcpkg-cmake-config/vcpkg.json | 2 +- .../vcpkg_cmake_config_fixup.cmake | 30 ++++++++----------- versions/baseline.json | 2 +- versions/v-/vcpkg-cmake-config.json | 5 ++++ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/ports/vcpkg-cmake-config/vcpkg.json b/ports/vcpkg-cmake-config/vcpkg.json index ae4ba43e39bb3d..2106a395577487 100644 --- a/ports/vcpkg-cmake-config/vcpkg.json +++ b/ports/vcpkg-cmake-config/vcpkg.json @@ -1,4 +1,4 @@ { "name": "vcpkg-cmake-config", - "version-date": "2021-11-01" + "version-date": "2021-12-01" } diff --git a/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake b/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake index f62deeeabe6378..9563341ae268ca 100644 --- a/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake +++ b/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake @@ -168,7 +168,7 @@ function(vcpkg_cmake_config_fixup) endforeach() endif() - #Fix ${_IMPORT_PREFIX} in cmake generated targets and configs; + #Fix ${_IMPORT_PREFIX} and absolute paths 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") @@ -201,22 +201,20 @@ get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]] 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} + #Fix absolute paths to installed dir with ones relative to ${CMAKE_CURRENT_LIST_DIR} #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: - #\$<\$:${CURRENT_INSTALLED_DIR}/debug/lib/somelib> - #and/or - #\$<\$>:${CURRENT_INSTALLED_DIR}/lib/somelib> - #with ${CURRENT_INSTALLED_DIR} being fully expanded - string(REPLACE "${CURRENT_INSTALLED_DIR}" [[${_IMPORT_PREFIX}]] contents "${contents}") - - # Patch out any remaining absolute references + #an imported target. + string(REPLACE "${CURRENT_INSTALLED_DIR}" [[${VCPKG_IMPORT_PREFIX}]] contents "${contents}") file(TO_CMAKE_PATH "${CURRENT_PACKAGES_DIR}" cmake_current_packages_dir) - string(REPLACE "${cmake_current_packages_dir}" [[${_IMPORT_PREFIX}]] contents "${contents}") + string(REPLACE "${cmake_current_packages_dir}" [[${VCPKG_IMPORT_PREFIX}]] contents "${contents}") + # If ${VCPKG_IMPORT_PREFIX} was actually used, inject a definition of it: + string(FIND "${contents}" [[${VCPKG_IMPORT_PREFIX}]] index) + if (NOT index STREQUAL "-1") + get_filename_component(main_cmake_dir "${main_cmake}" DIRECTORY) + # Calculate relative to be a sequence of "../" + file(RELATIVE_PATH relative "${main_cmake_dir}" "${cmake_current_packages_dir}") + string(PREPEND contents "get_filename_component(VCPKG_IMPORT_PREFIX \"\${CMAKE_CURRENT_LIST_DIR}\/${relative}\" ABSOLUTE)") + endif() file(WRITE "${main_cmake}" "${contents}") endforeach() @@ -233,5 +231,3 @@ get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]] file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") endif() endfunction() - - diff --git a/versions/baseline.json b/versions/baseline.json index f1faa62eb30357..99752f643c5bd2 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -7097,7 +7097,7 @@ "port-version": 0 }, "vcpkg-cmake-config": { - "baseline": "2021-11-01", + "baseline": "2021-12-01", "port-version": 0 }, "vcpkg-gfortran": { diff --git a/versions/v-/vcpkg-cmake-config.json b/versions/v-/vcpkg-cmake-config.json index ebb17990d27437..dda29410810e9c 100644 --- a/versions/v-/vcpkg-cmake-config.json +++ b/versions/v-/vcpkg-cmake-config.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "51df1bbddb22782b9e7f23f9b3588674184e991a", + "version-date": "2021-12-01", + "port-version": 0 + }, { "git-tree": "38a87ee8edd9ea8e8fff604fbcb785661a8d0e28", "version-date": "2021-11-01",