diff --git a/docs/maintainers/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.md b/docs/maintainers/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.md index 444b12853a7255..469e0b197a8072 100644 --- a/docs/maintainers/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.md +++ b/docs/maintainers/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.md @@ -36,11 +36,13 @@ and applies a rather simply correction which in some cases will yield the wrong ## How it Works 1. Moves `/debug//*targets-debug.cmake` to `/share/${PACKAGE_NAME}`. -2. Removes `/debug//*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.cmake`. ## Examples diff --git a/ports/tmx/portfile.cmake b/ports/tmx/portfile.cmake index 1ddf5a4f2020c5..ee76169108b2d6 100644 --- a/ports/tmx/portfile.cmake +++ b/ports/tmx/portfile.cmake @@ -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" diff --git a/ports/tmx/vcpkg.json b/ports/tmx/vcpkg.json index f21eba4edd8abf..764177045fe678 100644 --- a/ports/tmx/vcpkg.json +++ b/ports/tmx/vcpkg.json @@ -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", diff --git a/ports/vcpkg-cmake-config/vcpkg.json b/ports/vcpkg-cmake-config/vcpkg.json index 21a2f316c90d3b..a99271b63c4582 100644 --- a/ports/vcpkg-cmake-config/vcpkg.json +++ b/ports/vcpkg-cmake-config/vcpkg.json @@ -1,4 +1,4 @@ { "name": "vcpkg-cmake-config", - "version-date": "2022-01-30" + "version-date": "2022-02-06" } diff --git a/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake b/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake index 7245130e231fc6..4045ae1eae5093 100644 --- a/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake +++ b/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake @@ -35,11 +35,13 @@ and applies a rather simply correction which in some cases will yield the wrong ## How it Works 1. Moves `/debug//*targets-debug.cmake` to `/share/${PACKAGE_NAME}`. -2. Removes `/debug//*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.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// 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 [[^\\[$]<\\[$]:]]) + list(TRANSFORM release_libs REPLACE [[^\\[$]<\\[$]>:(.*)>$]] "\\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 [[^\\[$]<\\[$]>:]]) + list(TRANSFORM debug_libs REPLACE [[^\\[$]<\\[$]:(.*)>$]] "\\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 "\\\$<\\\$>:${release_lib}>") + endif() + if(debug_lib) + list(APPEND merged_libs "\\\$<\\\$:${debug_lib}>") + endif() + endif() + endforeach() + set("${out_var}" "${merged_libs}" PARENT_SCOPE) +endfunction() diff --git a/scripts/test_ports/unit-test-cmake/portfile.cmake b/scripts/test_ports/unit-test-cmake/portfile.cmake index 497cb18a383b09..d506ebaf66374a 100644 --- a/scripts/test_ports/unit-test-cmake/portfile.cmake +++ b/scripts/test_ports/unit-test-cmake/portfile.cmake @@ -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") diff --git a/scripts/test_ports/unit-test-cmake/test-z_vcpkg_cmake_config_fixup_merge.cmake b/scripts/test_ports/unit-test-cmake/test-z_vcpkg_cmake_config_fixup_merge.cmake new file mode 100644 index 00000000000000..8809af46ff577d --- /dev/null +++ b/scripts/test_ports/unit-test-cmake/test-z_vcpkg_cmake_config_fixup_merge.cmake @@ -0,0 +1,56 @@ +# z_vcpkg_cmake_config_fixup_merge( ) +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 [[\$<\$>:A>;\$<\$: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;\$<\$>: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;\$<\$: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 [[\$<\$>:A>;\$<\$:C>;\$<\$>:C>]] +) + +set(release_libs [[\$<\$>:A>;\$<\$:B>]]) +set(debug_libs [[\$<\$>:A>;\$<\$:B>]]) +unit_test_check_variable_equal( + [[z_vcpkg_cmake_config_fixup_merge(merged release_libs debug_libs)]] + merged [[\$<\$>:A>;\$<\$: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 [[\$<\$>:o1>;\$<\$: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 [[\$<\$:d2>;\$<\$>:o1>]] +) diff --git a/scripts/test_ports/unit-test-cmake/vcpkg.json b/scripts/test_ports/unit-test-cmake/vcpkg.json index 366d1d7a93fb7c..28cacbc8f34cf8 100644 --- a/scripts/test_ports/unit-test-cmake/vcpkg.json +++ b/scripts/test_ports/unit-test-cmake/vcpkg.json @@ -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" } diff --git a/versions/baseline.json b/versions/baseline.json index 17aabba0090fd2..a0054f4d406448 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -6950,7 +6950,7 @@ }, "tmx": { "baseline": "1.2.0", - "port-version": 0 + "port-version": 1 }, "tmxlite": { "baseline": "1.3.0", @@ -7189,7 +7189,7 @@ "port-version": 0 }, "vcpkg-cmake-config": { - "baseline": "2022-01-30", + "baseline": "2022-02-06", "port-version": 0 }, "vcpkg-gfortran": { diff --git a/versions/t-/tmx.json b/versions/t-/tmx.json index d362504b41da52..862004cd4473ae 100644 --- a/versions/t-/tmx.json +++ b/versions/t-/tmx.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "1b0ec7979f9a75aab71e9488940a4beff74bd745", + "version": "1.2.0", + "port-version": 1 + }, { "git-tree": "207601a8ff1891880a88013e3b36ea0f81979010", "version": "1.2.0", diff --git a/versions/v-/vcpkg-cmake-config.json b/versions/v-/vcpkg-cmake-config.json index ea72bd4f76a331..208504f941a30c 100644 --- a/versions/v-/vcpkg-cmake-config.json +++ b/versions/v-/vcpkg-cmake-config.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "24dc7dfc704406e9f745f033643dc25f56e4ca18", + "version-date": "2022-02-06", + "port-version": 0 + }, { "git-tree": "fea8f92ffa5e14c7111fe526f8cc93ecd8f9dbf0", "version-date": "2022-01-30",