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
[MesonToolchain] Added Objective-C/C++ arguments #11632
Merged
memsharded
merged 2 commits into
conan-io:develop
from
franramirez688:feature/meson_objc
Jul 14, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
conans/test/functional/toolchains/meson/test_meson_and_objc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import os | ||
import platform | ||
import sys | ||
import textwrap | ||
|
||
import pytest | ||
|
||
from conans.client.tools.apple import XCRun, to_apple_arch | ||
from conans.test.utils.tools import TestClient | ||
|
||
_conanfile_py = textwrap.dedent(""" | ||
from conan import ConanFile | ||
from conan.tools.meson import Meson, MesonToolchain | ||
|
||
|
||
class App(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
|
||
def layout(self): | ||
self.folders.build = "build" | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def generate(self): | ||
tc = MesonToolchain(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
meson = Meson(self) | ||
meson.configure() | ||
meson.build() | ||
""") | ||
|
||
_meson_build_objc = textwrap.dedent(""" | ||
project('tutorial', 'objc') | ||
executable('demo', 'main.m', link_args: ['-framework', 'Foundation']) | ||
""") | ||
|
||
|
||
@pytest.mark.tool_meson | ||
@pytest.mark.skipif(sys.version_info.major == 2, reason="Meson not supported in Py2") | ||
@pytest.mark.skipif(platform.system() != "Darwin", reason="requires Xcode") | ||
def test_apple_meson_toolchain_native_compilation_objective_c(): | ||
profile = textwrap.dedent(""" | ||
[settings] | ||
os = Macos | ||
arch = x86_64 | ||
compiler = apple-clang | ||
compiler.version = 12.0 | ||
compiler.libcxx = libc++ | ||
""") | ||
app = textwrap.dedent(""" | ||
#import <Foundation/Foundation.h> | ||
|
||
int main(int argc, const char * argv[]) { | ||
@autoreleasepool { | ||
// insert code here... | ||
NSLog(@"Hello, World!"); | ||
} | ||
return 0; | ||
} | ||
""") | ||
t = TestClient() | ||
t.save({"conanfile.py": _conanfile_py, | ||
"meson.build": _meson_build_objc, | ||
"main.m": app, | ||
"macos_pr": profile}) | ||
|
||
t.run("install . -pr macos_pr") | ||
t.run("build .") | ||
t.run_command("./demo", cwd=os.path.join(t.current_folder, "build")) | ||
assert "Hello, World!" in t.out | ||
|
||
|
||
@pytest.mark.parametrize("arch, os_, os_version, sdk", [ | ||
('armv8', 'iOS', '10.0', 'iphoneos'), | ||
('armv7', 'iOS', '10.0', 'iphoneos'), | ||
('x86', 'iOS', '10.0', 'iphonesimulator'), | ||
('x86_64', 'iOS', '10.0', 'iphonesimulator'), | ||
('armv8', 'Macos', None, None) # MacOS M1 | ||
]) | ||
@pytest.mark.tool_meson | ||
@pytest.mark.skipif(sys.version_info.major == 2, reason="Meson not supported in Py2") | ||
@pytest.mark.skipif(platform.system() != "Darwin", reason="requires Xcode") | ||
def test_apple_meson_toolchain_cross_compiling_and_objective_c(arch, os_, os_version, sdk): | ||
profile = textwrap.dedent(""" | ||
include(default) | ||
|
||
[settings] | ||
os = {os} | ||
os.version = {os_version} | ||
os.sdk = {os_sdk} | ||
arch = {arch} | ||
compiler = apple-clang | ||
compiler.version = 12.0 | ||
compiler.libcxx = libc++ | ||
|
||
[conf] | ||
tools.apple:sdk_path={sdk_path} | ||
""") | ||
|
||
xcrun = XCRun(None, sdk) | ||
sdk_path = xcrun.sdk_path | ||
app = textwrap.dedent(""" | ||
#import <Foundation/Foundation.h> | ||
|
||
int main(int argc, const char * argv[]) { | ||
@autoreleasepool { | ||
// insert code here... | ||
NSLog(@"Hello, World!"); | ||
} | ||
return 0; | ||
} | ||
""") | ||
profile = profile.format( | ||
os=os_, | ||
os_version=os_version, | ||
os_sdk=sdk, | ||
arch=arch, | ||
sdk_path=sdk_path) | ||
|
||
t = TestClient() | ||
t.save({"conanfile.py": _conanfile_py, | ||
"meson.build": _meson_build_objc, | ||
"main.m": app, | ||
"profile_host": profile}) | ||
|
||
t.run("install . --profile:build=default --profile:host=profile_host") | ||
t.run("build .") | ||
assert "Objective-C compiler for the host machine: clang" in t.out | ||
|
||
demo = os.path.join(t.current_folder, "build", "demo") | ||
assert os.path.isfile(demo) is True | ||
franramirez688 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
lipo = xcrun.find('lipo') | ||
t.run_command('"%s" -info "%s"' % (lipo, demo)) | ||
assert "architecture: %s" % to_apple_arch(arch) in t.out |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I still feel this is problematic, having 2 mechanisms to define CXX_FLAGS (env and conf). Not related to this PR, I know it is already this way for C/C++ flags, but something we want to clarify for the future.
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.
I absolutely agree. I can open a "look-into" feature to have this into account for future releases.