Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 33 additions & 36 deletions scripts/cmake/vcpkg_configure_meson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function(vcpkg_configure_meson)
endif()

include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")

string(APPEND MESON_COMMON_CFLAGS " ${CMAKE_C_FLAGS${MESON_CMAKE_FLAG_SUFFIX}}")
string(APPEND MESON_COMMON_CXXFLAGS " ${CMAKE_CXX_FLAGS${MESON_CMAKE_FLAG_SUFFIX}}")

Expand All @@ -72,35 +72,42 @@ function(vcpkg_configure_meson)
string(APPEND MESON_COMMON_LDFLAGS " ${CMAKE_SHARED_LINKER_FLAGS${MESON_CMAKE_FLAG_SUFFIX}}")
string(APPEND MESON_DEBUG_LDFLAGS " ${CMAKE_SHARED_LINKER_FLAGS_DEBUG${MESON_CMAKE_FLAG_SUFFIX}}")
string(APPEND MESON_RELEASE_LDFLAGS " ${CMAKE_SHARED_LINKER_FLAGS_RELEASE${MESON_CMAKE_FLAG_SUFFIX}}")

# select meson cmd-line options
if(VCPKG_TARGET_IS_WINDOWS)
list(APPEND _vcm_OPTIONS "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}','${CURRENT_INSTALLED_DIR}/share']")
else()
list(APPEND _vcm_OPTIONS "-Dcmake_prefix_path=['${CURRENT_INSTALLED_DIR}']")
endif()

list(APPEND _vcm_OPTIONS --buildtype plain --backend ninja --wrap-mode nodownload)


if(VCPKG_MESON_CROSS_FILE)
list(APPEND _vcm_OPTIONS --cross "${VCPKG_MESON_CROSS_FILE}")
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
list(APPEND _vcm_OPTIONS --default-library shared)
else()
list(APPEND _vcm_OPTIONS --default-library static)
endif()

list(APPEND _vcm_OPTIONS --libdir lib) # else meson install into an architecture describing folder
list(APPEND _vcm_OPTIONS_DEBUG --prefix ${CURRENT_PACKAGES_DIR}/debug --includedir ../include)
list(APPEND _vcm_OPTIONS_RELEASE --prefix ${CURRENT_PACKAGES_DIR})

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()

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("${NINJA_PATH}")

if(NOT ENV{PKG_CONFIG})
if(NOT DEFINED ENV{PKG_CONFIG})
find_program(PKGCONFIG pkg-config)
if(NOT PKGCONFIG AND CMAKE_HOST_WIN32)
vcpkg_acquire_msys(MSYS_ROOT PACKAGES pkg-config)
Expand All @@ -116,27 +123,22 @@ function(vcpkg_configure_meson)
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" PKGCONFIG_SHARE_DIR "${PKGCONFIG_SHARE_DIR}")
endif()
# configure debug
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
message(STATUS "Configuring ${TARGET_TRIPLET}-dbg")
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)

#setting up PKGCONFIG
if(NOT PKGCONFIG MATCHES "--define-variable=prefix")
set(PKGCONFIG_PREFIX "${CURRENT_INSTALLED_DIR}/debug")
# if(WIN32)
# string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" PKGCONFIG_PREFIX "${PKGCONFIG_PREFIX}")
# endif()
set(ENV{PKG_CONFIG} "${PKGCONFIG} --define-variable=prefix=${PKGCONFIG_PREFIX}")
endif()
set(ENV{PKG_CONFIG} "${PKGCONFIG}")

set(PKGCONFIG_INSTALLED_DIR "${CURRENT_INSTALLED_DIR}/debug/lib/pkgconfig/")
if(WIN32)
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" PKGCONFIG_INSTALLED_DIR "${PKGCONFIG_INSTALLED_DIR}")
endif()
if(ENV{PKG_CONFIG_PATH})
if(DEFINED ENV{PKG_CONFIG_PATH})
set(BACKUP_ENV_PKG_CONFIG_PATH_DEBUG $ENV{PKG_CONFIG_PATH})
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}: ${PKGCONFIG_SHARE_DIR}: $ENV{PKG_CONFIG_PATH}")
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}:${PKGCONFIG_SHARE_DIR}:$ENV{PKG_CONFIG_PATH}")
else()
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}: ${PKGCONFIG_SHARE_DIR}")
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}:${PKGCONFIG_SHARE_DIR}")
endif()

set(CFLAGS "-Dc_args=[${MESON_COMMON_CFLAGS} ${MESON_DEBUG_CFLAGS}]")
Expand Down Expand Up @@ -187,24 +189,19 @@ function(vcpkg_configure_meson)
# configure release
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
message(STATUS "Configuring ${TARGET_TRIPLET}-rel")
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
#setting up PKGCONFIG
if(NOT PKGCONFIG MATCHES "--define-variable=prefix")
set(PKGCONFIG_PREFIX "${CURRENT_INSTALLED_DIR}")
# if(WIN32)
# string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" PKGCONFIG_PREFIX "${PKGCONFIG_PREFIX}")
# endif()
set(ENV{PKG_CONFIG} "${PKGCONFIG} --define-variable=prefix=${PKGCONFIG_PREFIX}")
endif()
set(ENV{PKG_CONFIG} "${PKGCONFIG}")

set(PKGCONFIG_INSTALLED_DIR "${CURRENT_INSTALLED_DIR}/lib/pkgconfig/")
if(WIN32)
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" PKGCONFIG_INSTALLED_DIR "${PKGCONFIG_INSTALLED_DIR}")
endif()
if(ENV{PKG_CONFIG_PATH})
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}: ${PKGCONFIG_SHARE_DIR}: $ENV{PKG_CONFIG_PATH}")
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}:${PKGCONFIG_SHARE_DIR}:$ENV{PKG_CONFIG_PATH}")
else()
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}: ${PKGCONFIG_SHARE_DIR}")
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}:${PKGCONFIG_SHARE_DIR}")
endif()

# Normalize flags for meson (i.e. " /string /with /flags " -> ['/string', '/with', '/flags'])
Expand Down
11 changes: 6 additions & 5 deletions scripts/cmake/vcpkg_find_acquire_program.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@ function(vcpkg_find_acquire_program VAR)
if(CMAKE_HOST_WIN32)
set(SCRIPTNAME meson.py)
else()
set(SCRIPTNAME meson)
set(SCRIPTNAME meson.py meson)
endif()
set(PATHS ${DOWNLOADS}/tools/meson/meson-0.54.2)
set(_vfa_SUPPORTED ON) # Just download meson from github. It is very likely that the system package manager has only an outdated version
set(URL "https://github.com/mesonbuild/meson/archive/0.54.2.zip")
set(ARCHIVE "meson-0.54.2.zip")
set(HASH 8d19110bad3e6a223d1d169e833b746b884ece9cd23d2539ec02dccb5cd0c56542414b7afc0f7f2adcec9d957e4120d31f41734397aa0a7ee7f9c29ebdc9eb4c)
Expand Down Expand Up @@ -345,12 +346,12 @@ function(vcpkg_find_acquire_program VAR)

macro(do_find)
if(NOT DEFINED REQUIRED_INTERPRETER)
find_program(${VAR} ${PROGNAME} PATHS ${PATHS} NO_DEFAULT_PATH)
find_program(${VAR} ${PROGNAME})
find_program(${VAR} NAMES ${PROGNAME} PATHS ${PATHS} NO_DEFAULT_PATH)
find_program(${VAR} NAMES ${PROGNAME})
else()
vcpkg_find_acquire_program(${REQUIRED_INTERPRETER})
find_file(SCRIPT_${VAR} ${SCRIPTNAME} PATHS ${PATHS} NO_DEFAULT_PATH)
find_file(SCRIPT_${VAR} ${SCRIPTNAME})
find_file(SCRIPT_${VAR} NAMES ${SCRIPTNAME} PATHS ${PATHS} NO_DEFAULT_PATH)
find_file(SCRIPT_${VAR} NAMES ${SCRIPTNAME})
set(${VAR} ${${REQUIRED_INTERPRETER}} ${SCRIPT_${VAR}})
endif()
endmacro()
Expand Down
21 changes: 21 additions & 0 deletions scripts/toolchains/meson.windows.arm64.crossfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[binaries]
Copy link
Contributor

@dan-shaw dan-shaw Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to autogenerate this file from the toolchain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably Yes. Needs to be done anyway since vcpkg_configure_make also requires that information to correctly set all build flags.

We need some kind of vcpkg_determine_compile_settings_from_cmake or similar to generate the required information for vcpkg_configure_make and vcpkg_configure_meson and maybe other not CMake related ports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also meson tries to do it the other way around e.g. have a meson crossfile and generate a cmake toolchain out of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should figure out how to autogenerate this file before merging this. Otherwise, we may have too many files to maintain.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ras0219-msft do you have some suggestions?

Copy link
Contributor

@ras0219-msft ras0219-msft Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice those two scripts should be generalized.
A lot of that stuff is actually also required for vcpkg_configure_make and vcpkg_configure_qmake apart form vcpkg_configure_meson

#exe_wrapper = 'None' # A command used to run generated executables.
cc = 'msvc'
c = 'cl'
cpp = 'cl'
ar = 'lib'
windres = 'rc'
cmake = 'cmake'
[properties]
#needs_exe_wrapper = true
skip_sanity_check = True
[host_machine]
system = 'windows'
cpu_family = 'aarch64'
cpu = 'armv8'
endian = 'little'
[build_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
3 changes: 1 addition & 2 deletions triplets/arm64-windows.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)


set(VCPKG_MESON_CROSS_FILE "${SCRIPTS}/toolchains/meson.windows.arm64.crossfile")