-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[glib] Support cross-compiling Objective C code using Meson #33313
Conversation
/cc @Naville @ekilmer @dchengTSC @mike-malburg as you've been involved in similar conversations. |
1e9e54f
to
1b23d21
Compare
enable_language(C) | ||
enable_language(CXX) | ||
if(APPLE) | ||
enable_language(OBJC) | ||
enable_language(OBJCXX) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ras0219-msft: I think this needs to be configurable somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Neumann-A If we don't want enable ObjC on macOS by default, would a better alternative be to add support for ObjC to the port files that need it? E.g. in this case I just add it to ports/glib/portfile.cmake
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably yes. Other ports do that on a port level basis with ASM
and Fortran
if(APPLE) | ||
list(APPEND VCPKG_LANGUAGES "OBJC") | ||
list(APPEND VCPKG_LANGUAGES "OBJCXX") | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This always enable OBJC and OBJCXX on macosx running unnecessary compiler checks. You can use list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DVCPKG_LANGUAGES=C;CXX;OBJC;OBJCXX")
from the portfile or in vcpkg_configure_meson
to enable additional languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DVCPKG_LANGUAGES=C;CXX;OBJC;OBJCXX")
in the port file didn't seem to work; as cmake_get_vars
seems to always initialise that to C;CXX
Setting an -DVCPKG_ENABLE_OBJC
variable and having cmake_get_vars
append OBJC to that list did do the trick, though.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
1b23d21
to
4d804f3
Compare
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 microsoft#26147 Fixes microsoft#20341 Based on microsoft#26259 Based on TechSmith@27dee35 Tested on an arm64 mac to compile glib for x64 macos
4d804f3
to
5e08e12
Compare
@Neumann-A Thank you for your feedback! I was able to simplify the PR a bit, and confirmed it works on my M2 Mac when cross-compiling for x64 Mac (something which fails without this patch) |
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 theMESON_OBJC
CMake variable to be set.That's the job of
z_vcpkg_meson_set_proglist_variables
inscripts/cmake/vcpkg_configure_meson.cmake
. It will only generate data for an Objective C compiler if:Languages
argument includesOBJC
VCPKG_DETECTED_CMAKE_OBJC_COMPILER
To make this work, this patch:
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