[meson] fix windows linker detection (#22032)

* fix meson linker detection .....

* bit of code cleanup in vcpkg_configure_meson

* forgot the version stuff

* put cmake back on path because meson is buggy as hell
This commit is contained in:
Alexander Neumann 2021-12-17 07:47:16 +01:00 committed by GitHub
parent 7267752414
commit 8060230922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 66 deletions

View File

@ -0,0 +1,25 @@
diff --git a/tools/meson/mesonbuild/compilers/detect.py b/tools/meson/mesonbuild/compilers/detect.py
index 1eacecfa8..74668da1a 100644
--- a/tools/meson/mesonbuild/compilers/detect.py
+++ b/tools/meson/mesonbuild/compilers/detect.py
@@ -292,7 +292,7 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker
linkers = default_linkers
popen_exceptions = {}
for linker in linkers:
- if not {'lib', 'lib.exe', 'llvm-lib', 'llvm-lib.exe', 'xilib', 'xilib.exe'}.isdisjoint(linker):
+ if any(os.path.basename(x) in {'lib', 'lib.exe', 'llvm-lib', 'llvm-lib.exe', 'xilib', 'xilib.exe'} for x in linker):
arg = '/?'
elif not {'ar2000', 'ar2000.exe'}.isdisjoint(linker):
arg = '?'
diff --git a/tools/meson/mesonbuild/linkers/detect.py b/tools/meson/mesonbuild/linkers/detect.py
index 0bfd7083b..323801d9a 100644
--- a/tools/meson/mesonbuild/linkers/detect.py
+++ b/tools/meson/mesonbuild/linkers/detect.py
@@ -72,6 +72,7 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
override = [] # type: T.List[str]
value = env.lookup_binary_entry(for_machine, comp_class.language + '_ld')
if value is not None:
+ compiler = value
override = comp_class.use_linker_args(value[0])
check_args += override

View File

@ -47,6 +47,7 @@ if(NOT "${program}")
z_vcpkg_apply_patches( z_vcpkg_apply_patches(
SOURCE_PATH "${CURRENT_PACKAGES_DIR}" SOURCE_PATH "${CURRENT_PACKAGES_DIR}"
PATCHES meson-intl.patch PATCHES meson-intl.patch
fix_linker_detection.patch
) )
endif() endif()

View File

@ -1,6 +1,7 @@
{ {
"name": "vcpkg-tool-meson", "name": "vcpkg-tool-meson",
"version": "0.60.2", "version": "0.60.2",
"port-version": 1,
"description": "Meson build system", "description": "Meson build system",
"homepage": "https://github.com/mesonbuild/meson", "homepage": "https://github.com/mesonbuild/meson",
"supports": "native" "supports": "native"

View File

@ -40,45 +40,72 @@ This command supplies many common arguments to Meson. To see the full list, exam
* [libepoxy](https://github.com/Microsoft/vcpkg/blob/master/ports/libepoxy/portfile.cmake) * [libepoxy](https://github.com/Microsoft/vcpkg/blob/master/ports/libepoxy/portfile.cmake)
#]===] #]===]
function(z_vcpkg_meson_generate_native_file additional_binaries) #https://mesonbuild.com/Native-environments.html function(z_vcpkg_append_proglist var_to_append additional_binaries)
set(native_config "[binaries]\n") string(APPEND "${var_to_append}" "[binaries]\n")
#set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT)
if(VCPKG_TARGET_IS_WINDOWS) if(VCPKG_TARGET_IS_WINDOWS)
set(proglist MT) set(proglist MT AR)
else() else()
set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT) set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT)
endif() endif()
foreach(prog IN LISTS proglist) foreach(prog IN LISTS proglist)
if(VCPKG_DETECTED_CMAKE_${prog}) if(VCPKG_DETECTED_CMAKE_${prog})
string(TOLOWER "${prog}" proglower) if(meson_${prog})
string(APPEND native_config "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n") string(APPEND "${var_to_append}" "${meson_${prog}} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n")
else()
string(TOLOWER "${prog}" proglower)
string(APPEND "${var_to_append}" "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n")
endif()
endif() endif()
endforeach() endforeach()
set(programs C CXX RC) set(programs C CXX RC)
set(meson_RC windres)
set(meson_CXX cpp)
foreach(prog IN LISTS programs) foreach(prog IN LISTS programs)
if(VCPKG_DETECTED_CMAKE_${prog}_COMPILER) if(VCPKG_DETECTED_CMAKE_${prog}_COMPILER)
string(REPLACE "CXX" "CPP" mesonprog "${prog}") if(meson_${prog})
string(REPLACE "RC" "windres" mesonprog "${mesonprog}") # https://mesonbuild.com/Windows-module.html string(APPEND "${var_to_append}" "${meson_${prog}} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n")
string(TOLOWER "${mesonprog}" proglower) else()
string(APPEND native_config "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n") string(TOLOWER "${prog}" proglower)
string(APPEND "${var_to_append}" "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n")
endif()
endif() endif()
endforeach() endforeach()
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS) if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
# for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456 # for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
if (NOT VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "^(GNU|Intel)$") if (NOT VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "^(GNU|Intel)$")
string(APPEND native_config "c_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n") string(APPEND "${var_to_append}" "c_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
endif() endif()
endif() endif()
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS) if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
# for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456 # for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
if (NOT VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Intel)$") if (NOT VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Intel)$")
string(APPEND native_config "cpp_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n") string(APPEND "${var_to_append}" "cpp_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
endif() endif()
endif() endif()
string(APPEND native_config "cmake = '${CMAKE_COMMAND}'\n")
get_filename_component(CMAKE_PATH "${CMAKE_COMMAND}" DIRECTORY)
vcpkg_add_to_path("${CMAKE_PATH}" PREPEND) # Make CMake invokeable for Meson
string(APPEND "${var_to_append}" "cmake = '${CMAKE_COMMAND}'\n")
vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_DIR "${PYTHON3}" DIRECTORY)
vcpkg_add_to_path("${PYTHON3_DIR}")
string(APPEND "${var_to_append}" "python = '${PYTHON3}'\n")
vcpkg_find_acquire_program(NINJA)
get_filename_component(NINJA_PATH ${NINJA} DIRECTORY)
vcpkg_add_to_path(PREPEND "${NINJA_PATH}") # Prepend to use the correct ninja.
# string(APPEND "${var_to_append}" "ninja = '${NINJA}'\n") # This does not work due to meson issues
foreach(additional_binary IN LISTS additional_binaries) foreach(additional_binary IN LISTS additional_binaries)
string(APPEND native_config "${additional_binary}\n") string(APPEND "${var_to_append}" "${additional_binary}\n")
endforeach() endforeach()
set("${var_to_append}" "${${var_to_append}}" PARENT_SCOPE)
endfunction()
function(z_vcpkg_meson_generate_native_file additional_binaries) #https://mesonbuild.com/Native-environments.html
set(native_config "")
z_vcpkg_append_proglist(native_config "${additional_binaries}")
string(APPEND native_config "[built-in options]\n") #https://mesonbuild.com/Builtin-options.html string(APPEND native_config "[built-in options]\n") #https://mesonbuild.com/Builtin-options.html
if(VCPKG_DETECTED_CMAKE_C_COMPILER MATCHES "cl.exe") if(VCPKG_DETECTED_CMAKE_C_COMPILER MATCHES "cl.exe")
@ -276,43 +303,9 @@ function(z_vcpkg_meson_generate_cross_file additional_binaries) #https://mesonbu
else() else()
message(FATAL_ERROR "Unsupported target architecture ${VCPKG_TARGET_ARCHITECTURE}!" ) message(FATAL_ERROR "Unsupported target architecture ${VCPKG_TARGET_ARCHITECTURE}!" )
endif() endif()
set(cross_file "[binaries]\n")
if(VCPKG_TARGET_IS_WINDOWS) set(cross_file "")
set(proglist MT) z_vcpkg_append_proglist(cross_file "${additional_binaries}")
else()
set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT)
endif()
foreach(prog IN LISTS proglist)
if(VCPKG_DETECTED_CMAKE_${prog})
string(TOLOWER "${prog}" proglower)
string(APPEND cross_file "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n")
endif()
endforeach()
set(programs C CXX RC)
foreach(prog IN LISTS programs)
if(VCPKG_DETECTED_CMAKE_${prog}_COMPILER)
string(REPLACE "CXX" "CPP" mesonprog "${prog}")
string(REPLACE "RC" "windres" mesonprog "${mesonprog}") # https://mesonbuild.com/Windows-module.html
string(TOLOWER "${mesonprog}" proglower)
string(APPEND cross_file "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n")
endif()
endforeach()
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
# for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
if (NOT VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "^(GNU|Intel)$")
string(APPEND cross_file "c_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
endif()
endif()
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
# for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
if (NOT VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Intel)$")
string(APPEND cross_file "cpp_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
endif()
endif()
string(APPEND cross_file "cmake = '${CMAKE_COMMAND}'\n")
foreach(additional_binary IN LISTS additional_binaries)
string(APPEND cross_file "${additional_binary}\n")
endforeach()
string(APPEND cross_file "[properties]\n") string(APPEND cross_file "[properties]\n")
@ -391,22 +384,8 @@ function(vcpkg_configure_meson)
debug_message("Including cmake vars from: ${cmake_vars_file}") debug_message("Including cmake vars from: ${cmake_vars_file}")
include("${cmake_vars_file}") include("${cmake_vars_file}")
vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_DIR "${PYTHON3}" DIRECTORY)
vcpkg_add_to_path("${PYTHON3_DIR}")
vcpkg_list(APPEND arg_ADDITIONAL_NATIVE_BINARIES "python = '${PYTHON3}'")
vcpkg_list(APPEND arg_ADDITIONAL_CROSS_BINARIES "python = '${PYTHON3}'")
vcpkg_find_acquire_program(MESON) vcpkg_find_acquire_program(MESON)
get_filename_component(CMAKE_PATH ${CMAKE_COMMAND} DIRECTORY)
vcpkg_add_to_path("${CMAKE_PATH}") # Make CMake invokeable for Meson
vcpkg_find_acquire_program(NINJA)
get_filename_component(NINJA_PATH ${NINJA} DIRECTORY)
vcpkg_add_to_path(PREPEND "${NINJA_PATH}") # Need to prepend so that meson picks up the correct ninja from vcpkg ....
# vcpkg_list(APPEND arg_ADDITIONAL_NATIVE_BINARIES "ninja = '${NINJA}'") # This does not work due to meson issues ......
vcpkg_list(APPEND arg_OPTIONS --buildtype plain --backend ninja --wrap-mode nodownload) vcpkg_list(APPEND arg_OPTIONS --buildtype plain --backend ninja --wrap-mode nodownload)
if(NOT vcpkg_meson_cross_file) if(NOT vcpkg_meson_cross_file)

View File

@ -7126,7 +7126,7 @@
}, },
"vcpkg-tool-meson": { "vcpkg-tool-meson": {
"baseline": "0.60.2", "baseline": "0.60.2",
"port-version": 0 "port-version": 1
}, },
"vcpkg-tool-nodejs": { "vcpkg-tool-nodejs": {
"baseline": "14.17.4", "baseline": "14.17.4",

View File

@ -1,5 +1,10 @@
{ {
"versions": [ "versions": [
{
"git-tree": "932036adfc24dd5fa63787b825974b6938402700",
"version": "0.60.2",
"port-version": 1
},
{ {
"git-tree": "e6ef15a9dc810b4bde53d9b1e3da3a20107e3983", "git-tree": "e6ef15a9dc810b4bde53d9b1e3da3a20107e3983",
"version": "0.60.2", "version": "0.60.2",