[scripts|vcpkg_configure_make] Help C(XX)FLAGS survive through libtool (#28349)

* help cflags survive through libtool

* Guard -Xcompiler in case of gcc/gnu

since it doesn't like unknown compiler flags.

* export CMAKE_<lang>_COMPILER_FRONTEND_VARIANT from cmake

* v db and script changes

* also check compiler id

Co-authored-by: Cheney-Wang <850426846@qq.com>
This commit is contained in:
Alexander Neumann 2023-01-07 10:04:32 +01:00 committed by GitHub
parent 8b9ebdccdf
commit 45e66bff9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 8 deletions

View File

@ -25,6 +25,7 @@ set(COMPILERS ${VCPKG_LANGUAGES} RC)
foreach(prog IN LISTS COMPILERS) foreach(prog IN LISTS COMPILERS)
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog}_COMPILER) list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog}_COMPILER)
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog}_COMPILER_ID) list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog}_COMPILER_ID)
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog}_COMPILER_FRONTEND_VARIANT)
endforeach() endforeach()
# Variables to check # Variables to check
foreach(_lang IN LISTS VCPKG_LANGUAGES) foreach(_lang IN LISTS VCPKG_LANGUAGES)

View File

@ -1,6 +1,6 @@
{ {
"name": "vcpkg-cmake-get-vars", "name": "vcpkg-cmake-get-vars",
"version-date": "2022-09-04", "version-date": "2022-12-16",
"documentation": "https://vcpkg.io/en/docs/README.html", "documentation": "https://vcpkg.io/en/docs/README.html",
"license": "MIT", "license": "MIT",
"dependencies": [ "dependencies": [

View File

@ -79,14 +79,25 @@ macro(z_vcpkg_extract_cpp_flags_and_set_cflags_and_cxxflags flag_suffix)
string(REGEX REPLACE " +" " " CPPFLAGS_${flag_suffix} "${CPPFLAGS_${flag_suffix}}") string(REGEX REPLACE " +" " " CPPFLAGS_${flag_suffix} "${CPPFLAGS_${flag_suffix}}")
string(REGEX REPLACE " +" " " CFLAGS_${flag_suffix} "${CFLAGS_${flag_suffix}}") string(REGEX REPLACE " +" " " CFLAGS_${flag_suffix} "${CFLAGS_${flag_suffix}}")
string(REGEX REPLACE " +" " " CXXFLAGS_${flag_suffix} "${CXXFLAGS_${flag_suffix}}") string(REGEX REPLACE " +" " " CXXFLAGS_${flag_suffix} "${CXXFLAGS_${flag_suffix}}")
# libtool has and -R option so we need to guard against -RTC by using -Xcompiler
# while configuring there might be a lot of unknown compiler option warnings due to that
# just ignore them.
string(REGEX REPLACE "((-|/)RTC[^ ]+)" "-Xcompiler \\1" CFLAGS_${flag_suffix} "${CFLAGS_${flag_suffix}}")
string(REGEX REPLACE "((-|/)RTC[^ ]+)" "-Xcompiler \\1" CXXFLAGS_${flag_suffix} "${CXXFLAGS_${flag_suffix}}")
string(STRIP "${CPPFLAGS_${flag_suffix}}" CPPFLAGS_${flag_suffix}) string(STRIP "${CPPFLAGS_${flag_suffix}}" CPPFLAGS_${flag_suffix})
string(STRIP "${CFLAGS_${flag_suffix}}" CFLAGS_${flag_suffix}) string(STRIP "${CFLAGS_${flag_suffix}}" CFLAGS_${flag_suffix})
string(STRIP "${CXXFLAGS_${flag_suffix}}" CXXFLAGS_${flag_suffix}) string(STRIP "${CXXFLAGS_${flag_suffix}}" CXXFLAGS_${flag_suffix})
# libtool tries to filter CFLAGS passed to the link stage via a whitelist.
# that approach is flawed since it fails to pass flags unknown to libtool
# but required for linking to the link stage (e.g. -fsanitize=<x>).
# libtool has an -R option so we need to guard against -RTC by using -Xcompiler
# while configuring there might be a lot of unknown compiler option warnings due to that
# just ignore them.
if(VCPKG_DETECTED_CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" OR VCPKG_DETECTED_CMAKE_C_COMPILER_ID STREQUAL "MSVC")
separate_arguments(CFLAGS_LIST NATIVE_COMMAND "${CFLAGS_${flag_suffix}}")
list(JOIN CFLAGS_LIST " -Xcompiler " CFLAGS_${var_suffix})
string(PREPEND CFLAGS_${var_suffix} "-Xcompiler ")
endif()
if(VCPKG_DETECTED_CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" OR VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
separate_arguments(CXXFLAGS_LIST NATIVE_COMMAND "${CXXFLAGS_${flag_suffix}}")
list(JOIN CXXFLAGS_LIST " -Xcompiler " CXXFLAGS_${var_suffix})
string(PREPEND CXXFLAGS_${var_suffix} "-Xcompiler ")
endif()
debug_message("CPPFLAGS_${flag_suffix}: ${CPPFLAGS_${flag_suffix}}") debug_message("CPPFLAGS_${flag_suffix}: ${CPPFLAGS_${flag_suffix}}")
debug_message("CFLAGS_${flag_suffix}: ${CFLAGS_${flag_suffix}}") debug_message("CFLAGS_${flag_suffix}: ${CFLAGS_${flag_suffix}}")
debug_message("CXXFLAGS_${flag_suffix}: ${CXXFLAGS_${flag_suffix}}") debug_message("CXXFLAGS_${flag_suffix}: ${CXXFLAGS_${flag_suffix}}")

View File

@ -20,7 +20,7 @@ foreach(prog IN LISTS PROGLIST)
endforeach() endforeach()
set(COMPILERS ${VCPKG_LANGUAGES} RC) set(COMPILERS ${VCPKG_LANGUAGES} RC)
foreach(prog IN LISTS COMPILERS) foreach(prog IN LISTS COMPILERS)
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog}_COMPILER CMAKE_${prog}_COMPILER_ID) list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog}_COMPILER CMAKE_${prog}_COMPILER_ID CMAKE_${prog}_COMPILER_FRONTEND_VARIANT)
endforeach() endforeach()
# Variables to check # Variables to check
foreach(_lang IN LISTS VCPKG_LANGUAGES) foreach(_lang IN LISTS VCPKG_LANGUAGES)

View File

@ -7889,7 +7889,7 @@
"port-version": 1 "port-version": 1
}, },
"vcpkg-cmake-get-vars": { "vcpkg-cmake-get-vars": {
"baseline": "2022-09-04", "baseline": "2022-12-16",
"port-version": 0 "port-version": 0
}, },
"vcpkg-get-python-packages": { "vcpkg-get-python-packages": {

View File

@ -1,5 +1,10 @@
{ {
"versions": [ "versions": [
{
"git-tree": "bad453fe7f58edb2e8d0093692dcaa52347e446c",
"version-date": "2022-12-16",
"port-version": 0
},
{ {
"git-tree": "898079c6021ced406d7c75f852e67a5e8861db9b", "git-tree": "898079c6021ced406d7c75f852e67a5e8861db9b",
"version-date": "2022-09-04", "version-date": "2022-09-04",