From 52fc0d8c1e2cbd12c9907284566f5c17e5ef0d12 Mon Sep 17 00:00:00 2001 From: Osyotr Date: Fri, 4 Oct 2024 01:33:09 +0300 Subject: [PATCH] [vcpkg-cmake-get-vars] Handle CMAKE_SYSROOT_COMPILE/CMAKE_SYSROOT_LINK (#41116) --- .../cmake_get_vars/CMakeLists.txt | 31 +++++++++++++++++-- ports/vcpkg-cmake-get-vars/vcpkg.json | 2 +- scripts/get_cmake_vars/CMakeLists.txt | 27 ++++++++++++++-- versions/baseline.json | 2 +- versions/v-/vcpkg-cmake-get-vars.json | 5 +++ 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/ports/vcpkg-cmake-get-vars/cmake_get_vars/CMakeLists.txt b/ports/vcpkg-cmake-get-vars/cmake_get_vars/CMakeLists.txt index a6433e8e86..71aa1384e7 100644 --- a/ports/vcpkg-cmake-get-vars/cmake_get_vars/CMakeLists.txt +++ b/ports/vcpkg-cmake-get-vars/cmake_get_vars/CMakeLists.txt @@ -159,12 +159,37 @@ if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) string(APPEND EXTRA_FLAGS " ${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN} \"${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}\"") endif() endif() -if(CMAKE_SYSROOT AND CMAKE_CXX_COMPILE_OPTIONS_SYSROOT) - string(APPEND EXTRA_FLAGS " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}\"") + +set(extra_flags_compile "") +set(extra_flags_link "") +if(CMAKE_CXX_COMPILE_OPTIONS_SYSROOT) + if(CMAKE_SYSROOT_COMPILE) + string(APPEND extra_flags_compile " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT_COMPILE}\"") + elseif(CMAKE_SYSROOT) + string(APPEND extra_flags_compile " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}\"") + endif() + + if(CMAKE_SYSROOT_LINK) + string(APPEND extra_flags_link " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT_LINK}\"") + elseif(CMAKE_SYSROOT) + string(APPEND extra_flags_link " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}\"") + endif() endif() -foreach(flags ${VCPKG_LANGUAGES} SHARED_LINKER EXE_LINKER STATIC_LINKER MODULE_LINKER) +set(flags_to_add_target_compile "${VCPKG_LANGUAGES}") +set(flags_to_add_target_link SHARED_LINKER EXE_LINKER STATIC_LINKER MODULE_LINKER) + +foreach(flags IN LISTS flags_to_add_target_compile flags_to_add_target_link) set(${flags}_FLAGS "${target_param} ${CMAKE_${flags}_FLAGS} ${CMAKE_${flags}_FLAGS_${VCPKG_CONFIGS}} ${EXTRA_FLAGS}") +endforeach() + +foreach(flags IN LISTS flags_to_add_target_compile) + string(APPEND ${flags}_FLAGS " ${extra_flags_compile}") + string(STRIP ${flags}_FLAGS "${${flags}_FLAGS}") +endforeach() + +foreach(flags IN LISTS flags_to_add_target_link) + string(APPEND ${flags}_FLAGS " ${extra_flags_link}") string(STRIP ${flags}_FLAGS "${${flags}_FLAGS}") endforeach() diff --git a/ports/vcpkg-cmake-get-vars/vcpkg.json b/ports/vcpkg-cmake-get-vars/vcpkg.json index f6ed57a494..5396be4f4d 100644 --- a/ports/vcpkg-cmake-get-vars/vcpkg.json +++ b/ports/vcpkg-cmake-get-vars/vcpkg.json @@ -1,6 +1,6 @@ { "name": "vcpkg-cmake-get-vars", - "version-date": "2023-12-31", + "version-date": "2024-09-22", "documentation": "https://vcpkg.io/en/docs/README.html", "license": "MIT", "dependencies": [ diff --git a/scripts/get_cmake_vars/CMakeLists.txt b/scripts/get_cmake_vars/CMakeLists.txt index 934515dd18..bf1679d3da 100644 --- a/scripts/get_cmake_vars/CMakeLists.txt +++ b/scripts/get_cmake_vars/CMakeLists.txt @@ -111,8 +111,21 @@ if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) string(APPEND extra_flags " ${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN} \"${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}\"") endif() endif() -if(CMAKE_SYSROOT AND CMAKE_CXX_COMPILE_OPTIONS_SYSROOT) - string(APPEND extra_flags " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}\"") + +set(extra_flags_compile "") +set(extra_flags_link "") +if(CMAKE_CXX_COMPILE_OPTIONS_SYSROOT) + if(CMAKE_SYSROOT_COMPILE) + string(APPEND extra_flags_compile " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT_COMPILE}\"") + elseif(CMAKE_SYSROOT) + string(APPEND extra_flags_compile " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}\"") + endif() + + if(CMAKE_SYSROOT_LINK) + string(APPEND extra_flags_link " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT_LINK}\"") + elseif(CMAKE_SYSROOT) + string(APPEND extra_flags_link " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}\"") + endif() endif() macro(_vcpkg_adjust_flags flag_var) @@ -142,7 +155,9 @@ macro(_vcpkg_adjust_flags flag_var) endif() unset(flags_to_add_osx_arch_sysroot) endif() - set(flags_to_add_target "${VCPKG_LANG_FLAGS}" CMAKE_SHARED_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_EXE_LINKER_FLAGS) + set(flags_to_add_target_compile "${VCPKG_LANG_FLAGS}") + set(flags_to_add_target_link CMAKE_SHARED_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_EXE_LINKER_FLAGS) + set(flags_to_add_target "${flags_to_add_target_compile}" "${flags_to_add_target_link}") list(GET VCPKG_LANGUAGES 0 lang) if(CMAKE_${lang}_COMPILER_TARGET AND "${flag_var}" IN_LIST flags_to_add_target) if (CMAKE_${lang}_COMPILER_ID STREQUAL Clang) @@ -154,6 +169,12 @@ macro(_vcpkg_adjust_flags flag_var) if("${flag_var}" IN_LIST flags_to_add_target) string(APPEND ${flag_var} " ${extra_flags}") endif() + if("${flag_var}" IN_LIST flags_to_add_target_compile) + string(APPEND ${flag_var} " ${extra_flags_compile}") + endif() + if("${flag_var}" IN_LIST flags_to_add_target_link) + string(APPEND ${flag_var} " ${extra_flags_link}") + endif() unset(lang) unset(flags_to_add_target) endmacro() diff --git a/versions/baseline.json b/versions/baseline.json index 5399b5782a..e2a31cd073 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -9285,7 +9285,7 @@ "port-version": 0 }, "vcpkg-cmake-get-vars": { - "baseline": "2023-12-31", + "baseline": "2024-09-22", "port-version": 0 }, "vcpkg-get-python": { diff --git a/versions/v-/vcpkg-cmake-get-vars.json b/versions/v-/vcpkg-cmake-get-vars.json index 32fcd9f044..c5d4cf2759 100644 --- a/versions/v-/vcpkg-cmake-get-vars.json +++ b/versions/v-/vcpkg-cmake-get-vars.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "f23148add155147f3d95ae622d3b0031beb25acf", + "version-date": "2024-09-22", + "port-version": 0 + }, { "git-tree": "725c841810ceb8de33da68ea879eb8f0b4d6c94c", "version-date": "2023-12-31",