Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 5 additions & 1 deletion docs/maintainers/vcpkg_install_meson.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ Builds a meson project previously configured with `vcpkg_configure_meson()`.

## Usage
```cmake
vcpkg_install_meson()
vcpkg_install_meson([ADD_BIN_TO_PATH])
```

## Parameters:
### ADD_BIN_TO_PATH
Adds the appropriate Release and Debug `bin\` directories to the path during the build such that executables can run against the in-tree DLLs.

## Examples

* [fribidi](https://github.com/Microsoft/vcpkg/blob/master/ports/fribidi/portfile.cmake)
Expand Down
19 changes: 19 additions & 0 deletions scripts/buildsystems/meson/none.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# native file used to make the build machine compiler unusable
Comment thread
Neumann-A marked this conversation as resolved.

[host_machine]
system = 'none'
cpu_family = 'none'
cpu = 'none'
endian = 'little'

[properties]

[binaries]
c = ['false']
cpp = ['false']
objc = ['false']
objcpp = ['false']
ar = ['false']
pkgconfig = ['false']
cmake = ['false']
ninja = ['false']
48 changes: 26 additions & 22 deletions scripts/cmake/vcpkg_configure_meson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This command supplies many common arguments to Meson. To see the full list, exam
* [libepoxy](https://github.com/Microsoft/vcpkg/blob/master/ports/libepoxy/portfile.cmake)
#]===]


Comment thread
Neumann-A marked this conversation as resolved.
Outdated
function(vcpkg_internal_meson_generate_native_file _additional_binaries) #https://mesonbuild.com/Native-environments.html
set(NATIVE "[binaries]\n")
#set(proglist AR RANLIB STRIP NM OBJDUMP DLLTOOL MT)
Expand Down Expand Up @@ -101,15 +102,15 @@ function(vcpkg_internal_meson_generate_native_file_config _config) #https://meso
set(LIBPATH_${_config} "'${L_FLAG}${CURRENT_INSTALLED_DIR}${PATH_SUFFIX_${_config}}/lib'")

set(NATIVE_${_config} "[properties]\n") #https://mesonbuild.com/Builtin-options.html
string(REGEX REPLACE "( |^)(-|/)" ";\\2" MESON_CFLAGS_${_config} "${VCPKG_DETECTED_CMAKE_C_FLAGS_${_config}}")
string(REGEX REPLACE "( |^)(--?|/)" ";\\2" MESON_CFLAGS_${_config} "${VCPKG_DETECTED_CMAKE_C_FLAGS_${_config}}")
Comment thread
Neumann-A marked this conversation as resolved.
Outdated
list(TRANSFORM MESON_CFLAGS_${_config} APPEND "'")
list(TRANSFORM MESON_CFLAGS_${_config} PREPEND "'")
#list(APPEND MESON_CFLAGS_${_config} "${LIBPATH_${_config}}")
list(APPEND MESON_CFLAGS_${_config} "'-I${CURRENT_INSTALLED_DIR}/include'")
list(JOIN MESON_CFLAGS_${_config} ", " MESON_CFLAGS_${_config})
string(REPLACE "'', " "" MESON_CFLAGS_${_config} "${MESON_CFLAGS_${_config}}")
string(APPEND NATIVE_${_config} "c_args = [${MESON_CFLAGS_${_config}}]\n")
string(REGEX REPLACE "( |^)(-|/)" ";\\2" MESON_CXXFLAGS_${_config} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_${_config}}")
string(REGEX REPLACE "( |^)(--?|/)" ";\\2" MESON_CXXFLAGS_${_config} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_${_config}}")
Comment thread
Neumann-A marked this conversation as resolved.
Outdated
list(TRANSFORM MESON_CXXFLAGS_${_config} APPEND "'")
list(TRANSFORM MESON_CXXFLAGS_${_config} PREPEND "'")
#list(APPEND MESON_CXXFLAGS_${_config} "${LIBPATH_${_config}}")
Expand All @@ -123,7 +124,7 @@ function(vcpkg_internal_meson_generate_native_file_config _config) #https://meso
else()
set(LINKER_FLAGS_${_config} "${VCPKG_DETECTED_CMAKE_STATIC_LINKER_FLAGS_${_config}}")
endif()
string(REGEX REPLACE "( |^)(-|/)" ";\\2" LINKER_FLAGS_${_config} "${LINKER_FLAGS_${_config}}")
string(REGEX REPLACE "( +|^)(--?|/)" ";\\2" LINKER_FLAGS_${_config} "${LINKER_FLAGS_${_config}}")
list(TRANSFORM LINKER_FLAGS_${_config} APPEND "'")
list(TRANSFORM LINKER_FLAGS_${_config} PREPEND "'")
list(APPEND LINKER_FLAGS_${_config} "${LIBPATH_${_config}}")
Expand Down Expand Up @@ -249,7 +250,7 @@ function(vcpkg_internal_meson_generate_cross_file _additional_binaries) #https:/
endforeach()

string(APPEND CROSS "[properties]\n")
string(APPEND CROSS "skip_sanity_check = true\n")

string(APPEND CROSS "[host_machine]\n")
string(APPEND CROSS "endian = 'little'\n")
if(NOT VCPKG_CMAKE_SYSTEM_NAME)
Expand All @@ -273,7 +274,7 @@ function(vcpkg_internal_meson_generate_cross_file _additional_binaries) #https:/
string(APPEND CROSS "cpu_family = '${BUILD_CPU_FAM}'\n")
string(APPEND CROSS "cpu = '${BUILD_CPU}'\n")

if(NOT BUILD_CPU_FAM STREQUAL HOST_CPU_FAM)
if(NOT BUILD_CPU_FAM MATCHES "${HOST_CPU_FAM}" OR VCPKG_TARGET_IS_UWP)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this MATCHES over STREQUAL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So that x64_x86 MATCHES x86 and becomes a native build. Same for arm64 MATCHES arm.
UWP on the other hand should always be a crossbuild.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will likely need a follow-up PR to handle the more generic BUILD_OS != HOST_OS (such as windows cross to linux or vice versa).

What are the consequences of making everything a cross build?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What are the consequences of making everything a cross build?

That probably strongly depends on whatever is in the meson.build. But I would assume that cross builds will, in general, not try to build host/native tools/codegenerator which is a problem if you start to depend on them being available within vcpkg. If everything is a cross build and the buildscript just tests for 'cross' for building the required tool than additional patches are necessary to introduce the required options/fixes to make the port actually build the tools if it is native build. Furthermore there might be more introspection into the system if it is a native build.

But I agree everything should eventually be treated as a crossbuild. A native build is just a special case of a cross build, where the build machines happens to be the same as the target machine. Unfortunately most developers don't thing in that way and treat the cross build as the special case.

set(_file "${CURRENT_BUILDTREES_DIR}/meson-cross-${TARGET_TRIPLET}.log")
set(VCPKG_MESON_CROSS_FILE "${_file}" PARENT_SCOPE)
file(WRITE "${_file}" "${CROSS}")
Expand All @@ -291,14 +292,14 @@ function(vcpkg_internal_meson_generate_cross_file_config _config) #https://meson


set(NATIVE_${_config} "[properties]\n") #https://mesonbuild.com/Builtin-options.html
string(REGEX REPLACE "( |^)(-|/)" ";\\2" MESON_CFLAGS_${_config} "${VCPKG_DETECTED_CMAKE_C_FLAGS_${_config}}")
string(REGEX REPLACE "( |^)(--?|/)" ";\\2" MESON_CFLAGS_${_config} "${VCPKG_DETECTED_CMAKE_C_FLAGS_${_config}}")
Comment thread
Neumann-A marked this conversation as resolved.
Outdated
list(TRANSFORM MESON_CFLAGS_${_config} APPEND "'")
list(TRANSFORM MESON_CFLAGS_${_config} PREPEND "'")
list(APPEND MESON_CFLAGS_${_config} "'-I\"${CURRENT_INSTALLED_DIR}/include\"'")
list(JOIN MESON_CFLAGS_${_config} ", " MESON_CFLAGS_${_config})
string(REPLACE "'', " "" MESON_CFLAGS_${_config} "${MESON_CFLAGS_${_config}}")
string(APPEND NATIVE_${_config} "c_args = [${MESON_CFLAGS_${_config}}]\n")
string(REGEX REPLACE "( |^)(-|/)" ";\\2" MESON_CXXFLAGS_${_config} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_${_config}}")
string(REGEX REPLACE "( |^)(--?|/)" ";\\2" MESON_CXXFLAGS_${_config} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_${_config}}")
Comment thread
Neumann-A marked this conversation as resolved.
Outdated
list(TRANSFORM MESON_CXXFLAGS_${_config} APPEND "'")
list(TRANSFORM MESON_CXXFLAGS_${_config} PREPEND "'")
list(APPEND MESON_CXXFLAGS_${_config} "'-I\"${CURRENT_INSTALLED_DIR}/include\"'")
Expand All @@ -311,7 +312,7 @@ function(vcpkg_internal_meson_generate_cross_file_config _config) #https://meson
else()
set(LINKER_FLAGS_${_config} "${VCPKG_DETECTED_CMAKE_STATIC_LINKER_FLAGS_${_config}}")
endif()
string(REGEX REPLACE "( |^)(-|/)" ";\\2" LINKER_FLAGS_${_config} "${LINKER_FLAGS_${_config}}")
string(REGEX REPLACE "( +|^)(--?|/)" ";\\2" LINKER_FLAGS_${_config} "${LINKER_FLAGS_${_config}}")
list(TRANSFORM LINKER_FLAGS_${_config} APPEND "'")
list(TRANSFORM LINKER_FLAGS_${_config} PREPEND "'")
list(APPEND LINKER_FLAGS_${_config} "${LIBPATH_${_config}}")
Expand Down Expand Up @@ -370,19 +371,6 @@ function(vcpkg_configure_meson)

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

if(NOT VCPKG_MESON_NATIVE_FILE)
vcpkg_internal_meson_generate_native_file("_vcm_ADDITIONAL_NATIVE_BINARIES")
endif()
if(NOT VCPKG_MESON_NATIVE_FILE_DEBUG)
vcpkg_internal_meson_generate_native_file_config(DEBUG)
endif()
if(NOT VCPKG_MESON_NATIVE_FILE_RELEASE)
vcpkg_internal_meson_generate_native_file_config(RELEASE)
endif()
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}")

if(NOT VCPKG_MESON_CROSS_FILE)
vcpkg_internal_meson_generate_cross_file("_vcm_ADDITIONAL_CROSS_BINARIES")
endif()
Expand All @@ -395,14 +383,30 @@ function(vcpkg_configure_meson)
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()


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)
Comment thread
Neumann-A marked this conversation as resolved.
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()
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
list(APPEND _vcm_OPTIONS --default-library shared)
else()
Expand Down
48 changes: 35 additions & 13 deletions scripts/cmake/vcpkg_install_meson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ Builds a meson project previously configured with `vcpkg_configure_meson()`.

## Usage
```cmake
vcpkg_install_meson()
vcpkg_install_meson([ADD_BIN_TO_PATH])
```

## Parameters:
### ADD_BIN_TO_PATH
Adds the appropriate Release and Debug `bin\` directories to the path during the build such that executables can run against the in-tree DLLs.

## Examples

* [fribidi](https://github.com/Microsoft/vcpkg/blob/master/ports/fribidi/portfile.cmake)
Expand All @@ -17,6 +21,7 @@ vcpkg_install_meson()
function(vcpkg_install_meson)
vcpkg_find_acquire_program(NINJA)
unset(ENV{DESTDIR}) # installation directory was already specified with '--prefix' option
cmake_parse_arguments(PARSE_ARGV 0 _im "ADD_BIN_TO_PATH" "" "")

if(VCPKG_TARGET_IS_OSX)
if(DEFINED ENV{SDKROOT})
Expand All @@ -30,19 +35,35 @@ function(vcpkg_install_meson)
set(ENV{MACOSX_DEPLOYMENT_TARGET} "${VCPKG_DETECTED_CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()

message(STATUS "Package ${TARGET_TRIPLET}-rel")
vcpkg_execute_required_process(
COMMAND ${NINJA} install -v
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
LOGNAME package-${TARGET_TRIPLET}-rel
)
foreach(BUILDTYPE "debug" "release")
if(DEFINED VCPKG_BUILD_TYPE AND NOT VCPKG_BUILD_TYPE STREQUAL BUILDTYPE)
continue()
endif()

if(BUILDTYPE STREQUAL "debug")
set(SHORT_BUILDTYPE "dbg")
else()
set(SHORT_BUILDTYPE "rel")
endif()

message(STATUS "Package ${TARGET_TRIPLET}-dbg")
vcpkg_execute_required_process(
COMMAND ${NINJA} install -v
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg
LOGNAME package-${TARGET_TRIPLET}-dbg
)
message(STATUS "Package ${TARGET_TRIPLET}-${SHORT_BUILDTYPE}")
if(_im_ADD_BIN_TO_PATH)
set(_BACKUP_ENV_PATH "$ENV{PATH}")
if(BUILDTYPE STREQUAL "debug")
vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}/debug/bin")
else()
vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}/bin")
endif()
endif()
vcpkg_execute_required_process(
COMMAND ${NINJA} install -v
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${SHORT_BUILDTYPE}
LOGNAME package-${TARGET_TRIPLET}-${SHORT_BUILDTYPE}
)
if(_im_ADD_BIN_TO_PATH)
set(ENV{PATH} "${_BACKUP_ENV_PATH}")
endif()
endforeach()

set(RENAMED_LIBS)
if(VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL static)
Expand Down Expand Up @@ -81,4 +102,5 @@ function(vcpkg_install_meson)
unset(ENV{MACOSX_DEPLOYMENT_TARGET})
endif()
endif()

Comment thread
Neumann-A marked this conversation as resolved.
Outdated
endfunction()