microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.05k stars 6.36k forks source link

[macOS] Some ports reference hardcoded library paths #16259

Open davidebeatrici opened 3 years ago

davidebeatrici commented 3 years ago

After relocating a vcpkg build environment to another machine, I encountered the following error when building my application:

ninja: error: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreFoundation.framework', needed by 'murmurd', missing and no known rule to make it

Searching for /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk in the environment's directory yields the following results:

In installed/x64-osx/share/absl/abslTargets.cmake:

set_target_properties(absl::time_zone PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "\$<\$<PLATFORM_ID:Darwin>:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreFoundation.framework>"
)

In installed/x64-osx/share/unofficial-angle/unofficial-angle-config.cmake:

set_target_properties(unofficial::angle::angle_gpu_info_util PROPERTIES
  INTERFACE_LINK_LIBRARIES "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/IOKit.framework;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreFoundation.framework;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreGraphics.framework;\$<LINK_ONLY:unofficial::angle::angle_common>"
)

The correct content is as follows:

set_target_properties(absl::time_zone PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "\$<\$<PLATFORM_ID:Darwin>:-framework CoreFoundation>"
)
set_target_properties(unofficial::angle::angle_gpu_info_util PROPERTIES
  INTERFACE_LINK_LIBRARIES "-framework IOKit;-framework CoreFoundation;-framework CoreGraphics;\$<LINK_ONLY:unofficial::angle::angle_common>"
)
JackBoosY commented 3 years ago

@strega-nil What do you think about? I think we should correct vcpkg_fixup_cmake_targets.

strega-nil commented 3 years ago

@JackBoosY is this something that angle/abseil screws up, or is it something that cmake screws up? In the former case, then we should do the fix in the ports; if it's something that cmake screws up, then we should fix it with vcpkg_fixup_cmake_targets. At least, that's my opinion.

JackBoosY commented 3 years ago

I think that's a common issue. Will be fixed in vcpkg-cmake-config and vcpkg_fixup_cmake_targets.

daschuer commented 1 year ago

This seems to be a common upstream issue. I have tried to fix it in case of abseil with:

-    $<$<PLATFORM_ID:Darwin>:${CoreFoundation}>
+    $<$<PLATFORM_ID:Darwin>:"-framework CoreFoundation">

https://github.com/daschuer/vcpkg/blob/750ff67b6d676123c75065105b10bb7e3fac661c/ports/abseil/core-foundation-deps.patch

Unfortunately I get now a link error because of

-l"-framework CoreFoundation"
daschuer commented 1 year ago

This is a duplicate: https://github.com/aws/aws-sdk-cpp/issues/1245 It becomes a real error if you update Xcode and the original absolute path doe no longer exist.

dg0yt commented 1 year ago

AFAICT there are three common mistakes in CMake projects:

Maybe you can pass -framework CoreFoundation via LINKOPTS instead of DEPS.