Simlar problem of #7749. The absolute paths contain in installed *Targets.cmake files of POCO
Environment
To Reproduce
Steps to reproduce the behavior:
Failure logs
installed\x64-windows\share\poco\PocoFoundationTargets.cmake has absolute paths in its definition of INTERFACE_LINK_LIBRARIES that are wrong when exported
After install poco:x64-windows, following files contain absolute paths in my case.
libpng\libpng16.cmake
56: INTERFACE_LINK_LIBRARIES "\$<\$<NOT:\$<CONFIG:DEBUG>>:C:/src/vcpkg/installed/x64-windows/lib/zlib.lib>;\$<\$<CONFIG:DEBUG>:C:/src/vcpkg/installed/x64-windows/debug/lib/zlibd.lib>"
poco\PocoCryptoTargets.cmake
58: INTERFACE_LINK_LIBRARIES "Poco::Foundation;C:/src/vcpkg/installed/x64-windows/lib/ssleay32.lib;C:/src/vcpkg/installed/x64-windows/lib/libeay32.lib"
poco\PocoDataSQLiteTargets.cmake
58: INTERFACE_LINK_LIBRARIES "Poco::Foundation;Poco::Data;C:/src/vcpkg/installed/x64-windows/lib/sqlite3.lib"
poco\PocoFoundationTargets.cmake
58: INTERFACE_LINK_LIBRARIES "\$<\$<NOT:\$<CONFIG:DEBUG>>:C:/src/vcpkg/installed/x64-windows/lib/pcre.lib>;\$<\$<CONFIG:DEBUG>:C:/src/vcpkg/installed/x64-windows/debug/lib/pcred.lib>;\$<\$<NOT:\$<CONFIG:DEBUG>>:C:/src/vcpkg/installed/x64-windows/lib/zlib.lib>;\$<\$<CONFIG:DEBUG>:C:/src/vcpkg/installed/x64-windows/debug/lib/zlibd.lib>;iphlpapi"
poco\PocoNetSSLTargets.cmake
58: INTERFACE_LINK_LIBRARIES "Poco::Crypto;Poco::Net;Poco::Util;Poco::Foundation;C:/src/vcpkg/installed/x64-windows/lib/ssleay32.lib;C:/src/vcpkg/installed/x64-windows/lib/libeay32.lib"
poco\PocoXMLTargets.cmake
58: INTERFACE_LINK_LIBRARIES "C:/src/vcpkg/installed/x64-windows/lib/expat.lib;Poco::Foundation"
This doesn't seem to be a POCO specific issue.
libpng\libpng16.cmake also contain absolute path in INTERFACE_LINK_LIBRARIES.
The fix of #4622 (PR #5459) did not work because of the case difference of Windows drive letter.
I put debug print here.
> git diff
diff --git a/scripts/cmake/vcpkg_fixup_cmake_targets.cmake b/scripts/cmake/vcpkg_fixup_cmake_targets.cmake
index 1e0f2493d..b9150f1c6 100644
--- a/scripts/cmake/vcpkg_fixup_cmake_targets.cmake
+++ b/scripts/cmake/vcpkg_fixup_cmake_targets.cmake
@@ -152,6 +152,7 @@ function(vcpkg_fixup_cmake_targets)
_contents "${_contents}")
#Fix wrongly absolute paths to install dir with the correct dir using ${_IMPORT_PREFIX}
string(REPLACE "${CURRENT_INSTALLED_DIR}" [[${_IMPORT_PREFIX}]] _contents "${_contents}")
+ message("%%%% file = ${MAIN_CMAKE}, string replace ${CURRENT_INSTALLED_DIR} to _IMPORT_PREFIX")
file(WRITE ${MAIN_CMAKE} "${_contents}")
endforeach()
I reinstalled libpng.
> vcpkg install libpng
Your feedback is important to improve Vcpkg! Please take 3 minutes to complete our survey by running: vcpkg contact --survey
The following packages will be built and installed:
libpng[core]:x64-windows
Starting package 1/1: libpng:x64-windows
Building package libpng[core]:x64-windows...
Warning: abi keys are missing values:
zlib
-- Using cached C:/src/vcpkg/downloads/glennrp-libpng-v1.6.37.tar.gz
-- Using source at c:/src/vcpkg/buildtrees/libpng/src/v1.6.37-6445e5863e
-- Configuring x64-windows
-- Building x64-windows-dbg
-- Building x64-windows-rel
%%%% file = c:/src/vcpkg/packages/libpng_x64-windows/share/libpng/libpng16-debug.cmake, string replace c:/src/vcpkg/installed/x64-windows to _IMPORT_PREFIX
%%%% file = c:/src/vcpkg/packages/libpng_x64-windows/share/libpng/libpng16-release.cmake, string replace c:/src/vcpkg/installed/x64-windows to _IMPORT_PREFIX
%%%% file = c:/src/vcpkg/packages/libpng_x64-windows/share/libpng/libpng16.cmake, string replace c:/src/vcpkg/installed/x64-windows to _IMPORT_PREFIX
-- Performing post-build validation
-- Performing post-build validation done
Building package libpng[core]:x64-windows... done
Installing package libpng[core]:x64-windows...
Installing package libpng[core]:x64-windows... done
Elapsed time for package libpng:x64-windows: 21.75 s
Total elapsed time: 21.75 s
The package libpng:x64-windows provides CMake targets:
find_package(libpng CONFIG REQUIRED)
target_link_libraries(main PRIVATE png)
In this case, packages/libpng_x64-windows/share/libpng/libpng16.cmake contain
"C:/src/vcpkg/installed/x64-windows/lib/zlib.lib"
and tried to fix it by replace "c:/src/vcpkg/installed/x64-windows" into "${_IMPORT_PREFIX}".
It didn't work because case difference of drive letter. ah, orz...
This patch solves this issue. but not enough for general use. because,
0001-Fix-cmake-generated-targets-and-configs-with-case-in.patch.txt
I would like to discuss about a solution if you right.
Suppose replacing CURRENT_INSTALL_DIR by _IMPORT_PREFIX,
| (A) replace twice | (B) regex replace | (C) external script | (D) Make CURRENT_INSTALL_DIR use uppercase drive letter |
| -- | -- | -- | -- |
| Prepare two set of replace string. and do sring(replace) twice.
(e.g. C:/src/vcpkg and c:/src/vcpkg) | Prepare regex pattern of ${CURRENT_INSTALL_DIR}.
and do string(regex replace) | Write a PowerShell script for case insensitive replace ${CURRENT_INSTALL_DIR} by _IMPORT_PREFIX | Make CURRENT_INSTALL_DIR never contain lowercase drive letter even if current directory is lowercase drive letter. |
| (+) Simple. no need to care regex pattern escape. | (+) just replace once. | (+) no CMake tricks.
PowerShell may work better for case insensitive replace.
(+-) It's worth if you plan to use it elsewhere .cmake scripts. | (++) Simple |
| (-) not so smart | (-) messy regex pattern escape "([][+.*()^])" "\\\1"
CMake doesn't provide special function like .NET's Regex.Escape. | (-) increase a file to maintain.
(-) It's not intuitive. why call .ps1 from inside of .cmake... | (-) a bit wide impact by fix. It need to fixup VCPKG_ROOT_DIR at ports.cmake since CURRENT_INSTALLED_DIR made from VCPKG_ROOT_DIR. |
| (-) Only Windows need it. Linux and OSX also do repace twice by same string ? | (-) Overkill for Linux and OSX since they were happy by simple string(replace) | (-) same of left. Overkill for Linux and OSX. | (-) Only Windows need it. but just one line addition maybe OK. |
@Rastaban I think we should check if there are absolute paths to these cmake files in POST_CHECK.
@tetsuh I checked the generated *.cmake files and found that no path contains absolute path.
All of these paths are set to ${_IMPORT_PREFIX}.
I think cmake will convert ${_IMPORT_PREFIX} to an absolute path during configuration, which is why you see these absolute paths.
I could reproduced the reported behaviour. @JackBoosY Can you try following ?
NG: use c:\src\vcpkg as current directory.
Good: use C:\src\vcpkg as current directory.
I have used c: drive not C: drive. Is it so bad ? :(
NG (Reproduced)
> cd c:\src
c:\src> git clone https://github.com/Microsoft/vcpkg.git vcpkg.repro8237
c:\src> cd vcpkg.repro8237
c:\src\vcpkg.repro8237> .\bootstrap-vcpkg.bat
c:\src\vcpkg.repro8237> .\vcpkg.exe install libpng:x64-windows
Good
> cd C:\src
C:\src> git clone https://github.com/Microsoft/vcpkg.git vcpkg.norepro8237
C:\src> cd vcpkg.norepro8237
C:\src\vcpkg.norepro8237> .\bootstrap-vcpkg.bat
C:\src\vcpkg.norepro8237> .\vcpkg.exe install libpng:x64-windows
I added plan (D). and push draft PR #8304. Thnx.
Similar issue at CMake. it looks well-discussed.
https://gitlab.kitware.com/cmake/cmake/issues/16648
The CMAKE_ROOT had fixup of such lowercase drive letter issue by https://gitlab.kitware.com/cmake/cmake/merge_requests/495
I confirmed this issue was solved. Thank you.