mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-04 03:09:07 +08:00
[vcpkg-cmake-config] Merge INTERFACE_LINK_LIBRARIES configurations (#22546)
* Merge INTERFACE_LINK_LIBRARIES configurations Direct references to binaries must match the active build type when used. * Update tmx for cmake_config_fixup * Update versions * Prevent repeated fixup of the same file * Don't change line structure * Update versions * CI * Apply CR suggestion Co-authored-by: nicole mazzuca <mazzucan@outlook.com> * Update versions * Fixup CR suggestion * Update versions * Update versions Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
This commit is contained in:
parent
642a21c0f3
commit
3565cab797
@ -36,11 +36,13 @@ and applies a rather simply correction which in some cases will yield the wrong
|
||||
## How it Works
|
||||
|
||||
1. Moves `/debug/<CONFIG_PATH>/*targets-debug.cmake` to `/share/${PACKAGE_NAME}`.
|
||||
2. Removes `/debug/<CONFIG_PATH>/*config.cmake`.
|
||||
3. Transform all references matching `/bin/*.exe` to `/${TOOLS_PATH}/*.exe` on Windows.
|
||||
4. Transform all references matching `/bin/*` to `/${TOOLS_PATH}/*` on other platforms.
|
||||
5. Fixes `${_IMPORT_PREFIX}` in auto generated targets.
|
||||
6. Replace `${CURRENT_INSTALLED_DIR}` with `${_IMPORT_PREFIX}` in configs and targets.
|
||||
2. Transforms all references matching `/bin/*.exe` to `/${TOOLS_PATH}/*.exe` on Windows.
|
||||
3. Transforms all references matching `/bin/*` to `/${TOOLS_PATH}/*` on other platforms.
|
||||
4. Fixes `${_IMPORT_PREFIX}` in auto generated targets.
|
||||
5. Replaces `${CURRENT_INSTALLED_DIR}` with `${_IMPORT_PREFIX}` in configs.
|
||||
6. Merges INTERFACE_LINK_LIBRARIES of release and debug configurations.
|
||||
7. Replaces `${CURRENT_INSTALLED_DIR}` with `${VCPKG_IMPORT_PREFIX}` in targets.
|
||||
8. Removes `/debug/<CONFIG_PATH>/*config.cmake`.
|
||||
|
||||
## Examples
|
||||
|
||||
|
@ -13,9 +13,7 @@ vcpkg_cmake_configure(
|
||||
vcpkg_cmake_install()
|
||||
vcpkg_copy_pdbs()
|
||||
|
||||
file(RENAME "${CURRENT_PACKAGES_DIR}/lib/cmake/tmx/tmxExports.cmake" "${CURRENT_PACKAGES_DIR}/lib/cmake/tmx/tmxTargets.cmake")
|
||||
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/tmx)
|
||||
file(RENAME "${CURRENT_PACKAGES_DIR}/share/tmx/tmxTargets.cmake" "${CURRENT_PACKAGES_DIR}/share/tmx/tmxExports.cmake")
|
||||
|
||||
file(REMOVE_RECURSE
|
||||
"${CURRENT_PACKAGES_DIR}/debug/include"
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": "tmx",
|
||||
"version": "1.2.0",
|
||||
"port-version": 1,
|
||||
"description": "A portable C library to load tiled maps in your games.",
|
||||
"dependencies": [
|
||||
"libxml2",
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"name": "vcpkg-cmake-config",
|
||||
"version-date": "2022-01-30"
|
||||
"version-date": "2022-02-06"
|
||||
}
|
||||
|
@ -35,11 +35,13 @@ and applies a rather simply correction which in some cases will yield the wrong
|
||||
## How it Works
|
||||
|
||||
1. Moves `/debug/<CONFIG_PATH>/*targets-debug.cmake` to `/share/${PACKAGE_NAME}`.
|
||||
2. Removes `/debug/<CONFIG_PATH>/*config.cmake`.
|
||||
3. Transform all references matching `/bin/*.exe` to `/${TOOLS_PATH}/*.exe` on Windows.
|
||||
4. Transform all references matching `/bin/*` to `/${TOOLS_PATH}/*` on other platforms.
|
||||
5. Fixes `${_IMPORT_PREFIX}` in auto generated targets.
|
||||
6. Replace `${CURRENT_INSTALLED_DIR}` with `${_IMPORT_PREFIX}` in configs and targets.
|
||||
2. Transforms all references matching `/bin/*.exe` to `/${TOOLS_PATH}/*.exe` on Windows.
|
||||
3. Transforms all references matching `/bin/*` to `/${TOOLS_PATH}/*` on other platforms.
|
||||
4. Fixes `${_IMPORT_PREFIX}` in auto generated targets.
|
||||
5. Replaces `${CURRENT_INSTALLED_DIR}` with `${_IMPORT_PREFIX}` in configs.
|
||||
6. Merges INTERFACE_LINK_LIBRARIES of release and debug configurations.
|
||||
7. Replaces `${CURRENT_INSTALLED_DIR}` with `${VCPKG_IMPORT_PREFIX}` in targets.
|
||||
8. Removes `/debug/<CONFIG_PATH>/*config.cmake`.
|
||||
|
||||
## Examples
|
||||
|
||||
@ -134,16 +136,6 @@ function(vcpkg_cmake_config_fixup)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE unused_files
|
||||
"${debug_share}/*[Tt]argets.cmake"
|
||||
"${debug_share}/*[Cc]onfig.cmake"
|
||||
"${debug_share}/*[Cc]onfigVersion.cmake"
|
||||
"${debug_share}/*[Cc]onfig-version.cmake"
|
||||
)
|
||||
foreach(unused_file IN LISTS unused_files)
|
||||
file(REMOVE "${unused_file}")
|
||||
endforeach()
|
||||
|
||||
file(GLOB_RECURSE release_targets
|
||||
"${release_share}/*-release.cmake"
|
||||
)
|
||||
@ -173,8 +165,16 @@ function(vcpkg_cmake_config_fixup)
|
||||
endif()
|
||||
|
||||
#Fix ${_IMPORT_PREFIX} and absolute paths in cmake generated targets and configs;
|
||||
#Since those can be renamed we have to check in every *.cmake
|
||||
#Since those can be renamed we have to check in every *.cmake, but only once.
|
||||
file(GLOB_RECURSE main_cmakes "${release_share}/*.cmake")
|
||||
if(NOT DEFINED Z_VCPKG_CMAKE_CONFIG_ALREADY_FIXED_UP)
|
||||
vcpkg_list(SET Z_VCPKG_CMAKE_CONFIG_ALREADY_FIXED_UP)
|
||||
endif()
|
||||
foreach(already_fixed_up IN LISTS Z_VCPKG_CMAKE_CONFIG_ALREADY_FIXED_UP)
|
||||
vcpkg_list(REMOVE_ITEM main_cmakes "${already_fixed_up}")
|
||||
endforeach()
|
||||
vcpkg_list(APPEND Z_VCPKG_CMAKE_CONFIG_ALREADY_FIXED_UP ${main_cmakes})
|
||||
set(Z_VCPKG_CMAKE_CONFIG_ALREADY_FIXED_UP "${Z_VCPKG_CMAKE_CONFIG_ALREADY_FIXED_UP}" CACHE INTERNAL "")
|
||||
|
||||
foreach(main_cmake IN LISTS main_cmakes)
|
||||
file(READ "${main_cmake}" contents)
|
||||
@ -205,6 +205,38 @@ get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]]
|
||||
contents "${contents}") # This is a meson-related workaround, see https://github.com/mesonbuild/meson/issues/6955
|
||||
endif()
|
||||
|
||||
# Merge release and debug configurations of target property INTERFACE_LINK_LIBRARIES.
|
||||
string(REPLACE "${release_share}/" "${debug_share}/" debug_cmake "${main_cmake}")
|
||||
if(DEFINED VCPKG_BUILD_TYPE)
|
||||
# Skip. Warning: A release-only port in a dual-config installation
|
||||
# may pull release dependencies into the debug configuration.
|
||||
elseif(NOT contents MATCHES "INTERFACE_LINK_LIBRARIES")
|
||||
# Skip. No relevant properties.
|
||||
elseif(NOT contents MATCHES "# Generated CMake target import file\\.")
|
||||
# Skip. No safe assumptions about a matching debug import file.
|
||||
elseif(NOT EXISTS "${debug_cmake}")
|
||||
message(SEND_ERROR "Did not find a debug import file matching '${main_cmake}'")
|
||||
else()
|
||||
file(READ "${debug_cmake}" debug_contents)
|
||||
while(contents MATCHES "set_target_properties\\(([^ \$]*) PROPERTIES[^)]*\\)")
|
||||
set(matched_command "${CMAKE_MATCH_0}")
|
||||
string(REPLACE "+" "\\+" target "${CMAKE_MATCH_1}")
|
||||
if(NOT debug_contents MATCHES "set_target_properties\\(${target} PROPERTIES[^)]*\\)")
|
||||
message(SEND_ERROR "Did not find a debug configuration for target '${target}'.")
|
||||
endif()
|
||||
set(debug_command "${CMAKE_MATCH_0}")
|
||||
string(REGEX MATCH " INTERFACE_LINK_LIBRARIES \"([^\"]*)\"" release_line "${matched_command}")
|
||||
set(release_libs "${CMAKE_MATCH_1}")
|
||||
string(REGEX MATCH " INTERFACE_LINK_LIBRARIES \"([^\"]*)\"" debug_line "${debug_command}")
|
||||
set(debug_libs "${CMAKE_MATCH_1}")
|
||||
z_vcpkg_cmake_config_fixup_merge(merged_libs release_libs debug_libs)
|
||||
string(REPLACE "${release_line}" " INTERFACE_LINK_LIBRARIES \"${merged_libs}\"" updated_command "${matched_command}")
|
||||
string(REPLACE "set_target_properties" "set_target_properties::done" updated_command "${updated_command}") # Prevend 2nd match
|
||||
string(REPLACE "${matched_command}" "${updated_command}" contents "${contents}")
|
||||
endwhile()
|
||||
string(REPLACE "set_target_properties::done" "set_target_properties" contents "${contents}") # Restore original command
|
||||
endif()
|
||||
|
||||
#Fix absolute paths to installed dir with ones relative to ${CMAKE_CURRENT_LIST_DIR}
|
||||
#This happens if vcpkg built libraries are directly linked to a target instead of using
|
||||
#an imported target.
|
||||
@ -223,6 +255,16 @@ get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]]
|
||||
file(WRITE "${main_cmake}" "${contents}")
|
||||
endforeach()
|
||||
|
||||
file(GLOB_RECURSE unused_files
|
||||
"${debug_share}/*[Tt]argets.cmake"
|
||||
"${debug_share}/*[Cc]onfig.cmake"
|
||||
"${debug_share}/*[Cc]onfigVersion.cmake"
|
||||
"${debug_share}/*[Cc]onfig-version.cmake"
|
||||
)
|
||||
foreach(unused_file IN LISTS unused_files)
|
||||
file(REMOVE "${unused_file}")
|
||||
endforeach()
|
||||
|
||||
# Remove /debug/<target_path>/ if it's empty.
|
||||
file(GLOB_RECURSE remaining_files "${debug_share}/*")
|
||||
if(remaining_files STREQUAL "")
|
||||
@ -235,3 +277,36 @@ get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]]
|
||||
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Merges link interface library lists for release and debug
|
||||
# into a single expression which use generator expression as necessary.
|
||||
function(z_vcpkg_cmake_config_fixup_merge out_var release_var debug_var)
|
||||
set(release_libs "VCPKG;${${release_var}}")
|
||||
string(REGEX REPLACE ";optimized;([^;]*)" ";\\1" release_libs "${release_libs}")
|
||||
string(REGEX REPLACE ";debug;([^;]*)" ";" release_libs "${release_libs}")
|
||||
list(REMOVE_AT release_libs 0)
|
||||
list(FILTER release_libs EXCLUDE REGEX [[^\\[$]<\\[$]<CONFIG:DEBUG>:]])
|
||||
list(TRANSFORM release_libs REPLACE [[^\\[$]<\\[$]<NOT:\\[$]<CONFIG:DEBUG>>:(.*)>$]] "\\1")
|
||||
|
||||
set(debug_libs "VCPKG;${${debug_var}}")
|
||||
string(REGEX REPLACE ";optimized;([^;]*)" ";" debug_libs "${debug_libs}")
|
||||
string(REGEX REPLACE ";debug;([^;]*)" ";\\1" debug_libs "${debug_libs}")
|
||||
list(REMOVE_AT debug_libs 0)
|
||||
list(FILTER debug_libs EXCLUDE REGEX [[^\\[$]<\\[$]<NOT:\\[$]<CONFIG:DEBUG>>:]])
|
||||
list(TRANSFORM debug_libs REPLACE [[^\\[$]<\\[$]<CONFIG:DEBUG>:(.*)>$]] "\\1")
|
||||
|
||||
set(merged_libs "")
|
||||
foreach(release_lib debug_lib IN ZIP_LISTS release_libs debug_libs)
|
||||
if(release_lib STREQUAL debug_lib)
|
||||
list(APPEND merged_libs "${release_lib}")
|
||||
else()
|
||||
if(release_lib)
|
||||
list(APPEND merged_libs "\\\$<\\\$<NOT:\\\$<CONFIG:DEBUG>>:${release_lib}>")
|
||||
endif()
|
||||
if(debug_lib)
|
||||
list(APPEND merged_libs "\\\$<\\\$<CONFIG:DEBUG>:${debug_lib}>")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
set("${out_var}" "${merged_libs}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
@ -145,6 +145,9 @@ endif()
|
||||
if("function-arguments" IN_LIST FEATURES)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/test-z_vcpkg_function_arguments.cmake")
|
||||
endif()
|
||||
if("merge-libs" IN_LIST FEATURES)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/test-z_vcpkg_cmake_config_fixup_merge.cmake")
|
||||
endif()
|
||||
|
||||
if(Z_VCPKG_UNIT_TEST_HAS_ERROR)
|
||||
_message(FATAL_ERROR "At least one test failed")
|
||||
|
@ -0,0 +1,56 @@
|
||||
# z_vcpkg_cmake_config_fixup_merge(<out_list> <release_list> <debug_list>)
|
||||
set(release_libs namespace::C++_shared)
|
||||
set(debug_libs namespace::C++_shared)
|
||||
unit_test_check_variable_equal(
|
||||
[[z_vcpkg_cmake_config_fixup_merge(merged release_libs debug_libs)]]
|
||||
merged "namespace::C++_shared"
|
||||
)
|
||||
|
||||
set(release_libs A)
|
||||
set(debug_libs B)
|
||||
unit_test_check_variable_equal(
|
||||
[[z_vcpkg_cmake_config_fixup_merge(merged release_libs debug_libs)]]
|
||||
merged [[\$<\$<NOT:\$<CONFIG:DEBUG>>:A>;\$<\$<CONFIG:DEBUG>:B>]]
|
||||
)
|
||||
|
||||
set(release_libs A B)
|
||||
set(debug_libs A )
|
||||
unit_test_check_variable_equal(
|
||||
[[z_vcpkg_cmake_config_fixup_merge(merged release_libs debug_libs)]]
|
||||
merged [[A;\$<\$<NOT:\$<CONFIG:DEBUG>>:B>]]
|
||||
)
|
||||
|
||||
set(release_libs A )
|
||||
set(debug_libs A B)
|
||||
unit_test_check_variable_equal(
|
||||
[[z_vcpkg_cmake_config_fixup_merge(merged release_libs debug_libs)]]
|
||||
merged [[A;\$<\$<CONFIG:DEBUG>:B>]]
|
||||
)
|
||||
|
||||
set(release_libs A C)
|
||||
set(debug_libs C)
|
||||
unit_test_check_variable_equal(
|
||||
[[z_vcpkg_cmake_config_fixup_merge(merged release_libs debug_libs)]]
|
||||
merged [[\$<\$<NOT:\$<CONFIG:DEBUG>>:A>;\$<\$<CONFIG:DEBUG>:C>;\$<\$<NOT:\$<CONFIG:DEBUG>>:C>]]
|
||||
)
|
||||
|
||||
set(release_libs [[\$<\$<NOT:\$<CONFIG:DEBUG>>:A>;\$<\$<CONFIG:DEBUG>:B>]])
|
||||
set(debug_libs [[\$<\$<NOT:\$<CONFIG:DEBUG>>:A>;\$<\$<CONFIG:DEBUG>:B>]])
|
||||
unit_test_check_variable_equal(
|
||||
[[z_vcpkg_cmake_config_fixup_merge(merged release_libs debug_libs)]]
|
||||
merged [[\$<\$<NOT:\$<CONFIG:DEBUG>>:A>;\$<\$<CONFIG:DEBUG>:B>]]
|
||||
)
|
||||
|
||||
set(release_libs optimized o1 debug d1)
|
||||
set(debug_libs optimized o2 debug d2)
|
||||
unit_test_check_variable_equal(
|
||||
[[z_vcpkg_cmake_config_fixup_merge(merged release_libs debug_libs)]]
|
||||
merged [[\$<\$<NOT:\$<CONFIG:DEBUG>>:o1>;\$<\$<CONFIG:DEBUG>:d2>]]
|
||||
)
|
||||
|
||||
set(release_libs debug d1 optimized o1)
|
||||
set(debug_libs debug d2 optimized o2)
|
||||
unit_test_check_variable_equal(
|
||||
[[z_vcpkg_cmake_config_fixup_merge(merged release_libs debug_libs)]]
|
||||
merged [[\$<\$<CONFIG:DEBUG>:d2>;\$<\$<NOT:\$<CONFIG:DEBUG>>:o1>]]
|
||||
)
|
@ -18,6 +18,15 @@
|
||||
"list": {
|
||||
"description": "Test the vcpkg_list function"
|
||||
},
|
||||
"merge-libs": {
|
||||
"description": "Test the z_vcpkg_cmake_config_fixup_merge_lists function",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "vcpkg-cmake-config",
|
||||
"host": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"minimum-required": {
|
||||
"description": "Test the vcpkg_minimum_required function"
|
||||
}
|
||||
|
@ -6954,7 +6954,7 @@
|
||||
},
|
||||
"tmx": {
|
||||
"baseline": "1.2.0",
|
||||
"port-version": 0
|
||||
"port-version": 1
|
||||
},
|
||||
"tmxlite": {
|
||||
"baseline": "1.3.0",
|
||||
@ -7193,7 +7193,7 @@
|
||||
"port-version": 0
|
||||
},
|
||||
"vcpkg-cmake-config": {
|
||||
"baseline": "2022-01-30",
|
||||
"baseline": "2022-02-06",
|
||||
"port-version": 0
|
||||
},
|
||||
"vcpkg-gfortran": {
|
||||
|
@ -1,5 +1,10 @@
|
||||
{
|
||||
"versions": [
|
||||
{
|
||||
"git-tree": "1b0ec7979f9a75aab71e9488940a4beff74bd745",
|
||||
"version": "1.2.0",
|
||||
"port-version": 1
|
||||
},
|
||||
{
|
||||
"git-tree": "207601a8ff1891880a88013e3b36ea0f81979010",
|
||||
"version": "1.2.0",
|
||||
|
@ -1,5 +1,10 @@
|
||||
{
|
||||
"versions": [
|
||||
{
|
||||
"git-tree": "24dc7dfc704406e9f745f033643dc25f56e4ca18",
|
||||
"version-date": "2022-02-06",
|
||||
"port-version": 0
|
||||
},
|
||||
{
|
||||
"git-tree": "fea8f92ffa5e14c7111fe526f8cc93ecd8f9dbf0",
|
||||
"version-date": "2022-01-30",
|
||||
|
Loading…
Reference in New Issue
Block a user