Skip to content

Commit

Permalink
[vcpkg-cmake-config] fix up cmake_current_packages_dir (#20439)
Browse files Browse the repository at this point in the history
* [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 <bion@microsoft.com>
  • Loading branch information
3 people committed Dec 9, 2021
1 parent a7a0aaf commit 77967a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ports/vcpkg-cmake-config/vcpkg.json
@@ -1,4 +1,4 @@
{
"name": "vcpkg-cmake-config",
"version-date": "2021-11-01"
"version-date": "2021-12-01"
}
30 changes: 13 additions & 17 deletions ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake
Expand Up @@ -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")

Expand Down Expand Up @@ -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:
#\$<\$<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}")

# 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()
Expand All @@ -233,5 +231,3 @@ get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]]
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
endif()
endfunction()


2 changes: 1 addition & 1 deletion versions/baseline.json
Expand Up @@ -7097,7 +7097,7 @@
"port-version": 0
},
"vcpkg-cmake-config": {
"baseline": "2021-11-01",
"baseline": "2021-12-01",
"port-version": 0
},
"vcpkg-gfortran": {
Expand Down
5 changes: 5 additions & 0 deletions 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",
Expand Down

0 comments on commit 77967a6

Please sign in to comment.