Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vcpkg-fixup-cmake-targets] Rewrite the traversal code with -framework NAME on OSX #19629

Closed
3 changes: 1 addition & 2 deletions ports/vcpkg-cmake-config/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"name": "vcpkg-cmake-config",
"version-date": "2021-05-22",
"port-version": 1
"version-date": "2021-08-18"
}
49 changes: 49 additions & 0 deletions ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,55 @@ get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]]
file(WRITE "${main_cmake}" "${contents}")
endforeach()

if (VCPKG_TARGET_IS_OSX)
# 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")
endif()
# For every targets file
foreach(targets_file IN LISTS targets_files)
file(READ "${targets_file}" targets_content)
string(REGEX MATCHALL "INTERFACE_LINK_LIBRARIES[^\n]*\n" matched_lines "${targets_content}")
# For every line begin with `INTERFACE_LINK_LIBRARIES`
string(REGEX MATCH "INTERFACE_LINK_LIBRARIES[^\n]*\n" current_line "${matched_lines}")
while (current_line)
Comment on lines +233 to +236
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it will intercept each line in the list according to the keyword INTERFACE_LINK_LIBRARIES, and replace the fixed content in the original content line by line to prevent incorrect replacement of other content (such as INTERFACE_INCLUDE_DIRECTORIES).

debug_message("current_line: ${current_line}")
set(fixed_line "${current_line}")
string(REGEX MATCHALL [[/[^ ;"]+/[^ ;"/]+\.framework]] frameworks "${current_line}")
# For every value in this 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")
z_vcpkg_get_cmake_vars(cmake_vars_file)
debug_message("Including cmake vars from: ${cmake_vars_file}")
include("${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()
# Replace the fixed content in target file
debug_message("replace \"${current_line}\" with \"${fixed_line}\"")
string(REPLACE "${current_line}" "${fixed_line}" targets_content "${targets_content}")
# Remove this line from list
string(REPLACE "${current_line}" "" matched_lines "${matched_lines}")
# Find the next line
string(REGEX MATCH "INTERFACE_LINK_LIBRARIES[^\n]*\n" current_line "${matched_lines}")
endwhile()
file(WRITE "${targets_file}" "${targets_content}")
endforeach()
endif()

# Remove /debug/<target_path>/ if it's empty.
file(GLOB_RECURSE remaining_files "${debug_share}/*")
if(remaining_files STREQUAL "")
Expand Down
49 changes: 49 additions & 0 deletions scripts/cmake/vcpkg_fixup_cmake_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,55 @@ function(vcpkg_fixup_cmake_targets)
file(WRITE ${MAIN_CMAKE} "${_contents}")
endforeach()

if (VCPKG_TARGET_IS_OSX)
# 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")
endif()
# For every targets file
foreach(targets_file IN LISTS targets_files)
file(READ "${targets_file}" targets_content)
string(REGEX MATCHALL "INTERFACE_LINK_LIBRARIES[^\n]*\n" matched_lines "${targets_content}")
# For every line begin with `INTERFACE_LINK_LIBRARIES`
string(REGEX MATCH "INTERFACE_LINK_LIBRARIES[^\n]*\n" current_line "${matched_lines}")
while (current_line)
debug_message("current_line: ${current_line}")
set(fixed_line "${current_line}")
string(REGEX MATCHALL [[/[^ ;"]+/[^ ;"/]+\.framework]] frameworks "${current_line}")
# For every value in this 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")
z_vcpkg_get_cmake_vars(cmake_vars_file)
debug_message("Including cmake vars from: ${cmake_vars_file}")
include("${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()
# Replace the fixed content in target file
debug_message("replace \"${current_line}\" with \"${fixed_line}\"")
string(REPLACE "${current_line}" "${fixed_line}" targets_content "${targets_content}")
# Remove this line from list
string(REPLACE "${current_line}" "" matched_lines "${matched_lines}")
# Find the next line
string(REGEX MATCH "INTERFACE_LINK_LIBRARIES[^\n]*\n" current_line "${matched_lines}")
endwhile()
file(WRITE "${targets_file}" "${targets_content}")
endforeach()
endif()

# Remove /debug/<target_path>/ if it's empty.
file(GLOB_RECURSE REMAINING_FILES "${DEBUG_SHARE}/*")
if(NOT REMAINING_FILES)
Expand Down
4 changes: 2 additions & 2 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6621,8 +6621,8 @@
"port-version": 0
},
"vcpkg-cmake-config": {
"baseline": "2021-05-22",
"port-version": 1
"baseline": "2021-08-18",
"port-version": 0
},
"vcpkg-gfortran": {
"baseline": "3",
Expand Down
10 changes: 10 additions & 0 deletions versions/v-/vcpkg-cmake-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"versions": [
{
"git-tree": "dd7d67c81c2442c831a298d136b019a2bd138565",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"git-tree": "dd7d67c81c2442c831a298d136b019a2bd138565",
"git-tree": "d4b5ea86aea3416a957fbe2384610feb6106f730",

"version-date": "2021-08-18",
"port-version": 0
},
{
"git-tree": "b3abb12ba8ab43770aea4e5a8d4915319bd295ee",
"version-date": "2021-08-11",
"port-version": 0
},
{
"git-tree": "330cc51bc99c6b71ed5fb51901f6f838684015a5",
"version-date": "2021-05-22",
Expand Down