mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-06-07 19:32:46 +08:00
[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>
This commit is contained in:
parent
54c63514a6
commit
e2ec3b25e3
@ -27,6 +27,11 @@
|
|||||||
## Passing this option disable such behavior, as it is convenient for ports that install
|
## Passing this option disable such behavior, as it is convenient for ports that install
|
||||||
## more than one CMake package configuration file.
|
## 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
|
## ## Notes
|
||||||
## Transform all `/debug/<CONFIG_PATH>/*targets-debug.cmake` files and move them to `/<TARGET_PATH>`.
|
## 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`.
|
## 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)
|
## * [nlohmann-json](https://github.com/Microsoft/vcpkg/blob/master/ports/nlohmann-json/portfile.cmake)
|
||||||
function(vcpkg_fixup_cmake_targets)
|
function(vcpkg_fixup_cmake_targets)
|
||||||
# parse parameters such that semicolons in options arguments to COMMAND don't get erased
|
# 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)
|
if(_vfct_UNPARSED_ARGUMENTS)
|
||||||
message(FATAL_ERROR "vcpkg_fixup_cmake_targets was passed extra arguments: ${_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;
|
#Fix ${_IMPORT_PREFIX} in cmake generated targets and configs;
|
||||||
#Since those can be renamed we have to check in every *.cmake
|
#Since those can be renamed we have to check in every *.cmake
|
||||||
file(GLOB_RECURSE MAIN_CMAKES "${RELEASE_SHARE}/*.cmake")
|
file(GLOB_RECURSE MAIN_CMAKES "${RELEASE_SHARE}/*.cmake")
|
||||||
|
|
||||||
foreach(MAIN_CMAKE IN LISTS MAIN_CMAKES)
|
foreach(MAIN_CMAKE IN LISTS MAIN_CMAKES)
|
||||||
file(READ ${MAIN_CMAKE} _contents)
|
file(READ ${MAIN_CMAKE} _contents)
|
||||||
string(REGEX REPLACE
|
#This correction is not correct for all cases. To make it correct for all cases it needs to consider
|
||||||
"get_filename_component\\(_IMPORT_PREFIX \"\\\${CMAKE_CURRENT_LIST_FILE}\" PATH\\)(\nget_filename_component\\(_IMPORT_PREFIX \"\\\${_IMPORT_PREFIX}\" PATH\\))*"
|
#original folder deepness to CURRENT_PACKAGES_DIR in comparison to the moved to folder deepness which
|
||||||
"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)"
|
#is always at least (>=) 2, e.g. share/${PORT}. Currently the code assumes it is always 2 although
|
||||||
_contents "${_contents}") # see #1044 for details why this replacement is necessary. See #4782 why it must be a regex.
|
#this requirement is only true for the *Config.cmake. The targets are not required to be in the same
|
||||||
string(REGEX REPLACE
|
#folder as the *Config.cmake!
|
||||||
"get_filename_component\\(PACKAGE_PREFIX_DIR \"\\\${CMAKE_CURRENT_LIST_DIR}/\\.\\./(\\.\\./)*\" ABSOLUTE\\)"
|
if(NOT _vfct_NO_PREFIX_CORRECTION)
|
||||||
"get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/../../\" ABSOLUTE)"
|
string(REGEX REPLACE
|
||||||
_contents "${_contents}")
|
"get_filename_component\\(_IMPORT_PREFIX \"\\\${CMAKE_CURRENT_LIST_FILE}\" PATH\\)(\nget_filename_component\\(_IMPORT_PREFIX \"\\\${_IMPORT_PREFIX}\" PATH\\))*"
|
||||||
string(REGEX REPLACE
|
"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)"
|
||||||
"get_filename_component\\(PACKAGE_PREFIX_DIR \"\\\${CMAKE_CURRENT_LIST_DIR}/\\.\\.((\\\\|/)\\.\\.)*\" ABSOLUTE\\)"
|
_contents "${_contents}") # see #1044 for details why this replacement is necessary. See #4782 why it must be a regex.
|
||||||
"get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/../../\" ABSOLUTE)"
|
string(REGEX REPLACE
|
||||||
_contents "${_contents}") # This is a meson-related workaround, see https://github.com/mesonbuild/meson/issues/6955
|
"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}
|
#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}")
|
string(REPLACE "${CURRENT_INSTALLED_DIR}" [[${_IMPORT_PREFIX}]] _contents "${_contents}")
|
||||||
file(WRITE ${MAIN_CMAKE} "${_contents}")
|
file(WRITE ${MAIN_CMAKE} "${_contents}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
Loading…
Reference in New Issue
Block a user