2020-12-02 05:37:26 +08:00
|
|
|
#[===[.md:
|
|
|
|
# vcpkg_configure_meson
|
|
|
|
|
|
|
|
Configure Meson for Debug and Release builds of a project.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
```cmake
|
|
|
|
vcpkg_configure_meson(
|
|
|
|
SOURCE_PATH <${SOURCE_PATH}>
|
2021-09-25 03:11:38 +08:00
|
|
|
[NO_PKG_CONFIG]
|
2020-12-02 05:37:26 +08:00
|
|
|
[OPTIONS <-DUSE_THIS_IN_ALL_BUILDS=1>...]
|
|
|
|
[OPTIONS_RELEASE <-DOPTIMIZE=1>...]
|
|
|
|
[OPTIONS_DEBUG <-DDEBUGGABLE=1>...]
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
### SOURCE_PATH
|
|
|
|
Specifies the directory containing the `meson.build`.
|
|
|
|
By convention, this is usually set in the portfile as the variable `SOURCE_PATH`.
|
|
|
|
|
|
|
|
### OPTIONS
|
|
|
|
Additional options passed to Meson during the configuration.
|
|
|
|
|
|
|
|
### OPTIONS_RELEASE
|
|
|
|
Additional options passed to Meson during the Release configuration. These are in addition to `OPTIONS`.
|
|
|
|
|
|
|
|
### OPTIONS_DEBUG
|
|
|
|
Additional options passed to Meson during the Debug configuration. These are in addition to `OPTIONS`.
|
|
|
|
|
2021-09-25 03:11:38 +08:00
|
|
|
### NO_PKG_CONFIG
|
|
|
|
Disable pkg-config setup
|
|
|
|
|
2020-12-02 05:37:26 +08:00
|
|
|
## Notes
|
|
|
|
This command supplies many common arguments to Meson. To see the full list, examine the source.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
* [fribidi](https://github.com/Microsoft/vcpkg/blob/master/ports/fribidi/portfile.cmake)
|
|
|
|
* [libepoxy](https://github.com/Microsoft/vcpkg/blob/master/ports/libepoxy/portfile.cmake)
|
|
|
|
#]===]
|
|
|
|
|
2021-12-17 14:47:16 +08:00
|
|
|
function(z_vcpkg_append_proglist var_to_append additional_binaries)
|
|
|
|
string(APPEND "${var_to_append}" "[binaries]\n")
|
2020-11-19 05:36:20 +08:00
|
|
|
if(VCPKG_TARGET_IS_WINDOWS)
|
2021-12-17 14:47:16 +08:00
|
|
|
set(proglist MT AR)
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
|
|
|
set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT)
|
|
|
|
endif()
|
|
|
|
foreach(prog IN LISTS proglist)
|
|
|
|
if(VCPKG_DETECTED_CMAKE_${prog})
|
2021-12-17 14:47:16 +08:00
|
|
|
if(meson_${prog})
|
|
|
|
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()
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2021-11-09 04:27:18 +08:00
|
|
|
set(programs C CXX RC)
|
2021-12-17 14:47:16 +08:00
|
|
|
set(meson_RC windres)
|
|
|
|
set(meson_CXX cpp)
|
2021-11-09 04:27:18 +08:00
|
|
|
foreach(prog IN LISTS programs)
|
2020-11-19 05:36:20 +08:00
|
|
|
if(VCPKG_DETECTED_CMAKE_${prog}_COMPILER)
|
2021-12-17 14:47:16 +08:00
|
|
|
if(meson_${prog})
|
|
|
|
string(APPEND "${var_to_append}" "${meson_${prog}} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n")
|
|
|
|
else()
|
|
|
|
string(TOLOWER "${prog}" proglower)
|
|
|
|
string(APPEND "${var_to_append}" "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n")
|
|
|
|
endif()
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
|
2021-11-09 04:27:18 +08:00
|
|
|
# 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)$")
|
2021-12-17 14:47:16 +08:00
|
|
|
string(APPEND "${var_to_append}" "c_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
|
2021-09-10 11:41:01 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
if(VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS)
|
2021-11-09 04:27:18 +08:00
|
|
|
# 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)$")
|
2021-12-17 14:47:16 +08:00
|
|
|
string(APPEND "${var_to_append}" "cpp_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n")
|
2021-09-10 11:41:01 +08:00
|
|
|
endif()
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-12-17 14:47:16 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
foreach(additional_binary IN LISTS additional_binaries)
|
2021-12-17 14:47:16 +08:00
|
|
|
string(APPEND "${var_to_append}" "${additional_binary}\n")
|
2021-01-12 08:12:01 +08:00
|
|
|
endforeach()
|
2021-12-17 14:47:16 +08:00
|
|
|
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}")
|
2021-01-12 08:12:01 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND native_config "[built-in options]\n") #https://mesonbuild.com/Builtin-options.html
|
2020-11-19 05:36:20 +08:00
|
|
|
if(VCPKG_DETECTED_CMAKE_C_COMPILER MATCHES "cl.exe")
|
2021-04-01 02:54:44 +08:00
|
|
|
# This is currently wrongly documented in the meson docs or buggy. The docs say: 'none' = no flags
|
|
|
|
# In reality however 'none' tries to deactivate eh and meson passes the flags for it resulting in a lot of warnings
|
2021-05-27 05:00:07 +08:00
|
|
|
# about overriden flags. Until this is fixed in meson vcpkg should not pass this here.
|
2021-11-09 04:27:18 +08:00
|
|
|
# string(APPEND native_config "cpp_eh='none'\n") # To make sure meson is not adding eh flags by itself using msvc
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
|
|
|
if(VCPKG_TARGET_IS_WINDOWS)
|
2021-11-09 04:27:18 +08:00
|
|
|
set(c_winlibs "${VCPKG_DETECTED_CMAKE_C_STANDARD_LIBRARIES}")
|
|
|
|
set(cpp_winlibs "${VCPKG_DETECTED_CMAKE_CXX_STANDARD_LIBRARIES}")
|
|
|
|
foreach(libvar IN ITEMS c_winlibs cpp_winlibs)
|
|
|
|
string(REGEX REPLACE "( |^)(-|/)" [[;\2]] "${libvar}" "${${libvar}}")
|
|
|
|
string(REPLACE ".lib " ".lib;" "${libvar}" "${${libvar}}")
|
|
|
|
vcpkg_list(REMOVE_ITEM "${libvar}" "")
|
|
|
|
vcpkg_list(JOIN "${libvar}" "', '" "${libvar}")
|
|
|
|
string(APPEND native_config "${libvar} = ['${${libvar}}']\n")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(native_config_name "${CURRENT_BUILDTREES_DIR}/meson-native-${TARGET_TRIPLET}.log")
|
|
|
|
set(vcpkg_meson_native_file "${native_config_name}" PARENT_SCOPE)
|
|
|
|
file(WRITE "${native_config_name}" "${native_config}")
|
2020-11-19 05:36:20 +08:00
|
|
|
endfunction()
|
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
function(z_vcpkg_meson_convert_compiler_flags_to_list out_var compiler_flags)
|
|
|
|
string(REPLACE ";" [[\;]] tmp_var "${compiler_flags}")
|
|
|
|
string(REGEX REPLACE [=[( +|^)((\"(\\"|[^"])+"|\\"|\\ |[^ ])+)]=] ";\\2" tmp_var "${tmp_var}")
|
|
|
|
vcpkg_list(POP_FRONT tmp_var) # The first element is always empty due to the above replacement
|
|
|
|
list(TRANSFORM tmp_var STRIP) # Strip leading trailing whitespaces from each element in the list.
|
|
|
|
set("${out_var}" "${tmp_var}" PARENT_SCOPE)
|
2021-02-11 16:44:49 +08:00
|
|
|
endfunction()
|
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
function(z_vcpkg_meson_convert_list_to_python_array out_var)
|
|
|
|
z_vcpkg_function_arguments(flag_list 1)
|
|
|
|
vcpkg_list(REMOVE_ITEM flag_list "") # remove empty elements if any
|
|
|
|
vcpkg_list(JOIN flag_list "', '" flag_list)
|
|
|
|
set("${out_var}" "['${flag_list}']" PARENT_SCOPE)
|
2021-04-01 02:54:44 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Generates the required compiler properties for meson
|
2021-11-09 04:27:18 +08:00
|
|
|
function(z_vcpkg_meson_generate_flags_properties_string out_var config_type)
|
|
|
|
set(result "")
|
|
|
|
|
2021-05-25 06:09:58 +08:00
|
|
|
if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
|
2021-11-09 04:27:18 +08:00
|
|
|
set(libpath_flag /LIBPATH:)
|
|
|
|
else()
|
|
|
|
set(libpath_flag -L)
|
|
|
|
endif()
|
|
|
|
if(config_type STREQUAL "DEBUG")
|
|
|
|
set(path_suffix "/debug")
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
set(path_suffix "")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(libpath "${libpath_flag}${CURRENT_INSTALLED_DIR}${path_suffix}/lib")
|
|
|
|
|
|
|
|
z_vcpkg_meson_convert_compiler_flags_to_list(cflags "${VCPKG_DETECTED_CMAKE_C_FLAGS_${config_type}}")
|
|
|
|
vcpkg_list(APPEND cflags "-I${CURRENT_INSTALLED_DIR}/include")
|
|
|
|
z_vcpkg_meson_convert_list_to_python_array(cflags ${cflags})
|
|
|
|
string(APPEND result "c_args = ${cflags}\n")
|
|
|
|
|
|
|
|
z_vcpkg_meson_convert_compiler_flags_to_list(cxxflags "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_${config_type}}")
|
|
|
|
vcpkg_list(APPEND cxxflags "-I${CURRENT_INSTALLED_DIR}/include")
|
|
|
|
z_vcpkg_meson_convert_list_to_python_array(cxxflags ${cxxflags})
|
|
|
|
string(APPEND result "cpp_args = ${cxxflags}\n")
|
|
|
|
|
2020-11-19 05:36:20 +08:00
|
|
|
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(linker_flags "${VCPKG_DETECTED_CMAKE_SHARED_LINKER_FLAGS_${config_type}}")
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
set(linker_flags "${VCPKG_DETECTED_CMAKE_STATIC_LINKER_FLAGS_${config_type}}")
|
|
|
|
endif()
|
|
|
|
z_vcpkg_meson_convert_compiler_flags_to_list(linker_flags "${linker_flags}")
|
2022-02-25 03:04:11 +08:00
|
|
|
if(VCPKG_TARGET_IS_OSX)
|
|
|
|
# macOS - append arch and isysroot if cross-compiling
|
|
|
|
if(NOT "${VCPKG_OSX_ARCHITECTURES}" STREQUAL "${VCPKG_DETECTED_CMAKE_HOST_SYSTEM_PROCESSOR}")
|
|
|
|
foreach(arch IN LISTS VCPKG_OSX_ARCHITECTURES)
|
|
|
|
vcpkg_list(APPEND linker_flags -arch "${arch}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
if(VCPKG_DETECTED_CMAKE_OSX_SYSROOT)
|
|
|
|
vcpkg_list(APPEND linker_flags -isysroot "${VCPKG_DETECTED_CMAKE_OSX_SYSROOT}")
|
|
|
|
endif()
|
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND linker_flags "${libpath}")
|
|
|
|
z_vcpkg_meson_convert_list_to_python_array(linker_flags ${linker_flags})
|
|
|
|
string(APPEND result "c_link_args = ${linker_flags}\n")
|
|
|
|
string(APPEND result "cpp_link_args = ${linker_flags}\n")
|
|
|
|
set("${out_var}" "${result}" PARENT_SCOPE)
|
2021-04-01 02:54:44 +08:00
|
|
|
endfunction()
|
2020-11-19 05:36:20 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
function(z_vcpkg_meson_generate_native_file_config config_type) #https://mesonbuild.com/Native-environments.html
|
|
|
|
set(native_file "[properties]\n") #https://mesonbuild.com/Builtin-options.html
|
2020-11-19 05:36:20 +08:00
|
|
|
#Setup CMake properties
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND native_file "cmake_toolchain_file = '${SCRIPTS}/buildsystems/vcpkg.cmake'\n")
|
|
|
|
string(APPEND native_file "[cmake]\n")
|
2020-04-07 05:43:16 +08:00
|
|
|
|
|
|
|
if(NOT VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
|
2022-04-12 06:57:36 +08:00
|
|
|
z_vcpkg_select_default_vcpkg_chainload_toolchain()
|
2017-02-10 01:13:52 +08:00
|
|
|
endif()
|
2020-04-07 05:43:16 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND native_file "VCPKG_TARGET_TRIPLET = '${TARGET_TRIPLET}'\n")
|
|
|
|
string(APPEND native_file "VCPKG_CHAINLOAD_TOOLCHAIN_FILE = '${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}'\n")
|
|
|
|
string(APPEND native_file "VCPKG_CRT_LINKAGE = '${VCPKG_CRT_LINKAGE}'\n")
|
2020-04-07 05:43:16 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND native_file "[built-in options]\n")
|
2022-02-25 03:04:11 +08:00
|
|
|
z_vcpkg_meson_generate_flags_properties_string(native_properties "${config_type}")
|
|
|
|
string(APPEND native_file "${native_properties}")
|
2020-11-19 05:36:20 +08:00
|
|
|
if(VCPKG_TARGET_IS_WINDOWS)
|
|
|
|
if(VCPKG_CRT_LINKAGE STREQUAL "static")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(crt_type mt)
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
set(crt_type md)
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if("${config_type}" STREQUAL "DEBUG")
|
|
|
|
string(APPEND crt_type "d")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND native_file "b_vscrt = '${crt_type}'\n")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
string(TOLOWER "${config_type}" lowerconfig)
|
|
|
|
set(native_config_name "${CURRENT_BUILDTREES_DIR}/meson-native-${TARGET_TRIPLET}-${lowerconfig}.log")
|
|
|
|
file(WRITE "${native_config_name}" "${native_file}")
|
|
|
|
set("vcpkg_meson_native_file_${config_type}" "${native_config_name}" PARENT_SCOPE)
|
2020-11-19 05:36:20 +08:00
|
|
|
endfunction()
|
2020-04-07 05:43:16 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
function(z_vcpkg_meson_generate_cross_file additional_binaries) #https://mesonbuild.com/Cross-compilation.html
|
2020-11-19 05:36:20 +08:00
|
|
|
if(CMAKE_HOST_WIN32)
|
|
|
|
if(DEFINED ENV{PROCESSOR_ARCHITEW6432})
|
2021-11-09 04:27:18 +08:00
|
|
|
set(build_arch $ENV{PROCESSOR_ARCHITEW6432})
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
set(build_arch $ENV{PROCESSOR_ARCHITECTURE})
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if(build_arch MATCHES "(amd|AMD)64")
|
|
|
|
set(build_cpu_fam x86_64)
|
|
|
|
set(build_cpu x86_64)
|
|
|
|
elseif(build_arch MATCHES "(x|X)86")
|
|
|
|
set(build_cpu_fam x86)
|
|
|
|
set(build_cpu i686)
|
|
|
|
elseif(build_arch MATCHES "^(ARM|arm)64$")
|
|
|
|
set(build_cpu_fam aarch64)
|
|
|
|
set(build_cpu armv8)
|
|
|
|
elseif(build_arch MATCHES "^(ARM|arm)$")
|
|
|
|
set(build_cpu_fam arm)
|
|
|
|
set(build_cpu armv7hl)
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
message(FATAL_ERROR "Unsupported host architecture ${build_arch}!")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-05-27 05:00:07 +08:00
|
|
|
elseif(CMAKE_HOST_UNIX)
|
|
|
|
# at this stage, CMAKE_HOST_SYSTEM_PROCESSOR is not defined
|
|
|
|
execute_process(
|
|
|
|
COMMAND uname -m
|
|
|
|
OUTPUT_VARIABLE MACHINE
|
|
|
|
COMMAND_ERROR_IS_FATAL ANY)
|
2021-07-16 06:15:36 +08:00
|
|
|
|
|
|
|
# Show real machine architecture to visually understand whether we are in a native Apple Silicon terminal or running under Rosetta emulation
|
|
|
|
debug_message("Machine: ${MACHINE}")
|
2021-05-27 05:00:07 +08:00
|
|
|
|
2021-11-17 08:50:43 +08:00
|
|
|
if(MACHINE MATCHES "arm64|aarch64")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(build_cpu_fam aarch64)
|
|
|
|
set(build_cpu armv8)
|
2021-05-27 05:00:07 +08:00
|
|
|
elseif(MACHINE MATCHES "x86_64|amd64")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(build_cpu_fam x86_64)
|
|
|
|
set(build_cpu x86_64)
|
2021-05-27 05:00:07 +08:00
|
|
|
elseif(MACHINE MATCHES "x86|i686")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(build_cpu_fam x86)
|
|
|
|
set(build_cpu i686)
|
2021-05-27 05:00:07 +08:00
|
|
|
elseif(MACHINE MATCHES "i386")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(build_cpu_fam x86)
|
|
|
|
set(build_cpu i386)
|
2021-05-27 05:00:07 +08:00
|
|
|
else()
|
|
|
|
# https://github.com/mesonbuild/meson/blob/master/docs/markdown/Reference-tables.md#cpu-families
|
|
|
|
message(FATAL_ERROR "Unhandled machine: ${MACHINE}")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Failed to detect the host architecture!")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2020-04-07 05:43:16 +08:00
|
|
|
|
2020-11-19 05:36:20 +08:00
|
|
|
if(VCPKG_TARGET_ARCHITECTURE MATCHES "(amd|AMD|x|X)64")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(host_cpu_fam x86_64)
|
|
|
|
set(host_cpu x86_64)
|
2020-11-19 05:36:20 +08:00
|
|
|
elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "(x|X)86")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(host_cpu_fam x86)
|
|
|
|
set(host_cpu i686)
|
2020-11-19 05:36:20 +08:00
|
|
|
elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "^(ARM|arm)64$")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(host_cpu_fam aarch64)
|
|
|
|
set(host_cpu armv8)
|
2020-11-19 05:36:20 +08:00
|
|
|
elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "^(ARM|arm)$")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(host_cpu_fam arm)
|
|
|
|
set(host_cpu armv7hl)
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unsupported target architecture ${VCPKG_TARGET_ARCHITECTURE}!" )
|
|
|
|
endif()
|
2021-12-17 14:47:16 +08:00
|
|
|
|
|
|
|
set(cross_file "")
|
|
|
|
z_vcpkg_append_proglist(cross_file "${additional_binaries}")
|
2021-01-12 08:12:01 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND cross_file "[properties]\n")
|
2021-04-01 02:54:44 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND cross_file "[host_machine]\n")
|
|
|
|
string(APPEND cross_file "endian = 'little'\n")
|
2021-09-10 11:41:01 +08:00
|
|
|
if(NOT VCPKG_CMAKE_SYSTEM_NAME OR VCPKG_TARGET_IS_MINGW)
|
2021-11-09 04:27:18 +08:00
|
|
|
set(meson_system_name "windows")
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
string(TOLOWER "${VCPKG_CMAKE_SYSTEM_NAME}" meson_system_name)
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND cross_file "system = '${meson_system_name}'\n")
|
|
|
|
string(APPEND cross_file "cpu_family = '${host_cpu_fam}'\n")
|
|
|
|
string(APPEND cross_file "cpu = '${host_cpu}'\n")
|
2021-05-27 05:00:07 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND cross_file "[build_machine]\n")
|
|
|
|
string(APPEND cross_file "endian = 'little'\n")
|
2020-11-19 05:36:20 +08:00
|
|
|
if(WIN32)
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND cross_file "system = 'windows'\n")
|
2020-11-19 05:36:20 +08:00
|
|
|
elseif(DARWIN)
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND cross_file "system = 'darwin'\n")
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND cross_file "system = 'linux'\n")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-05-27 05:00:07 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
if(DEFINED build_cpu_fam)
|
|
|
|
string(APPEND cross_file "cpu_family = '${build_cpu_fam}'\n")
|
2021-05-27 05:00:07 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if(DEFINED build_cpu)
|
|
|
|
string(APPEND cross_file "cpu = '${build_cpu}'\n")
|
2021-05-27 05:00:07 +08:00
|
|
|
endif()
|
2021-02-21 13:29:35 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
if(NOT build_cpu_fam MATCHES "${host_cpu_fam}"
|
|
|
|
OR VCPKG_TARGET_IS_ANDROID OR VCPKG_TARGET_IS_IOS OR VCPKG_TARGET_IS_UWP
|
|
|
|
OR (VCPKG_TARGET_IS_MINGW AND NOT WIN32))
|
|
|
|
set(native_config_name "${CURRENT_BUILDTREES_DIR}/meson-cross-${TARGET_TRIPLET}.log")
|
|
|
|
set(vcpkg_meson_cross_file "${native_config_name}" PARENT_SCOPE)
|
|
|
|
file(WRITE "${native_config_name}" "${cross_file}")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
function(z_vcpkg_meson_generate_cross_file_config config_type) #https://mesonbuild.com/Native-environments.html
|
|
|
|
set(cross_${config_type}_log "[properties]\n") #https://mesonbuild.com/Builtin-options.html
|
2022-02-25 03:04:11 +08:00
|
|
|
string(APPEND cross_${config_type}_log "[built-in options]\n")
|
2021-11-09 04:27:18 +08:00
|
|
|
z_vcpkg_meson_generate_flags_properties_string(cross_properties ${config_type})
|
|
|
|
string(APPEND cross_${config_type}_log "${cross_properties}")
|
2020-11-19 05:36:20 +08:00
|
|
|
if(VCPKG_TARGET_IS_WINDOWS)
|
|
|
|
if(VCPKG_CRT_LINKAGE STREQUAL "static")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(crt_type mt)
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
set(crt_type md)
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if(${config_type} STREQUAL "DEBUG")
|
|
|
|
set(crt_type ${crt_type}d)
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
string(APPEND cross_${config_type}_log "b_vscrt = '${crt_type}'\n")
|
2020-04-07 05:43:16 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
string(TOLOWER "${config_type}" lowerconfig)
|
|
|
|
set(native_config_name "${CURRENT_BUILDTREES_DIR}/meson-cross-${TARGET_TRIPLET}-${lowerconfig}.log")
|
|
|
|
set(VCPKG_MESON_CROSS_FILE_${config_type} "${native_config_name}" PARENT_SCOPE)
|
|
|
|
file(WRITE "${native_config_name}" "${cross_${config_type}_log}")
|
2020-11-19 05:36:20 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
|
|
function(vcpkg_configure_meson)
|
|
|
|
# parse parameters such that semicolons in options arguments to COMMAND don't get erased
|
2021-11-09 04:27:18 +08:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 arg
|
|
|
|
"NO_PKG_CONFIG"
|
|
|
|
"SOURCE_PATH"
|
|
|
|
"OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE;ADDITIONAL_NATIVE_BINARIES;ADDITIONAL_CROSS_BINARIES"
|
|
|
|
)
|
2020-11-19 05:36:20 +08:00
|
|
|
|
2021-04-01 02:54:44 +08:00
|
|
|
file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
|
|
|
|
file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
|
2020-11-19 05:36:20 +08:00
|
|
|
|
2021-07-30 00:47:35 +08:00
|
|
|
z_vcpkg_get_cmake_vars(cmake_vars_file)
|
|
|
|
debug_message("Including cmake vars from: ${cmake_vars_file}")
|
|
|
|
include("${cmake_vars_file}")
|
2020-11-19 05:36:20 +08:00
|
|
|
|
2021-01-12 08:12:01 +08:00
|
|
|
vcpkg_find_acquire_program(MESON)
|
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND arg_OPTIONS --buildtype plain --backend ninja --wrap-mode nodownload)
|
2020-11-19 05:36:20 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
if(NOT vcpkg_meson_cross_file)
|
|
|
|
z_vcpkg_meson_generate_cross_file("${arg_ADDITIONAL_CROSS_BINARIES}")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
# We must use uppercase `DEBUG` and `RELEASE` here because they matches the configuration data
|
|
|
|
if(NOT VCPKG_MESON_CROSS_FILE_DEBUG AND vcpkg_meson_cross_file)
|
|
|
|
z_vcpkg_meson_generate_cross_file_config(DEBUG)
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if(NOT VCPKG_MESON_CROSS_FILE_RELEASE AND vcpkg_meson_cross_file)
|
|
|
|
z_vcpkg_meson_generate_cross_file_config(RELEASE)
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if(vcpkg_meson_cross_file)
|
|
|
|
vcpkg_list(APPEND arg_OPTIONS --cross "${vcpkg_meson_cross_file}")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
|
|
|
if(VCPKG_MESON_CROSS_FILE_DEBUG)
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND arg_OPTIONS_DEBUG --cross "${VCPKG_MESON_CROSS_FILE_DEBUG}")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
|
|
|
if(VCPKG_MESON_CROSS_FILE_RELEASE)
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND arg_OPTIONS_RELEASE --cross "${VCPKG_MESON_CROSS_FILE_RELEASE}")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
if(NOT vcpkg_meson_native_file AND NOT vcpkg_meson_cross_file)
|
|
|
|
z_vcpkg_meson_generate_native_file("${arg_ADDITIONAL_NATIVE_BINARIES}")
|
2021-04-01 02:54:44 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if(NOT vcpkg_meson_native_file_DEBUG AND NOT vcpkg_meson_cross_file)
|
|
|
|
z_vcpkg_meson_generate_native_file_config(DEBUG)
|
2021-04-01 02:54:44 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if(NOT vcpkg_meson_native_file_RELEASE AND NOT vcpkg_meson_cross_file)
|
|
|
|
z_vcpkg_meson_generate_native_file_config(RELEASE)
|
2021-04-01 02:54:44 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if(vcpkg_meson_native_file AND NOT vcpkg_meson_cross_file)
|
|
|
|
vcpkg_list(APPEND arg_OPTIONS --native "${vcpkg_meson_native_file}")
|
|
|
|
vcpkg_list(APPEND arg_OPTIONS_DEBUG --native "${vcpkg_meson_native_file_DEBUG}")
|
|
|
|
vcpkg_list(APPEND arg_OPTIONS_RELEASE --native "${vcpkg_meson_native_file_RELEASE}")
|
2021-04-01 02:54:44 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND arg_OPTIONS --native "${SCRIPTS}/buildsystems/meson/none.txt")
|
2021-04-01 02:54:44 +08:00
|
|
|
endif()
|
2020-02-13 07:58:43 +08:00
|
|
|
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND arg_OPTIONS --default-library shared)
|
2017-02-10 01:13:52 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND arg_OPTIONS --default-library static)
|
2017-02-10 01:13:52 +08:00
|
|
|
endif()
|
2021-05-27 05:00:07 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND arg_OPTIONS --libdir lib) # else meson install into an architecture describing folder
|
|
|
|
vcpkg_list(APPEND arg_OPTIONS_DEBUG -Ddebug=true --prefix "${CURRENT_PACKAGES_DIR}/debug" --includedir ../include)
|
|
|
|
vcpkg_list(APPEND arg_OPTIONS_RELEASE -Ddebug=false --prefix "${CURRENT_PACKAGES_DIR}")
|
2020-11-19 05:36:20 +08:00
|
|
|
|
|
|
|
# select meson cmd-line options
|
|
|
|
if(VCPKG_TARGET_IS_WINDOWS)
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND arg_OPTIONS_DEBUG "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}/debug','${CURRENT_INSTALLED_DIR}','${CURRENT_INSTALLED_DIR}/share']")
|
|
|
|
vcpkg_list(APPEND arg_OPTIONS_RELEASE "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}','${CURRENT_INSTALLED_DIR}/debug','${CURRENT_INSTALLED_DIR}/share']")
|
2020-11-19 05:36:20 +08:00
|
|
|
else()
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_list(APPEND arg_OPTIONS_DEBUG "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}/debug','${CURRENT_INSTALLED_DIR}']")
|
|
|
|
vcpkg_list(APPEND arg_OPTIONS_RELEASE "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}','${CURRENT_INSTALLED_DIR}/debug']")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
2021-09-25 03:11:38 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
if(NOT arg_NO_PKG_CONFIG)
|
2021-09-25 03:11:38 +08:00
|
|
|
vcpkg_find_acquire_program(PKGCONFIG)
|
|
|
|
get_filename_component(PKGCONFIG_PATH ${PKGCONFIG} DIRECTORY)
|
|
|
|
vcpkg_add_to_path("${PKGCONFIG_PATH}")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(pkgconfig_share_dir "${CURRENT_INSTALLED_DIR}/share/pkgconfig/")
|
2021-09-25 03:11:38 +08:00
|
|
|
endif()
|
|
|
|
|
2020-11-19 05:36:20 +08:00
|
|
|
set(buildtypes)
|
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(buildname "DEBUG")
|
|
|
|
vcpkg_list(APPEND buildtypes ${buildname})
|
|
|
|
set(path_suffix_${buildname} "debug/")
|
|
|
|
set(suffix_${buildname} "dbg")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
|
2021-11-09 04:27:18 +08:00
|
|
|
set(buildname "RELEASE")
|
|
|
|
vcpkg_list(APPEND buildtypes ${buildname})
|
|
|
|
set(path_suffix_${buildname} "")
|
|
|
|
set(suffix_${buildname} "rel")
|
2020-11-19 05:36:20 +08:00
|
|
|
endif()
|
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_backup_env_variables(VARS INCLUDE)
|
|
|
|
vcpkg_host_path_list(APPEND ENV{INCLUDE} "${CURRENT_INSTALLED_DIR}/include")
|
2020-11-19 05:36:20 +08:00
|
|
|
# configure build
|
|
|
|
foreach(buildtype IN LISTS buildtypes)
|
2021-11-09 04:27:18 +08:00
|
|
|
message(STATUS "Configuring ${TARGET_TRIPLET}-${suffix_${buildtype}}")
|
|
|
|
file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}")
|
2020-04-07 05:43:16 +08:00
|
|
|
#setting up PKGCONFIG
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_backup_env_variables(VARS PKG_CONFIG PKG_CONFIG_PATH)
|
|
|
|
if(NOT arg_NO_PKG_CONFIG)
|
2021-09-25 03:11:38 +08:00
|
|
|
set(ENV{PKG_CONFIG} "${PKGCONFIG}") # Set via native file?
|
2021-11-09 04:27:18 +08:00
|
|
|
set(pkgconfig_installed_dir "${CURRENT_INSTALLED_DIR}/${path_suffix_${buildtype}}lib/pkgconfig/")
|
|
|
|
vcpkg_host_path_list(APPEND ENV{PKG_CONFIG_PATH} "${pkgconfig_installed_dir}" "${pkgconfig_share_dir}" "$ENV{PKG_CONFIG_PATH}")
|
2020-04-07 05:43:16 +08:00
|
|
|
endif()
|
|
|
|
|
2017-11-26 07:25:18 +08:00
|
|
|
vcpkg_execute_required_process(
|
2021-11-09 04:27:18 +08:00
|
|
|
COMMAND ${MESON} ${arg_OPTIONS} ${arg_OPTIONS_${buildtype}} ${arg_SOURCE_PATH}
|
|
|
|
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}"
|
|
|
|
LOGNAME config-${TARGET_TRIPLET}-${suffix_${buildtype}}
|
2017-11-26 07:25:18 +08:00
|
|
|
)
|
2020-11-19 05:36:20 +08:00
|
|
|
|
2020-04-07 05:43:16 +08:00
|
|
|
#Copy meson log files into buildtree for CI
|
2021-11-09 04:27:18 +08:00
|
|
|
if(EXISTS "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}/meson-logs/meson-log.txt")
|
|
|
|
file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}/meson-logs/meson-log.txt" DESTINATION "${CURRENT_BUILDTREES_DIR}")
|
2021-12-03 07:48:34 +08:00
|
|
|
file(RENAME "${CURRENT_BUILDTREES_DIR}/meson-log.txt" "${CURRENT_BUILDTREES_DIR}/meson-log-${suffix_${buildtype}}.log")
|
|
|
|
endif()
|
|
|
|
if(EXISTS "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}/meson-info/intro-dependencies.json")
|
|
|
|
file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}/meson-info/intro-dependencies.json" DESTINATION "${CURRENT_BUILDTREES_DIR}")
|
|
|
|
file(RENAME "${CURRENT_BUILDTREES_DIR}/intro-dependencies.json" "${CURRENT_BUILDTREES_DIR}/intro-dependencies-${suffix_${buildtype}}.log")
|
2020-04-07 05:43:16 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
if(EXISTS "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}/meson-logs/install-log.txt")
|
|
|
|
file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${suffix_${buildtype}}/meson-logs/install-log.txt" DESTINATION "${CURRENT_BUILDTREES_DIR}")
|
2021-12-03 07:48:34 +08:00
|
|
|
file(RENAME "${CURRENT_BUILDTREES_DIR}/install-log.txt" "${CURRENT_BUILDTREES_DIR}/install-log-${suffix_${buildtype}}.log")
|
2020-04-07 05:43:16 +08:00
|
|
|
endif()
|
2021-11-09 04:27:18 +08:00
|
|
|
message(STATUS "Configuring ${TARGET_TRIPLET}-${suffix_${buildtype}} done")
|
|
|
|
|
|
|
|
vcpkg_restore_env_variables(VARS PKG_CONFIG PKG_CONFIG_PATH)
|
2020-11-19 05:36:20 +08:00
|
|
|
endforeach()
|
2017-02-10 01:13:52 +08:00
|
|
|
|
2021-11-09 04:27:18 +08:00
|
|
|
vcpkg_restore_env_variables(VARS INCLUDE)
|
2017-02-10 01:13:52 +08:00
|
|
|
endfunction()
|