2020-12-02 05:37:26 +08:00
#[===[.md:
# vcpkg_configure_meson
C o n f i g u r e M e s o n f o r D e b u g a n d R e l e a s e b u i l d s o f a p r o j e c t .
## Usage
` ` ` c m a k e
vcpkg_configure_meson (
S O U R C E _ P A T H < $ { S O U R C E _ P A T H } >
2021-09-25 03:11:38 +08:00
[ N O _ P K G _ C O N F I G ]
2020-12-02 05:37:26 +08:00
[ O P T I O N S < - D U S E _ T H I S _ I N _ A L L _ B U I L D S = 1 > . . . ]
[ O P T I O N S _ R E L E A S E < - D O P T I M I Z E = 1 > . . . ]
[ O P T I O N S _ D E B U G < - D D E B U G G A B L E = 1 > . . . ]
)
` ` `
## Parameters
### SOURCE_PATH
S p e c i f i e s t h e d i r e c t o r y c o n t a i n i n g t h e ` m e s o n . b u i l d ` .
B y c o n v e n t i o n , t h i s i s u s u a l l y s e t i n t h e p o r t f i l e a s t h e v a r i a b l e ` S O U R C E _ P A T H ` .
### OPTIONS
A d d i t i o n a l o p t i o n s p a s s e d t o M e s o n d u r i n g t h e c o n f i g u r a t i o n .
### OPTIONS_RELEASE
A d d i t i o n a l o p t i o n s p a s s e d t o M e s o n d u r i n g t h e R e l e a s e c o n f i g u r a t i o n . T h e s e a r e i n a d d i t i o n t o ` O P T I O N S ` .
### OPTIONS_DEBUG
A d d i t i o n a l o p t i o n s p a s s e d t o M e s o n d u r i n g t h e D e b u g c o n f i g u r a t i o n . T h e s e a r e i n a d d i t i o n t o ` O P T I O N S ` .
2021-09-25 03:11:38 +08:00
### NO_PKG_CONFIG
D i s a b l e p k g - c o n f i g s e t u p
2020-12-02 05:37:26 +08:00
## Notes
T h i s c o m m a n d s u p p l i e s m a n y c o m m o n a r g u m e n t s t o M e s o n . T o s e e t h e f u l l l i s t , e x a m i n e t h e s o u r c e .
## Examples
* [ f r i b i d i ] ( h t t p s : / / g i t h u b . c o m / M i c r o s o f t / v c p k g / b l o b / m a s t e r / p o r t s / f r i b i d i / p o r t f i l e . c m a k e )
* [ l i b e p o x y ] ( h t t p s : / / g i t h u b . c o m / M i c r o s o f t / v c p k g / b l o b / m a s t e r / p o r t s / l i b e p o x y / p o r t f i l e . c m a k e )
#]===]
2021-01-12 08:12:01 +08:00
function ( vcpkg_internal_meson_generate_native_file _additional_binaries ) #https://mesonbuild.com/Native-environments.html
2020-11-19 05:36:20 +08:00
set ( NATIVE "[binaries]\n" )
#set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT)
if ( VCPKG_TARGET_IS_WINDOWS )
set ( proglist MT )
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 NATIVE "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n" )
endif ( )
endforeach ( )
set ( compiler C CXX RC )
foreach ( prog IN LISTS compiler )
if ( VCPKG_DETECTED_CMAKE_ ${ prog } _COMPILER )
string ( REPLACE "CXX" "CPP" mesonprog "${prog}" )
2021-09-10 11:41:01 +08:00
string ( REPLACE "RC" "windres" mesonprog "${mesonprog}" ) # https://mesonbuild.com/Windows-module.html
2020-11-19 05:36:20 +08:00
string ( TOLOWER "${mesonprog}" proglower )
string ( APPEND NATIVE "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n" )
endif ( )
endforeach ( )
if ( VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS )
2021-09-10 11:41:01 +08:00
if ( NOT VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "^(GNU|Intel)$" ) # for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
string ( APPEND NATIVE "c_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n" )
endif ( )
endif ( )
if ( VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS )
if ( NOT VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Intel)$" ) # for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
string ( APPEND NATIVE "cpp_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n" )
endif ( )
2020-11-19 05:36:20 +08:00
endif ( )
string ( APPEND NATIVE "cmake = '${CMAKE_COMMAND}'\n" )
2021-01-12 08:12:01 +08:00
foreach ( _binary IN LISTS ${ _additional_binaries } )
string ( APPEND NATIVE "${_binary}\n" )
endforeach ( )
2020-11-19 05:36:20 +08:00
string ( APPEND NATIVE "[built-in options]\n" ) #https://mesonbuild.com/Builtin-options.html
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-04-01 02:54:44 +08:00
# string(APPEND NATIVE "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 )
string ( REGEX REPLACE "( |^)(-|/)" ";\\2" WIN_C_STANDARD_LIBRARIES "${VCPKG_DETECTED_CMAKE_C_STANDARD_LIBRARIES}" )
string ( REGEX REPLACE "\\.lib " ".lib;" WIN_C_STANDARD_LIBRARIES "${WIN_C_STANDARD_LIBRARIES}" )
list ( TRANSFORM WIN_C_STANDARD_LIBRARIES APPEND "'" )
list ( TRANSFORM WIN_C_STANDARD_LIBRARIES PREPEND "'" )
2021-09-10 11:41:01 +08:00
list ( REMOVE_ITEM WIN_C_STANDARD_LIBRARIES "''" )
2020-11-19 05:36:20 +08:00
list ( JOIN WIN_C_STANDARD_LIBRARIES ", " WIN_C_STANDARD_LIBRARIES )
string ( APPEND NATIVE "c_winlibs = [${WIN_C_STANDARD_LIBRARIES}]\n" )
string ( REGEX REPLACE "( |^)(-|/)" ";\\2" WIN_CXX_STANDARD_LIBRARIES "${VCPKG_DETECTED_CMAKE_CXX_STANDARD_LIBRARIES}" )
string ( REGEX REPLACE "\\.lib " ".lib;" WIN_CXX_STANDARD_LIBRARIES "${WIN_CXX_STANDARD_LIBRARIES}" )
list ( TRANSFORM WIN_CXX_STANDARD_LIBRARIES APPEND "'" )
list ( TRANSFORM WIN_CXX_STANDARD_LIBRARIES PREPEND "'" )
2021-09-10 11:41:01 +08:00
list ( REMOVE_ITEM WIN_CXX_STANDARD_LIBRARIES "''" )
2020-11-19 05:36:20 +08:00
list ( JOIN WIN_CXX_STANDARD_LIBRARIES ", " WIN_CXX_STANDARD_LIBRARIES )
string ( APPEND NATIVE "cpp_winlibs = [${WIN_CXX_STANDARD_LIBRARIES}]\n" )
endif ( )
set ( _file "${CURRENT_BUILDTREES_DIR}/meson-nativ-${TARGET_TRIPLET}.log" )
set ( VCPKG_MESON_NATIVE_FILE "${_file}" PARENT_SCOPE )
file ( WRITE "${_file}" "${NATIVE}" )
endfunction ( )
2021-02-11 16:44:49 +08:00
function ( vcpkg_internal_meson_convert_compiler_flags_to_list _out_var _compiler_flags )
2021-04-01 02:54:44 +08:00
string ( REPLACE ";" "\\\;" tmp_var "${_compiler_flags}" )
string ( REGEX REPLACE [=[( +|^ ) ( ( \ " ( \ \ \ " | [ ^ " ] ) + \ " | \ \ \ " | \ \ | [ ^ ] ) + ) ] = ] " ; \ \ 2 " $ { _ o u t _ v a r } " $ { t m p _ v a r } " )
list ( POP_FRONT ${ _out_var } ) # The first element is always empty due to the above replacement
list ( TRANSFORM ${ _out_var } STRIP ) # Strip leading trailing whitespaces from each element in the list.
2021-02-11 16:44:49 +08:00
set ( ${ _out_var } "${${_out_var}}" PARENT_SCOPE )
endfunction ( )
2021-04-01 02:54:44 +08:00
function ( vcpkg_internal_meson_convert_list_to_python_array _out_var )
set ( FLAG_LIST ${ ARGN } )
list ( TRANSFORM FLAG_LIST APPEND "'" )
list ( TRANSFORM FLAG_LIST PREPEND "'" )
list ( JOIN FLAG_LIST ", " ${ _out_var } )
string ( REPLACE "'', " "" ${ _out_var } "${${_out_var}}" ) # remove empty elements if any
set ( ${ _out_var } "[${${_out_var}}]" PARENT_SCOPE )
endfunction ( )
# Generates the required compiler properties for meson
function ( vcpkg_internal_meson_generate_flags_properties_string _out_var _config )
2021-05-25 06:09:58 +08:00
if ( VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW )
2020-11-19 05:36:20 +08:00
set ( L_FLAG /LIBPATH: )
else ( )
set ( L_FLAG -L )
endif ( )
set ( PATH_SUFFIX_DEBUG /debug )
2021-04-01 02:54:44 +08:00
set ( LIBPATH_ ${ _config } "${L_FLAG}${CURRENT_INSTALLED_DIR}${PATH_SUFFIX_${_config}}/lib" )
2021-02-11 16:44:49 +08:00
vcpkg_internal_meson_convert_compiler_flags_to_list ( MESON_CFLAGS_ ${ _config } "${VCPKG_DETECTED_CMAKE_C_FLAGS_${_config}}" )
2021-09-10 11:41:01 +08:00
list ( APPEND MESON_CFLAGS_ ${ _config } "-I${CURRENT_INSTALLED_DIR}/include" )
2021-04-01 02:54:44 +08:00
vcpkg_internal_meson_convert_list_to_python_array ( MESON_CFLAGS_ ${ _config } ${ MESON_CFLAGS_${_config } } )
string ( APPEND ${ _out_var } "c_args = ${MESON_CFLAGS_${_config}}\n" )
2021-02-11 16:44:49 +08:00
vcpkg_internal_meson_convert_compiler_flags_to_list ( MESON_CXXFLAGS_ ${ _config } "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_${_config}}" )
2021-09-10 11:41:01 +08:00
list ( APPEND MESON_CXXFLAGS_ ${ _config } "-I${CURRENT_INSTALLED_DIR}/include" )
2021-04-01 02:54:44 +08:00
vcpkg_internal_meson_convert_list_to_python_array ( MESON_CXXFLAGS_ ${ _config } ${ MESON_CXXFLAGS_${_config } } )
string ( APPEND ${ _out_var } "cpp_args = ${MESON_CXXFLAGS_${_config}}\n" )
2020-11-19 05:36:20 +08:00
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" )
set ( LINKER_FLAGS_ ${ _config } "${VCPKG_DETECTED_CMAKE_SHARED_LINKER_FLAGS_${_config}}" )
else ( )
set ( LINKER_FLAGS_ ${ _config } "${VCPKG_DETECTED_CMAKE_STATIC_LINKER_FLAGS_${_config}}" )
endif ( )
2021-02-21 13:29:35 +08:00
vcpkg_internal_meson_convert_compiler_flags_to_list ( LINKER_FLAGS_ ${ _config } "${LINKER_FLAGS_${_config}}" )
2020-11-19 05:36:20 +08:00
list ( APPEND LINKER_FLAGS_ ${ _config } "${LIBPATH_${_config}}" )
2021-04-01 02:54:44 +08:00
vcpkg_internal_meson_convert_list_to_python_array ( LINKER_FLAGS_ ${ _config } ${ LINKER_FLAGS_${_config } } )
string ( APPEND ${ _out_var } "c_link_args = ${LINKER_FLAGS_${_config}}\n" )
string ( APPEND ${ _out_var } "cpp_link_args = ${LINKER_FLAGS_${_config}}\n" )
set ( ${ _out_var } "${${_out_var}}" PARENT_SCOPE )
endfunction ( )
2020-11-19 05:36:20 +08:00
2021-04-01 02:54:44 +08:00
function ( vcpkg_internal_meson_generate_native_file_config _config ) #https://mesonbuild.com/Native-environments.html
set ( NATIVE_ ${ _config } "[properties]\n" ) #https://mesonbuild.com/Builtin-options.html
vcpkg_internal_meson_generate_flags_properties_string ( NATIVE_PROPERTIES ${ _config } )
string ( APPEND NATIVE_ ${ _config } "${NATIVE_PROPERTIES}" )
2020-11-19 05:36:20 +08:00
#Setup CMake properties
string ( APPEND NATIVE_ ${ _config } "cmake_toolchain_file = '${SCRIPTS}/buildsystems/vcpkg.cmake'\n" )
string ( APPEND NATIVE_ ${ _config } "[cmake]\n" )
2020-04-07 05:43:16 +08:00
if ( NOT VCPKG_CHAINLOAD_TOOLCHAIN_FILE )
if ( VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW )
set ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/windows.cmake" )
elseif ( VCPKG_TARGET_IS_LINUX )
set ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/linux.cmake" )
elseif ( VCPKG_TARGET_IS_ANDROID )
set ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/android.cmake" )
elseif ( VCPKG_TARGET_IS_OSX )
set ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/osx.cmake" )
2020-11-19 05:36:20 +08:00
elseif ( VCPKG_TARGET_IS_IOS )
set ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/ios.cmake" )
elseif ( VCPKG_TARGET_IS_FREEBSD )
2020-04-07 05:43:16 +08:00
set ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/freebsd.cmake" )
2020-11-24 01:43:23 +08:00
elseif ( VCPKG_TARGET_IS_OPENBSD )
set ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/openbsd.cmake" )
2020-04-07 05:43:16 +08:00
elseif ( VCPKG_TARGET_IS_MINGW )
set ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/mingw.cmake" )
endif ( )
2017-02-10 01:13:52 +08:00
endif ( )
2020-04-07 05:43:16 +08:00
2020-11-19 05:36:20 +08:00
string ( APPEND NATIVE_ ${ _config } "VCPKG_TARGET_TRIPLET = '${TARGET_TRIPLET}'\n" )
string ( APPEND NATIVE_ ${ _config } "VCPKG_CHAINLOAD_TOOLCHAIN_FILE = '${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}'\n" )
2021-01-12 08:12:01 +08:00
string ( APPEND NATIVE_ ${ _config } "VCPKG_CRT_LINKAGE = '${VCPKG_CRT_LINKAGE}'\n" )
2020-04-07 05:43:16 +08:00
2020-11-19 05:36:20 +08:00
string ( APPEND NATIVE_ ${ _config } "[built-in options]\n" )
if ( VCPKG_TARGET_IS_WINDOWS )
if ( VCPKG_CRT_LINKAGE STREQUAL "static" )
set ( CRT mt )
else ( )
set ( CRT md )
endif ( )
if ( ${ _config } STREQUAL DEBUG )
set ( CRT ${ CRT } d )
endif ( )
string ( APPEND NATIVE_ ${ _config } "b_vscrt = '${CRT}'\n" )
endif ( )
string ( TOLOWER "${_config}" lowerconfig )
set ( _file "${CURRENT_BUILDTREES_DIR}/meson-nativ-${TARGET_TRIPLET}-${lowerconfig}.log" )
set ( VCPKG_MESON_NATIVE_FILE_ ${ _config } "${_file}" PARENT_SCOPE )
file ( WRITE "${_file}" "${NATIVE_${_config}}" )
endfunction ( )
2020-04-07 05:43:16 +08:00
2021-01-12 08:12:01 +08:00
function ( vcpkg_internal_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} )
set ( BUILD_ARCH $ENV{ PROCESSOR_ARCHITEW6432 } )
else ( )
set ( BUILD_ARCH $ENV{ PROCESSOR_ARCHITECTURE } )
endif ( )
if ( BUILD_ARCH MATCHES "(amd|AMD)64" )
2021-05-27 05:00:07 +08:00
set ( BUILD_CPU_FAM x86_64 )
set ( BUILD_CPU x86_64 )
2020-11-19 05:36:20 +08:00
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 )
else ( )
2021-05-27 05:00:07 +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 (
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
C O M M A N D _ E R R O R _ I S _ F A T A L A N Y )
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
if ( MACHINE MATCHES "arm64" )
set ( BUILD_CPU_FAM aarch64 )
set ( BUILD_CPU armv8 )
elseif ( MACHINE MATCHES "x86_64|amd64" )
set ( BUILD_CPU_FAM x86_64 )
set ( BUILD_CPU x86_64 )
elseif ( MACHINE MATCHES "x86|i686" )
set ( BUILD_CPU_FAM x86 )
set ( BUILD_CPU i686 )
elseif ( MACHINE MATCHES "i386" )
set ( BUILD_CPU_FAM x86 )
set ( BUILD_CPU i386 )
else ( )
unset ( BUILD_CPU_FAM )
unset ( BUILD_CPU )
# 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-05-27 05:00:07 +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" )
set ( HOST_CPU_FAM x86 )
set ( HOST_CPU i686 )
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "^(ARM|arm)64$" )
set ( HOST_CPU_FAM aarch64 )
set ( HOST_CPU armv8 )
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "^(ARM|arm)$" )
set ( HOST_CPU_FAM arm )
set ( HOST_CPU armv7hl )
else ( )
message ( FATAL_ERROR "Unsupported target architecture ${VCPKG_TARGET_ARCHITECTURE}!" )
endif ( )
set ( CROSS "[binaries]\n" )
if ( VCPKG_TARGET_IS_WINDOWS )
set ( proglist MT )
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 "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}}'\n" )
endif ( )
endforeach ( )
set ( compiler C CXX RC )
foreach ( prog IN LISTS compiler )
if ( VCPKG_DETECTED_CMAKE_ ${ prog } _COMPILER )
string ( REPLACE "CXX" "CPP" mesonprog "${prog}" )
2021-09-10 11:41:01 +08:00
string ( REPLACE "RC" "windres" mesonprog "${mesonprog}" ) # https://mesonbuild.com/Windows-module.html
2020-11-19 05:36:20 +08:00
string ( TOLOWER "${mesonprog}" proglower )
string ( APPEND CROSS "${proglower} = '${VCPKG_DETECTED_CMAKE_${prog}_COMPILER}'\n" )
endif ( )
endforeach ( )
if ( VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS )
2021-09-10 11:41:01 +08:00
if ( NOT VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "^(GNU|Intel)$" ) # for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
string ( APPEND CROSS "c_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n" )
endif ( )
endif ( )
if ( VCPKG_DETECTED_CMAKE_LINKER AND VCPKG_TARGET_IS_WINDOWS )
if ( NOT VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Intel)$" ) # for gcc and icc the linker flag -fuse-ld is used. See https://github.com/mesonbuild/meson/issues/8647#issuecomment-878673456
string ( APPEND CROSS "cpp_ld = '${VCPKG_DETECTED_CMAKE_LINKER}'\n" )
endif ( )
2020-11-19 05:36:20 +08:00
endif ( )
2021-09-25 03:02:48 +08:00
string ( APPEND CROSS "cmake = '${CMAKE_COMMAND}'\n" )
2021-01-12 08:12:01 +08:00
foreach ( _binary IN LISTS ${ _additional_binaries } )
string ( APPEND CROSS "${_binary}\n" )
endforeach ( )
2020-11-19 05:36:20 +08:00
string ( APPEND CROSS "[properties]\n" )
2021-04-01 02:54:44 +08:00
2020-11-19 05:36:20 +08:00
string ( APPEND CROSS "[host_machine]\n" )
string ( APPEND CROSS "endian = 'little'\n" )
2021-09-10 11:41:01 +08:00
if ( NOT VCPKG_CMAKE_SYSTEM_NAME OR VCPKG_TARGET_IS_MINGW )
2020-11-19 05:36:20 +08:00
set ( MESON_SYSTEM_NAME "windows" )
else ( )
string ( TOLOWER "${VCPKG_CMAKE_SYSTEM_NAME}" MESON_SYSTEM_NAME )
endif ( )
string ( APPEND CROSS "system = '${MESON_SYSTEM_NAME}'\n" )
string ( APPEND CROSS "cpu_family = '${HOST_CPU_FAM}'\n" )
string ( APPEND CROSS "cpu = '${HOST_CPU}'\n" )
2021-05-27 05:00:07 +08:00
2020-11-19 05:36:20 +08:00
string ( APPEND CROSS "[build_machine]\n" )
string ( APPEND CROSS "endian = 'little'\n" )
if ( WIN32 )
string ( APPEND CROSS "system = 'windows'\n" )
elseif ( DARWIN )
string ( APPEND CROSS "system = 'darwin'\n" )
else ( )
string ( APPEND CROSS "system = 'linux'\n" )
endif ( )
2021-05-27 05:00:07 +08:00
if ( DEFINED BUILD_CPU_FAM )
string ( APPEND CROSS "cpu_family = '${BUILD_CPU_FAM}'\n" )
endif ( )
if ( DEFINED BUILD_CPU )
string ( APPEND CROSS "cpu = '${BUILD_CPU}'\n" )
endif ( )
2021-02-21 13:29:35 +08:00
2021-09-10 11:41:01 +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 ) )
2020-11-19 05:36:20 +08:00
set ( _file "${CURRENT_BUILDTREES_DIR}/meson-cross-${TARGET_TRIPLET}.log" )
set ( VCPKG_MESON_CROSS_FILE "${_file}" PARENT_SCOPE )
file ( WRITE "${_file}" "${CROSS}" )
endif ( )
endfunction ( )
function ( vcpkg_internal_meson_generate_cross_file_config _config ) #https://mesonbuild.com/Native-environments.html
2021-04-01 02:54:44 +08:00
set ( CROSS_ ${ _config } "[properties]\n" ) #https://mesonbuild.com/Builtin-options.html
vcpkg_internal_meson_generate_flags_properties_string ( CROSS_PROPERTIES ${ _config } )
string ( APPEND CROSS_ ${ _config } "${CROSS_PROPERTIES}" )
string ( APPEND CROSS_ ${ _config } "[built-in options]\n" )
2020-11-19 05:36:20 +08:00
if ( VCPKG_TARGET_IS_WINDOWS )
if ( VCPKG_CRT_LINKAGE STREQUAL "static" )
set ( CRT mt )
else ( )
set ( CRT md )
endif ( )
if ( ${ _config } STREQUAL DEBUG )
set ( CRT ${ CRT } d )
endif ( )
2021-04-01 02:54:44 +08:00
string ( APPEND CROSS_ ${ _config } "b_vscrt = '${CRT}'\n" )
2020-04-07 05:43:16 +08:00
endif ( )
2020-11-19 05:36:20 +08:00
string ( TOLOWER "${_config}" lowerconfig )
set ( _file "${CURRENT_BUILDTREES_DIR}/meson-cross-${TARGET_TRIPLET}-${lowerconfig}.log" )
set ( VCPKG_MESON_CROSS_FILE_ ${ _config } "${_file}" PARENT_SCOPE )
2021-04-01 02:54:44 +08:00
file ( WRITE "${_file}" "${CROSS_${_config}}" )
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-09-25 03:11:38 +08:00
cmake_parse_arguments ( PARSE_ARGV 0 _vcm "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 ( PYTHON3 )
get_filename_component ( PYTHON3_DIR "${PYTHON3}" DIRECTORY )
vcpkg_add_to_path ( "${PYTHON3_DIR}" )
list ( APPEND _vcm_ADDITIONAL_NATIVE_BINARIES "python = '${PYTHON3}'" )
list ( APPEND _vcm_ADDITIONAL_CROSS_BINARIES "python = '${PYTHON3}'" )
2021-05-27 05:00:07 +08:00
2021-01-12 08:12:01 +08:00
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 ....
# list(APPEND _vcm_ADDITIONAL_NATIVE_BINARIES "ninja = '${NINJA}'") # This does not work due to meson issues ......
2019-05-31 17:50:05 +08:00
list ( APPEND _vcm_OPTIONS --buildtype plain --backend ninja --wrap-mode nodownload )
2020-11-19 05:36:20 +08:00
if ( NOT VCPKG_MESON_CROSS_FILE )
2021-01-12 08:12:01 +08:00
vcpkg_internal_meson_generate_cross_file ( "_vcm_ADDITIONAL_CROSS_BINARIES" )
2020-11-19 05:36:20 +08:00
endif ( )
if ( NOT VCPKG_MESON_CROSS_FILE_DEBUG AND VCPKG_MESON_CROSS_FILE )
vcpkg_internal_meson_generate_cross_file_config ( DEBUG )
endif ( )
if ( NOT VCPKG_MESON_CROSS_FILE_RELEASE AND VCPKG_MESON_CROSS_FILE )
vcpkg_internal_meson_generate_cross_file_config ( RELEASE )
endif ( )
if ( VCPKG_MESON_CROSS_FILE )
list ( APPEND _vcm_OPTIONS --cross "${VCPKG_MESON_CROSS_FILE}" )
endif ( )
if ( VCPKG_MESON_CROSS_FILE_DEBUG )
list ( APPEND _vcm_OPTIONS_DEBUG --cross "${VCPKG_MESON_CROSS_FILE_DEBUG}" )
endif ( )
if ( VCPKG_MESON_CROSS_FILE_RELEASE )
list ( APPEND _vcm_OPTIONS_RELEASE --cross "${VCPKG_MESON_CROSS_FILE_RELEASE}" )
endif ( )
2021-04-01 02:54:44 +08:00
if ( NOT VCPKG_MESON_NATIVE_FILE AND NOT VCPKG_MESON_CROSS_FILE )
vcpkg_internal_meson_generate_native_file ( "_vcm_ADDITIONAL_NATIVE_BINARIES" )
endif ( )
if ( NOT VCPKG_MESON_NATIVE_FILE_DEBUG AND NOT VCPKG_MESON_CROSS_FILE )
vcpkg_internal_meson_generate_native_file_config ( DEBUG )
endif ( )
if ( NOT VCPKG_MESON_NATIVE_FILE_RELEASE AND NOT VCPKG_MESON_CROSS_FILE )
vcpkg_internal_meson_generate_native_file_config ( RELEASE )
endif ( )
if ( VCPKG_MESON_NATIVE_FILE AND NOT VCPKG_MESON_CROSS_FILE )
list ( APPEND _vcm_OPTIONS --native "${VCPKG_MESON_NATIVE_FILE}" )
list ( APPEND _vcm_OPTIONS_DEBUG --native "${VCPKG_MESON_NATIVE_FILE_DEBUG}" )
list ( APPEND _vcm_OPTIONS_RELEASE --native "${VCPKG_MESON_NATIVE_FILE_RELEASE}" )
else ( )
list ( APPEND _vcm_OPTIONS --native "${SCRIPTS}/buildsystems/meson/none.txt" )
endif ( )
2020-02-13 07:58:43 +08:00
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" )
2017-02-10 01:13:52 +08:00
list ( APPEND _vcm_OPTIONS --default-library shared )
else ( )
list ( APPEND _vcm_OPTIONS --default-library static )
endif ( )
2021-05-27 05:00:07 +08:00
2020-04-07 05:43:16 +08:00
list ( APPEND _vcm_OPTIONS --libdir lib ) # else meson install into an architecture describing folder
2020-11-19 05:36:20 +08:00
list ( APPEND _vcm_OPTIONS_DEBUG -Ddebug=true --prefix ${ CURRENT_PACKAGES_DIR } /debug --includedir ../include )
list ( APPEND _vcm_OPTIONS_RELEASE -Ddebug=false --prefix ${ CURRENT_PACKAGES_DIR } )
# select meson cmd-line options
if ( VCPKG_TARGET_IS_WINDOWS )
list ( APPEND _vcm_OPTIONS_DEBUG "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}/debug','${CURRENT_INSTALLED_DIR}','${CURRENT_INSTALLED_DIR}/share']" )
list ( APPEND _vcm_OPTIONS_RELEASE "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}','${CURRENT_INSTALLED_DIR}/debug','${CURRENT_INSTALLED_DIR}/share']" )
else ( )
list ( APPEND _vcm_OPTIONS_DEBUG "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}/debug','${CURRENT_INSTALLED_DIR}']" )
list ( APPEND _vcm_OPTIONS_RELEASE "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}','${CURRENT_INSTALLED_DIR}/debug']" )
endif ( )
2021-09-25 03:11:38 +08:00
if ( NOT _vcm_NO_PKG_CONFIG )
vcpkg_find_acquire_program ( PKGCONFIG )
get_filename_component ( PKGCONFIG_PATH ${ PKGCONFIG } DIRECTORY )
vcpkg_add_to_path ( "${PKGCONFIG_PATH}" )
set ( PKGCONFIG_SHARE_DIR "${CURRENT_INSTALLED_DIR}/share/pkgconfig/" )
endif ( )
2020-11-19 05:36:20 +08:00
set ( buildtypes )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
set ( BUILDNAME DEBUG )
list ( APPEND buildtypes ${ BUILDNAME } )
set ( PATH_SUFFIX_ ${ BUILDNAME } "debug/" )
set ( SUFFIX_ ${ BUILDNAME } "dbg" )
endif ( )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release" )
set ( BUILDNAME RELEASE )
list ( APPEND buildtypes ${ BUILDNAME } )
set ( PATH_SUFFIX_ ${ BUILDNAME } "" )
set ( SUFFIX_ ${ BUILDNAME } "rel" )
endif ( )
if ( VCPKG_TARGET_IS_OSX )
if ( DEFINED ENV{SDKROOT} )
set ( _VCPKG_ENV_SDKROOT_BACKUP $ENV{ SDKROOT } )
2020-04-07 05:43:16 +08:00
endif ( )
2020-11-19 05:36:20 +08:00
set ( ENV{SDKROOT} "${VCPKG_DETECTED_CMAKE_OSX_SYSROOT}" )
set ( VCPKG_DETECTED_CMAKE_OSX_SYSROOT "${VCPKG_DETECTED_CMAKE_OSX_SYSROOT}" PARENT_SCOPE )
if ( DEFINED ENV{MACOSX_DEPLOYMENT_TARGET} )
set ( _VCPKG_ENV_MACOSX_DEPLOYMENT_TARGET_BACKUP $ENV{ MACOSX_DEPLOYMENT_TARGET } )
2020-04-07 05:43:16 +08:00
endif ( )
2020-11-19 05:36:20 +08:00
set ( ENV{MACOSX_DEPLOYMENT_TARGET} "${VCPKG_DETECTED_CMAKE_OSX_DEPLOYMENT_TARGET}" )
set ( VCPKG_DETECTED_CMAKE_OSX_DEPLOYMENT_TARGET "${VCPKG_DETECTED_CMAKE_OSX_DEPLOYMENT_TARGET}" PARENT_SCOPE )
2020-04-07 05:43:16 +08:00
endif ( )
2020-11-19 05:36:20 +08:00
if ( DEFINED ENV{INCLUDE} )
set ( ENV{INCLUDE} "$ENV{INCLUDE}${VCPKG_HOST_PATH_SEPARATOR}${CURRENT_INSTALLED_DIR}/include" )
else ( )
set ( ENV{INCLUDE} "${CURRENT_INSTALLED_DIR}/include" )
endif ( )
# configure build
foreach ( buildtype IN LISTS buildtypes )
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-09-25 03:11:38 +08:00
if ( NOT _vcm_NO_PKG_CONFIG )
set ( ENV{PKG_CONFIG} "${PKGCONFIG}" ) # Set via native file?
set ( PKGCONFIG_INSTALLED_DIR "${CURRENT_INSTALLED_DIR}/${PATH_SUFFIX_${buildtype}}lib/pkgconfig/" )
if ( DEFINED ENV{PKG_CONFIG_PATH} )
set ( BACKUP_ENV_PKG_CONFIG_PATH_RELEASE $ENV{ PKG_CONFIG_PATH } )
set ( ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}${VCPKG_HOST_PATH_SEPARATOR}${PKGCONFIG_SHARE_DIR}${VCPKG_HOST_PATH_SEPARATOR}$ENV{PKG_CONFIG_PATH}" )
else ( )
set ( ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}${VCPKG_HOST_PATH_SEPARATOR}${PKGCONFIG_SHARE_DIR}" )
endif ( )
2020-04-07 05:43:16 +08:00
endif ( )
2017-11-26 07:25:18 +08:00
vcpkg_execute_required_process (
2020-11-19 05:36:20 +08:00
C O M M A N D $ { M E S O N } $ { _ v c m _ O P T I O N S } $ { _ v c m _ O P T I O N S _ $ { b u i l d t y p e } } $ { _ v c m _ 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 } }
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
2020-11-19 05:36:20 +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}" )
file ( RENAME "${CURRENT_BUILDTREES_DIR}/meson-log.txt" "${CURRENT_BUILDTREES_DIR}/meson-log-${SUFFIX_${buildtype}}.txt" )
2020-04-07 05:43:16 +08:00
endif ( )
2020-11-19 05:36:20 +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}" )
file ( RENAME "${CURRENT_BUILDTREES_DIR}/install-log.txt" "${CURRENT_BUILDTREES_DIR}/install-log-${SUFFIX_${buildtype}}.txt" )
2020-04-07 05:43:16 +08:00
endif ( )
2020-11-19 05:36:20 +08:00
message ( STATUS "Configuring ${TARGET_TRIPLET}-${SUFFIX_${buildtype}} done" )
2021-09-25 03:11:38 +08:00
if ( NOT _vcm_NO_PKG_CONFIG )
#Restore PKG_CONFIG_PATH
if ( BACKUP_ENV_PKG_CONFIG_PATH_ ${ buildtype } )
set ( ENV{PKG_CONFIG_PATH} "${BACKUP_ENV_PKG_CONFIG_PATH_${buildtype}}" )
unset ( BACKUP_ENV_PKG_CONFIG_PATH_ ${ buildtype } )
else ( )
unset ( ENV{PKG_CONFIG_PATH} )
endif ( )
2020-04-07 05:43:16 +08:00
endif ( )
2020-11-19 05:36:20 +08:00
endforeach ( )
2017-02-10 01:13:52 +08:00
2020-11-19 05:36:20 +08:00
if ( VCPKG_TARGET_IS_OSX )
if ( DEFINED _VCPKG_ENV_SDKROOT_BACKUP )
set ( ENV{SDKROOT} "${_VCPKG_ENV_SDKROOT_BACKUP}" )
else ( )
unset ( ENV{SDKROOT} )
endif ( )
if ( DEFINED _VCPKG_ENV_MACOSX_DEPLOYMENT_TARGET_BACKUP )
set ( ENV{MACOSX_DEPLOYMENT_TARGET} "${_VCPKG_ENV_MACOSX_DEPLOYMENT_TARGET_BACKUP}" )
else ( )
unset ( ENV{MACOSX_DEPLOYMENT_TARGET} )
endif ( )
endif ( )
2017-02-10 01:13:52 +08:00
endfunction ( )