2022-10-14 00:40:52 +08:00
function ( z_vcpkg_meson_set_proglist_variables config_type )
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 } )
2022-10-14 00:40:52 +08:00
string ( TOUPPER "MESON_${meson_${prog}}" var_to_set )
set ( "${var_to_set}" "${meson_${prog}} = ['${VCPKG_DETECTED_CMAKE_${prog}}']" PARENT_SCOPE )
elseif ( ${ prog } STREQUAL AR AND VCPKG_DETECTED_CMAKE_STATIC_LINKER_FLAGS_ ${ config_type } )
# Probably need to move AR somewhere else
string ( TOLOWER "${prog}" proglower )
z_vcpkg_meson_convert_compiler_flags_to_list ( ar_flags "${VCPKG_DETECTED_CMAKE_STATIC_LINKER_FLAGS_${config_type}}" )
list ( PREPEND ar_flags "${VCPKG_DETECTED_CMAKE_${prog}}" )
z_vcpkg_meson_convert_list_to_python_array ( ar_flags ${ ar_flags } )
set ( "MESON_AR" "${proglower} = ${ar_flags}" PARENT_SCOPE )
2021-12-17 14:47:16 +08:00
else ( )
2022-10-14 00:40:52 +08:00
string ( TOUPPER "MESON_${prog}" var_to_set )
2021-12-17 14:47:16 +08:00
string ( TOLOWER "${prog}" proglower )
2022-10-14 00:40:52 +08:00
set ( "${var_to_set}" "${proglower} = ['${VCPKG_DETECTED_CMAKE_${prog}}']" PARENT_SCOPE )
2021-12-17 14:47:16 +08:00
endif ( )
2020-11-19 05:36:20 +08:00
endif ( )
endforeach ( )
2022-10-14 00:40:52 +08:00
set ( compilers "${arg_LANGUAGES}" )
if ( VCPKG_TARGET_IS_WINDOWS )
list ( APPEND compilers RC )
endif ( )
2021-12-17 14:47:16 +08:00
set ( meson_RC windres )
2022-10-14 00:40:52 +08:00
set ( meson_Fortran fc )
2021-12-17 14:47:16 +08:00
set ( meson_CXX cpp )
2022-10-14 00:40:52 +08:00
foreach ( prog IN LISTS compilers )
2020-11-19 05:36:20 +08:00
if ( VCPKG_DETECTED_CMAKE_ ${ prog } _COMPILER )
2022-10-14 00:40:52 +08:00
string ( TOUPPER "MESON_${prog}" var_to_set )
2021-12-17 14:47:16 +08:00
if ( meson_ ${ prog } )
2022-10-14 00:40:52 +08:00
set ( "${var_to_set}" "${meson_${prog}} = ['${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}']" PARENT_SCOPE )
if ( DEFINED VCPKG_DETECTED_CMAKE_ ${ prog } _COMPILER_ID AND NOT VCPKG_DETECTED_CMAKE_ ${ prog } _COMPILER_ID MATCHES "^(GNU|Intel)$" )
string ( TOUPPER "MESON_${prog}_LD" var_to_set )
set ( ${ var_to_set } "${meson_${prog}}_ld = ['${VCPKG_DETECTED_CMAKE_LINKER}']" PARENT_SCOPE )
endif ( )
elseif ( ${ prog } MATCHES RC AND VCPKG_DETECTED_CMAKE_RC_FLAGS_ ${ config_type } )
z_vcpkg_meson_convert_compiler_flags_to_list ( rc_flags "${VCPKG_DETECTED_CMAKE_RC_FLAGS_${config_type}}" )
list ( PREPEND rc_flags "${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}" )
z_vcpkg_meson_convert_list_to_python_array ( rc_flags ${ rc_flags } )
set ( "${var_to_set}" "${meson_${prog}} = ${rc_flags}" PARENT_SCOPE )
2021-12-17 14:47:16 +08:00
else ( )
string ( TOLOWER "${prog}" proglower )
2022-10-14 00:40:52 +08:00
set ( "${var_to_set}" "${proglower} = ['${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}']" PARENT_SCOPE )
if ( DEFINED VCPKG_DETECTED_CMAKE_ ${ prog } _COMPILER_ID AND NOT VCPKG_DETECTED_CMAKE_ ${ prog } _COMPILER_ID MATCHES "^(GNU|Intel)$" )
string ( TOUPPER "MESON_${prog}_LD" var_to_set )
set ( ${ var_to_set } "${proglower}_ld = ['${VCPKG_DETECTED_CMAKE_LINKER}']" PARENT_SCOPE )
endif ( )
2021-12-17 14:47:16 +08:00
endif ( )
2020-11-19 05:36:20 +08:00
endif ( )
endforeach ( )
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 " t m p _ v a r " $ { t m p _ v a r } " )
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
2022-10-14 00:40:52 +08:00
function ( z_vcpkg_meson_set_flags_variables config_type )
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 ( )
2022-10-14 00:40:52 +08:00
set ( includepath "-I${CURRENT_INSTALLED_DIR}/include" )
2021-11-09 04:27:18 +08:00
set ( libpath "${libpath_flag}${CURRENT_INSTALLED_DIR}${path_suffix}/lib" )
2022-10-14 00:40:52 +08:00
foreach ( lang IN LISTS arg_LANGUAGES )
z_vcpkg_meson_convert_compiler_flags_to_list ( ${ lang } flags "${VCPKG_DETECTED_CMAKE_${lang}_FLAGS_${config_type}}" )
if ( lang MATCHES "^(C|CXX)$" )
vcpkg_list ( APPEND ${ lang } flags "${includepath}" )
2022-02-25 03:04:11 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
z_vcpkg_meson_convert_list_to_python_array ( ${ lang } flags ${ ${lang } flags} )
set ( lang_mapping "${lang}" )
if ( lang STREQUAL "Fortran" )
set ( lang_mapping "FC" )
2020-11-19 05:36:20 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
string ( TOLOWER "${lang_mapping}" langlower )
if ( lang STREQUAL "CXX" )
set ( langlower cpp )
2020-11-19 05:36:20 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
set ( MESON_ ${ lang_mapping } FLAGS "${langlower}_args = ${${lang}flags}\n" )
set ( linker_flags "${VCPKG_DETECTED_CMAKE_SHARED_LINKER_FLAGS_${config_type}}" )
z_vcpkg_meson_convert_compiler_flags_to_list ( linker_flags "${linker_flags}" )
vcpkg_list ( APPEND linker_flags "${libpath}" )
z_vcpkg_meson_convert_list_to_python_array ( linker_flags ${ linker_flags } )
string ( APPEND MESON_ ${ lang_mapping } FLAGS "${langlower}_link_args = ${linker_flags}" )
set ( MESON_ ${ lang_mapping } FLAGS "${MESON_${lang_mapping}FLAGS}" PARENT_SCOPE )
endforeach ( )
2020-11-19 05:36:20 +08:00
endfunction ( )
2020-04-07 05:43:16 +08:00
2022-10-14 00:40:52 +08:00
function ( z_vcpkg_get_build_and_host_system build_system host_system is_cross ) #https://mesonbuild.com/Cross-compilation.html
set ( build_unknown FALSE )
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 ( )
2022-10-14 00:40:52 +08:00
if ( NOT DEFINED VCPKG_MESON_CROSS_FILE OR NOT DEFINED VCPKG_MESON_NATIVE_FILE )
message ( WARNING "Unsupported build architecture ${build_arch}! Please set VCPKG_MESON_(CROSS|NATIVE)_FILE to a meson file containing the build_machine entry!" )
endif ( )
set ( build_unknown TRUE )
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 (
C O M M A N D u n a m e - m
O U T P U T _ V A R I A B L E M A C H I N E
2023-01-20 10:39:39 +08:00
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
2021-05-27 05:00:07 +08:00
C O M M A N D _ E R R O R _ I S _ F A T A L A N Y )
2022-10-14 00:40:52 +08:00
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 )
2022-10-01 08:22:06 +08:00
elseif ( MACHINE MATCHES "armv7h?l" )
set ( build_cpu_fam arm )
set ( build_cpu ${ MACHINE } )
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 )
2022-07-18 10:41:15 +08:00
elseif ( MACHINE MATCHES "loongarch64" )
set ( build_cpu_fam loongarch64 )
set ( build_cpu loongarch64 )
2021-05-27 05:00:07 +08:00
else ( )
# https://github.com/mesonbuild/meson/blob/master/docs/markdown/Reference-tables.md#cpu-families
2022-10-14 00:40:52 +08:00
if ( NOT DEFINED VCPKG_MESON_CROSS_FILE OR NOT DEFINED VCPKG_MESON_NATIVE_FILE )
message ( WARNING "Unhandled machine: ${MACHINE}! Please set VCPKG_MESON_(CROSS|NATIVE)_FILE to a meson file containing the build_machine entry!" )
endif ( )
set ( build_unknown TRUE )
2021-05-27 05:00:07 +08:00
endif ( )
else ( )
2022-10-14 00:40:52 +08:00
if ( NOT DEFINED VCPKG_MESON_CROSS_FILE OR NOT DEFINED VCPKG_MESON_NATIVE_FILE )
message ( WARNING "Failed to detect the build architecture! Please set VCPKG_MESON_(CROSS|NATIVE)_FILE to a meson file containing the build_machine entry!" )
endif ( )
set ( build_unknown TRUE )
2020-11-19 05:36:20 +08:00
endif ( )
2020-04-07 05:43:16 +08:00
2022-10-14 00:40:52 +08:00
set ( build "[build_machine]\n" ) # Machine the build is performed on
string ( APPEND build "endian = 'little'\n" )
if ( WIN32 )
string ( APPEND build "system = 'windows'\n" )
elseif ( DARWIN )
string ( APPEND build "system = 'darwin'\n" )
elseif ( CYGWIN )
string ( APPEND build "system = 'cygwin'\n" )
elseif ( UNIX )
string ( APPEND build "system = 'linux'\n" )
else ( )
set ( build_unknown TRUE )
endif ( )
if ( DEFINED build_cpu_fam )
string ( APPEND build "cpu_family = '${build_cpu_fam}'\n" )
endif ( )
if ( DEFINED build_cpu )
string ( APPEND build "cpu = '${build_cpu}'" )
endif ( )
if ( NOT build_unknown )
set ( ${ build_system } "${build}" PARENT_SCOPE )
endif ( )
set ( host_unkown FALSE )
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 )
2022-07-18 10:41:15 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "loongarch64" )
set ( host_cpu_fam loongarch64 )
set ( host_cpu loongarch64 )
2022-10-01 08:23:42 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "wasm32" )
set ( host_cpu_fam wasm32 )
set ( host_cpu wasm32 )
2020-11-19 05:36:20 +08:00
else ( )
2022-10-14 00:40:52 +08:00
if ( NOT DEFINED VCPKG_MESON_CROSS_FILE OR NOT DEFINED VCPKG_MESON_NATIVE_FILE )
message ( WARNING "Unsupported target architecture ${VCPKG_TARGET_ARCHITECTURE}! Please set VCPKG_MESON_(CROSS|NATIVE)_FILE to a meson file containing the host_machine entry!" )
endif ( )
set ( host_unkown TRUE )
2020-11-19 05:36:20 +08:00
endif ( )
2021-12-17 14:47:16 +08:00
2022-10-14 00:40:52 +08:00
set ( host "[host_machine]\n" ) # host=target in vcpkg.
string ( APPEND host "endian = 'little'\n" )
2022-08-18 03:36:12 +08:00
if ( NOT VCPKG_CMAKE_SYSTEM_NAME OR VCPKG_TARGET_IS_MINGW OR VCPKG_TARGET_IS_UWP )
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 ( )
2022-10-14 00:40:52 +08:00
string ( APPEND host "system = '${meson_system_name}'\n" )
string ( APPEND host "cpu_family = '${host_cpu_fam}'\n" )
string ( APPEND host "cpu = '${host_cpu}'" )
if ( NOT host_unkown )
set ( ${ host_system } "${host}" PARENT_SCOPE )
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}"
O R V C P K G _ T A R G E T _ I S _ A N D R O I D O R V C P K G _ T A R G E T _ I S _ I O S O R V C P K G _ T A R G E T _ I S _ U W P
OR ( VCPKG_TARGET_IS_MINGW AND NOT WIN32 ) )
2022-10-14 00:40:52 +08:00
set ( ${ is_cross } TRUE PARENT_SCOPE )
2020-11-19 05:36:20 +08:00
endif ( )
endfunction ( )
2022-10-14 00:40:52 +08:00
function ( z_vcpkg_meson_setup_extra_windows_variables config_type )
## b_vscrt
if ( VCPKG_CRT_LINKAGE STREQUAL "static" )
set ( crt_type "mt" )
else ( )
set ( crt_type "md" )
endif ( )
if ( config_type STREQUAL "DEBUG" )
set ( crt_type "${crt_type}d" )
endif ( )
set ( MESON_VSCRT_LINKAGE "b_vscrt = '${crt_type}'" PARENT_SCOPE )
## winlibs
separate_arguments ( c_winlibs NATIVE_COMMAND "${VCPKG_DETECTED_CMAKE_C_STANDARD_LIBRARIES}" )
separate_arguments ( cpp_winlibs NATIVE_COMMAND "${VCPKG_DETECTED_CMAKE_CXX_STANDARD_LIBRARIES}" )
z_vcpkg_meson_convert_list_to_python_array ( c_winlibs ${ c_winlibs } )
z_vcpkg_meson_convert_list_to_python_array ( cpp_winlibs ${ cpp_winlibs } )
set ( MESON_WINLIBS "c_winlibs = ${c_winlibs}\n" )
string ( APPEND MESON_WINLIBS "cpp_winlibs = ${cpp_winlibs}" )
set ( MESON_WINLIBS "${MESON_WINLIBS}" PARENT_SCOPE )
2020-11-19 05:36:20 +08:00
endfunction ( )
2022-10-14 00:40:52 +08:00
function ( z_vcpkg_meson_setup_variables config_type )
set ( meson_var_list VSCRT_LINKAGE WINLIBS MT AR RC C C_LD CXX CXX_LD OBJC OBJC_LD OBJCXX OBJCXX_LD FC FC_LD WINDRES CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS FCFLAGS SHARED_LINKER_FLAGS )
foreach ( var IN LISTS meson_var_list )
set ( MESON_ ${ var } "" )
endforeach ( )
if ( VCPKG_TARGET_IS_WINDOWS )
z_vcpkg_meson_setup_extra_windows_variables ( "${config_type}" )
endif ( )
z_vcpkg_meson_set_proglist_variables ( "${config_type}" )
z_vcpkg_meson_set_flags_variables ( "${config_type}" )
foreach ( var IN LISTS meson_var_list )
set ( MESON_ ${ var } "${MESON_${var}}" PARENT_SCOPE )
endforeach ( )
endfunction ( )
2020-11-19 05:36:20 +08:00
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
" N O _ P K G _ C O N F I G "
" S O U R C E _ P A T H "
2022-10-14 00:40:52 +08:00
" O P T I O N S ; O P T I O N S _ D E B U G ; O P T I O N S _ R E L E A S E ; L A N G U A G E S ; A D D I T I O N A L _ B I N A R I E S ; A D D I T I O N A L _ N A T I V E _ B I N A R I E S ; A D D I T I O N A L _ C R O S S _ B I N A R I E S "
2021-11-09 04:27:18 +08:00
)
2020-11-19 05:36:20 +08:00
2022-10-14 00:40:52 +08:00
if ( NOT arg_LANGUAGES )
set ( arg_LANGUAGES C CXX )
endif ( )
if ( DEFINED arg_ADDITIONAL_NATIVE_BINARIES OR DEFINED arg_ADDITIONAL_CROSS_BINARIES )
message ( WARNING "Options ADDITIONAL_(NATIVE|CROSS)_BINARIES have been deprecated. Only use ADDITIONAL_BINARIES!" )
endif ( )
vcpkg_list ( APPEND arg_ADDITIONAL_BINARIES ${ arg_ADDITIONAL_NATIVE_BINARIES } ${ arg_ADDITIONAL_CROSS_BINARIES } )
vcpkg_list ( REMOVE_DUPLICATES arg_ADDITIONAL_BINARIES )
vcpkg_list ( JOIN arg_ADDITIONAL_BINARIES "\n" MESON_ADDITIONAL_BINARIES )
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
2022-10-14 00:40:52 +08:00
if ( NOT VCPKG_CHAINLOAD_TOOLCHAIN_FILE )
z_vcpkg_select_default_vcpkg_chainload_toolchain ( )
endif ( )
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 )
2022-10-14 00:40:52 +08:00
get_filename_component ( CMAKE_PATH "${CMAKE_COMMAND}" DIRECTORY )
vcpkg_add_to_path ( "${CMAKE_PATH}" PREPEND ) # Make CMake invokeable for Meson
2020-11-19 05:36:20 +08:00
2022-10-14 00:40:52 +08:00
vcpkg_find_acquire_program ( PYTHON3 )
get_filename_component ( PYTHON3_DIR "${PYTHON3}" DIRECTORY )
vcpkg_add_to_path ( "${PYTHON3_DIR}" )
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.
set ( buildtypes "" )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
set ( buildname "DEBUG" )
vcpkg_list ( APPEND buildtypes "${buildname}" )
set ( path_suffix_ ${ buildname } "debug/" )
set ( suffix_ ${ buildname } "dbg" )
set ( meson_input_file_ ${ buildname } "${CURRENT_BUILDTREES_DIR}/meson-${TARGET_TRIPLET}-${suffix_${buildname}}.log" )
2022-07-18 10:41:15 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release" )
set ( buildname "RELEASE" )
vcpkg_list ( APPEND buildtypes "${buildname}" )
set ( path_suffix_ ${ buildname } "" )
set ( suffix_ ${ buildname } "rel" )
set ( meson_input_file_ ${ buildname } "${CURRENT_BUILDTREES_DIR}/meson-${TARGET_TRIPLET}-${suffix_${buildname}}.log" )
2022-07-18 10:41:15 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
vcpkg_list ( APPEND arg_OPTIONS --buildtype plain --backend ninja --wrap-mode nodownload )
z_vcpkg_get_build_and_host_system ( MESON_HOST_MACHINE MESON_BUILD_MACHINE IS_CROSS )
if ( IS_CROSS )
# VCPKG_CROSSCOMPILING is not used since it regresses a lot of ports in x64-windows-x triplets
# For consistency this should proably be changed in the future?
vcpkg_list ( APPEND arg_OPTIONS --native "${SCRIPTS}/buildsystems/meson/none.txt" )
vcpkg_list ( APPEND arg_OPTIONS_DEBUG --cross "${meson_input_file_DEBUG}" )
vcpkg_list ( APPEND arg_OPTIONS_RELEASE --cross "${meson_input_file_RELEASE}" )
else ( )
vcpkg_list ( APPEND arg_OPTIONS_DEBUG --native "${meson_input_file_DEBUG}" )
vcpkg_list ( APPEND arg_OPTIONS_RELEASE --native "${meson_input_file_RELEASE}" )
2020-11-19 05:36:20 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
# User provided cross/native files
if ( VCPKG_MESON_NATIVE_FILE )
vcpkg_list ( APPEND arg_OPTIONS_RELEASE --native "${VCPKG_MESON_NATIVE_FILE}" )
2020-11-19 05:36:20 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
if ( VCPKG_MESON_NATIVE_FILE_RELEASE )
vcpkg_list ( APPEND arg_OPTIONS_RELEASE --native "${VCPKG_MESON_NATIVE_FILE_RELEASE}" )
2020-11-19 05:36:20 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
if ( VCPKG_MESON_NATIVE_FILE_DEBUG )
vcpkg_list ( APPEND arg_OPTIONS_DEBUG --native "${VCPKG_MESON_NATIVE_FILE_DEBUG}" )
2020-11-19 05:36:20 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
if ( VCPKG_MESON_CROSS_FILE )
vcpkg_list ( APPEND arg_OPTIONS_RELEASE --cross "${VCPKG_MESON_CROSS_FILE}" )
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 ( )
2022-10-14 00:40:52 +08:00
if ( VCPKG_MESON_CROSS_FILE_DEBUG )
vcpkg_list ( APPEND arg_OPTIONS_DEBUG --cross "${VCPKG_MESON_CROSS_FILE_DEBUG}" )
2021-04-01 02:54:44 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
2020-02-13 07:58:43 +08:00
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" )
2022-10-14 00:40:52 +08:00
set ( MESON_DEFAULT_LIBRARY shared )
2017-02-10 01:13:52 +08:00
else ( )
2022-10-14 00:40:52 +08:00
set ( MESON_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 ( )
2022-10-14 00:40:52 +08:00
# Allow overrides / additional configuration variables from triplets
if ( DEFINED VCPKG_MESON_CONFIGURE_OPTIONS )
vcpkg_list ( APPEND arg_OPTIONS ${ VCPKG_MESON_CONFIGURE_OPTIONS } )
2020-11-19 05:36:20 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
if ( DEFINED VCPKG_MESON_CONFIGURE_OPTIONS_RELEASE )
vcpkg_list ( APPEND arg_OPTIONS_RELEASE ${ VCPKG_MESON_CONFIGURE_OPTIONS_RELEASE } )
endif ( )
if ( DEFINED VCPKG_MESON_CONFIGURE_OPTIONS_DEBUG )
vcpkg_list ( APPEND arg_OPTIONS_DEBUG ${ VCPKG_MESON_CONFIGURE_OPTIONS_DEBUG } )
2020-11-19 05:36:20 +08:00
endif ( )
# 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
if ( NOT arg_NO_PKG_CONFIG )
2022-05-10 08:23:32 +08:00
if ( "${buildtype}" STREQUAL "DEBUG" )
z_vcpkg_setup_pkgconfig_path ( BASE_DIRS "${CURRENT_INSTALLED_DIR}/debug" )
else ( )
z_vcpkg_setup_pkgconfig_path ( BASE_DIRS "${CURRENT_INSTALLED_DIR}" )
endif ( )
2020-04-07 05:43:16 +08:00
endif ( )
2022-10-14 00:40:52 +08:00
z_vcpkg_meson_setup_variables ( ${ buildtype } )
configure_file ( "${SCRIPTS}/buildsystems/meson/meson.template.in" "${meson_input_file_${buildtype}}" @ONLY )
2017-11-26 07:25:18 +08:00
vcpkg_execute_required_process (
2021-11-09 04:27:18 +08:00
C O M M A N D $ { M E S O N } $ { a r g _ O P T I O N S } $ { a r g _ O P T I O N S _ $ { b u i l d t y p e } } $ { a r g _ S O U R C E _ P A T H }
W O R K I N G _ D I R E C T O R Y " $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - $ { s u f f i x _ $ { b u i l d t y p e } } "
L O G N A M E c o n f i g - $ { T A R G E T _ T R I P L E T } - $ { s u f f i x _ $ { b u i l d t y p e } }
2022-07-19 04:21:36 +08:00
S A V E _ L O G _ F I L E S
m e s o n - l o g s / m e s o n - l o g . t x t
m e s o n - i n f o / i n t r o - d e p e n d e n c i e s . j s o n
m e s o n - l o g s / i n s t a l l - l o g . t x t
2017-11-26 07:25:18 +08:00
)
2020-11-19 05:36:20 +08:00
2021-11-09 04:27:18 +08:00
message ( STATUS "Configuring ${TARGET_TRIPLET}-${suffix_${buildtype}} done" )
2022-05-10 08:23:32 +08:00
if ( NOT arg_NO_PKG_CONFIG )
z_vcpkg_restore_pkgconfig_path ( )
endif ( )
2020-11-19 05:36:20 +08:00
endforeach ( )
2017-02-10 01:13:52 +08:00
endfunction ( )