We currently only "collapse" debug files from debug\share\<name>\. Ideally, we should handle all of the valid package directories so portfile authors can just drop this call in their portfile and avoid patching any cmake files.
<prefix>/ (W)
<prefix>/(cmake|CMake)/ (W)
<prefix>/<name>*/ (W)
<prefix>/<name>*/(cmake|CMake)/ (W)
<prefix>/(lib/<arch>|lib|share)/cmake/<name>*/ (U)
<prefix>/(lib/<arch>|lib|share)/<name>*/ (U)
<prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/ (U)
This is a must needed feature. I am having all sorts of trouble patching the config.cmake file that was originally located at <prefix>/lib/cmake/<name>
vcpkg_fixup_cmake_targets support CONFIG_PATH parameter https://github.com/Microsoft/vcpkg/blob/9f0a7173a21e8b036d0df467aae978fda74e4a05/scripts/cmake/vcpkg_fixup_cmake_targets.cmake#L9-L13
@KindDragon I am trying to test vcpkg install tinyxml2 --head while waiting for the author of tinyxml2 to make a release for the newly supported cmake export. I modify the portfile.cmake for tinyxml2 to add in vcpkg_fixup_cmake_targets(CONFIG_PATH "lib/cmake/tinyxml2")and it builds successfully but the problem is when I use find_package(tinyxml2) in my code it throws the below error
``````
CMake Error at C:/dev/vcpkg/packages/tinyxml2_x64-windows/share/tinyxml2/tinyxml2Targets.cmake:77 (message):
The imported target "tinyxml2" references the file
"C:/dev/vcpkg/packages/debug/lib/tinyxml2d.lib"
but this file does not exist. Possible reasons include:
The file was deleted, renamed, or moved to another location.
An install or uninstall procedure did not complete successfully.
The installation package was faulty and contained
"C:/dev/vcpkg/packages/tinyxml2_x64-windows/share/tinyxml2/tinyxml2Targets.cmake"
but not all the files it references.
Call Stack (most recent call first):
C:/dev/vcpkg/packages/tinyxml2_x64-windows/share/tinyxml2/tinyxml2Config.cmake:1 (include)
modules/Reconstruct/CMakeLists.txt:97 (find_package)
-- Configuring incomplete, errors occurred!
``````
tinyxml2d.lib is in C:/dev/vcpkg/packages/tinyxml2_x64-windows/debug/lib/tinyxml2d.lib instead of C:/dev/vcpkg/packages/debug/lib/tinyxml2d.lib. I am having trouble to figure out which and where I should patch in the portfile.cmake to fix it.
vcpkg_fixup_cmake_targets doesn't solve all problems, sometimes you need patch config files manually https://github.com/Microsoft/vcpkg/blob/748e8b6e7495f06253eb21236bf3abf38b897b63/ports/fmt/portfile.cmake#L36-L42
@KindDragon I just figured out what I need to patch to get tinyxml2 to work.
In line 44~51 of tinyxml2Targets.cmake
``````
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()
``````
I had to delete one line of get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) to make it work, so it becomes
``````
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()
``````
Do you know how I can achieve this just by modifying the portfile.cmake? There seems to be no command to delete by line. If I do a string replace of get_filename_component into blank then all three lines of get_filename_component will disappear.
@jasjuang You can try something like:
string(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)" TINYXML2_TARGETS ${TINYXML2_TARGETS})
@KindDragon That is a very clever patch! I had to escape " and $ with a backslash in front of it to make it work though.
This should now be fixed by 338f8614. Thanks again to @KindDragon for the crux of the solution :)
We should try to remove as much of the previous manual patching as possible from ports that can now be serviced by vcpkg_fixup_cmake_targets().
Most helpful comment
This should now be fixed by 338f8614. Thanks again to @KindDragon for the crux of the solution :)
We should try to remove as much of the previous manual patching as possible from ports that can now be serviced by
vcpkg_fixup_cmake_targets().