Skip to content

Commit

Permalink
[glib] Support cross-compiling Objective C code using Meson (#33313)
Browse files Browse the repository at this point in the history
* Support cross-compiling Objective C code using Meson

The glib port uses Objective C code and the Meson build system.
You'll end up cross compiling glib when compiling for x64 osx
on an arm64 osx machine, or vice versa.

For this to work, an Objective C compiler needs to be set
in the Meson cross file.

vcpkg generates this file based on the
`scripts/buildsystems/meson/meson.template.in` template, and expects
the `MESON_OBJC` CMake variable to be set.

That's the job of `z_vcpkg_meson_set_proglist_variables` in
`scripts/cmake/vcpkg_configure_meson.cmake`.  It will only generate data
for an Objective C compiler if:

- The `Languages` argument includes `OBJC`
- CMake has detected a Objective C compiler, and has set `VCPKG_DETECTED_CMAKE_OBJC_COMPILER`

To make this work, this patch:
- Enables the OBJC and OBJCXX language on Apple platforms
- Updates the call to `vcpkg_configure_meson` in the glib port file
  to include the OBJC OBJCXX languages.

Fixes #26147
Fixes #20341
Based on #26259
Based on TechSmith@27dee35

Tested on an arm64 mac to compile glib for x64 macos

* Update version database
  • Loading branch information
qmfrederik committed Aug 25, 2023
1 parent c747905 commit ba58a3f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ports/glib/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ vcpkg_extract_source_archive(SOURCE_PATH
fix-build-race-on-gio.patch # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3512
)

if(APPLE)
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DVCPKG_ENABLE_OBJC=1")
endif()

vcpkg_list(SET OPTIONS)
if (selinux IN_LIST FEATURES)
if(NOT EXISTS "/usr/include/selinux")
Expand All @@ -38,6 +42,7 @@ endif()

vcpkg_configure_meson(
SOURCE_PATH "${SOURCE_PATH}"
LANGUAGES C CXX OBJC OBJCXX
ADDITIONAL_BINARIES
${ADDITIONAL_BINARIES}
OPTIONS
Expand Down
2 changes: 1 addition & 1 deletion ports/glib/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "glib",
"version": "2.76.3",
"port-version": 2,
"port-version": 3,
"description": "Portable, general-purpose utility library.",
"homepage": "https://developer.gnome.org/glib/",
"license": "LGPL-2.1-or-later",
Expand Down
3 changes: 3 additions & 0 deletions scripts/get_cmake_vars/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ else()
endif()

set(VCPKG_LANGUAGES "C;CXX" CACHE STRING "Languages to enables for this project")
if(VCPKG_ENABLE_OBJC)
list(APPEND VCPKG_LANGUAGES "OBJC")
endif()

project(get_cmake_vars LANGUAGES ${VCPKG_LANGUAGES})

Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -2910,7 +2910,7 @@
},
"glib": {
"baseline": "2.76.3",
"port-version": 2
"port-version": 3
},
"glibmm": {
"baseline": "2.76.0",
Expand Down
5 changes: 5 additions & 0 deletions versions/g-/glib.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "ac7af1a224e7dfe9c18e629bf8de7798a0cda932",
"version": "2.76.3",
"port-version": 3
},
{
"git-tree": "c4aa04cd3294219ddd4b43c2f02b95c100683156",
"version": "2.76.3",
Expand Down

0 comments on commit ba58a3f

Please sign in to comment.