Skip to content

Commit

Permalink
Merge pull request #2 from dg0yt/osx-framework-config
Browse files Browse the repository at this point in the history
Fix exported osx framework config
  • Loading branch information
JackBoosY authored May 31, 2021
2 parents 80d5126 + d71129e commit 96c2367
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 46 deletions.
56 changes: 33 additions & 23 deletions ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,39 @@ get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]]
endif()
foreach(targets_file IN LISTS targets_files)
file(READ "${targets_file}" targets_content)

string(REGEX MATCHALL "INTERFACE_LINK_LIBRARIES[^\n]*" library_contents "${targets_content}")
string(REGEX REPLACE
[[/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/[^/]+/System/Library/Frameworks/([_a-zA-Z]+)\.framework]]
[[-framework \1]]
fixed_contents
"${library_contents}"
)
string(REGEX REPLACE
[[/Library/Developer/CommandLineTools/SDKs/[^/]+/System/Library/Frameworks/([_a-zA-Z]+)\.framework]]
[[-framework \1]]
fixed_contents
"${fixed_contents}"
)
if (fixed_contents AND NOT fixed_contents STREQUAL library_contents)
string(REGEX REPLACE
"${library_contents}"
"${fixed_contents}"
targets_content
"${targets_content}"
)
endif()

string(REGEX MATCHALL "INTERFACE_LINK_LIBRARIES[^\n]*\n" library_contents "${targets_content}")
foreach(line IN LISTS library_contents)
set(fixed_line "${line}")
string(REGEX MATCHALL [[/[^ ;"]+/[^ ;"/]+\.framework]] frameworks "${line}")
foreach(framework IN LISTS frameworks)
if(NOT framework MATCHES [[^(.+)/(.+)\.framework$]])
continue()
endif()
set(path "${CMAKE_MATCH_1}")
set(name "${CMAKE_MATCH_2}")
if(NOT DEFINED VCPKG_DETECTED_CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES)
set(_saved_buildtrees_dir "${CURRENT_BUILDTREES_DIR}")
set(CURRENT_BUILDTREES_DIR "${CURRENT_BUILDTREES_DIR}/get-cmake-vars")
vcpkg_internal_get_cmake_vars(
OUTPUT_FILE _VCPKG_CMAKE_VARS_FILE
OPTIONS
-DVCPKG_LANGUAGES=CXX
-DVCPKG_VARS_TO_CHECK=CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
-DVCPKG_FLAGS_TO_CHECK=
-DVCPKG_ENV_VARS_TO_CHECK=
)
debug_message("Including cmake vars from: ${_VCPKG_CMAKE_VARS_FILE}")
include("${_VCPKG_CMAKE_VARS_FILE}")
set(VCPKG_DETECTED_CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "${VCPKG_DETECTED_CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES}" PARENT_SCOPE)
set(CURRENT_BUILDTREES_DIR "${_saved_buildtrees_dir}")
endif()
list(FIND VCPKG_DETECTED_CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "${path}" index)
if(NOT index EQUAL -1)
string(REPLACE "${framework}" "-framework ${name}" fixed_line "${fixed_line}")
endif()
endforeach()
string(REPLACE "${line}" "${fixed_line}" targets_content "${targets_content}")
endforeach()
file(WRITE "${targets_file}" "${targets_content}")
endforeach()
endif()
Expand Down
57 changes: 34 additions & 23 deletions scripts/cmake/vcpkg_fixup_cmake_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -225,32 +225,43 @@ function(vcpkg_fixup_cmake_targets)
# see #16259 for details why this replacement is necessary.
file(GLOB targets_files "${RELEASE_SHARE}/*[Tt]argets.cmake")
if (targets_files STREQUAL "")
file(GLOB targets_files "${release_share}/*[Cc]onfig.cmake")
file(GLOB targets_files "${RELEASE_SHARE}/*[Cc]onfig.cmake")
endif()
foreach(targets_file IN LISTS targets_files)
file(READ "${targets_file}" targets_content)

string(REGEX MATCHALL "INTERFACE_LINK_LIBRARIES[^\n]*" library_contents "${targets_content}")
string(REGEX REPLACE
[[/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/[^/]+/System/Library/Frameworks/([_a-zA-Z]+)\.framework]]
[[-framework \1]]
fixed_contents
"${library_contents}"
)
string(REGEX REPLACE
[[/Library/Developer/CommandLineTools/SDKs/[^/]+/System/Library/Frameworks/([_a-zA-Z]+)\.framework]]
[[-framework \1]]
fixed_contents
"${fixed_contents}"
)
if (fixed_contents AND NOT fixed_contents STREQUAL library_contents)
string(REGEX REPLACE
"${library_contents}"
"${fixed_contents}"
targets_content
"${targets_content}"
)
endif()
string(REGEX MATCHALL "INTERFACE_LINK_LIBRARIES[^\n]*\n" library_contents "${targets_content}")
foreach(line IN LISTS library_contents)
set(fixed_line "${line}")
string(REGEX MATCHALL [[/[^ ;"]+/[^ ;"/]+\.framework]] frameworks "${line}")
foreach(framework IN LISTS frameworks)
if(NOT framework MATCHES [[^(.+)/(.+)\.framework$]])
continue()
endif()
set(path "${CMAKE_MATCH_1}")
set(name "${CMAKE_MATCH_2}")
if(NOT DEFINED VCPKG_DETECTED_CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES)
set(_saved_buildtrees_dir "${CURRENT_BUILDTREES_DIR}")
set(CURRENT_BUILDTREES_DIR "${CURRENT_BUILDTREES_DIR}/get-cmake-vars")
vcpkg_internal_get_cmake_vars(
OUTPUT_FILE _VCPKG_CMAKE_VARS_FILE
OPTIONS
-DVCPKG_LANGUAGES=CXX
-DVCPKG_VARS_TO_CHECK=CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
-DVCPKG_FLAGS_TO_CHECK=
-DVCPKG_ENV_VARS_TO_CHECK=
)
debug_message("Including cmake vars from: ${_VCPKG_CMAKE_VARS_FILE}")
include("${_VCPKG_CMAKE_VARS_FILE}")
set(VCPKG_DETECTED_CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "${VCPKG_DETECTED_CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES}" PARENT_SCOPE)
set(CURRENT_BUILDTREES_DIR "${_saved_buildtrees_dir}")
endif()
list(FIND VCPKG_DETECTED_CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "${path}" index)
if(NOT index EQUAL -1)
string(REPLACE "${framework}" "-framework ${name}" fixed_line "${fixed_line}")
endif()
endforeach()
string(REPLACE "${line}" "${fixed_line}" targets_content "${targets_content}")
endforeach()
file(WRITE "${targets_file}" "${targets_content}")
endforeach()
endif()
Expand Down

0 comments on commit 96c2367

Please sign in to comment.