Skip to content

Commit

Permalink
Add support for depending on ObjFW
Browse files Browse the repository at this point in the history
This uses objfw-config to get to the flags, however, there's still
several todos that can only be addressed once dependencies can have
per-language flags.
  • Loading branch information
Midar committed Apr 23, 2024
1 parent de4de65 commit ed71e8b
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 5 deletions.
42 changes: 37 additions & 5 deletions docs/markdown/Dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,20 @@ DC="dmd" meson setup builddir

## Config tool

[CUPS](#cups), [LLVM](#llvm), [pcap](#pcap), [WxWidgets](#wxwidgets),
[libwmf](#libwmf), [GCrypt](#libgcrypt), [GPGME](#gpgme), and GnuStep either do not provide pkg-config
modules or additionally can be detected via a config tool
(cups-config, llvm-config, libgcrypt-config, etc). Meson has native support for these
tools, and they can be found like other dependencies:
[CUPS](#cups), [LLVM](#llvm), [ObjFW](#objfw), [pcap](#pcap),
[WxWidgets](#wxwidgets), [libwmf](#libwmf), [GCrypt](#libgcrypt),
[GPGME](#gpgme), and GnuStep either do not provide pkg-config modules or
additionally can be detected via a config tool (cups-config, llvm-config,
libgcrypt-config, etc). Meson has native support for these tools, and they can
be found like other dependencies:

```meson
pcap_dep = dependency('pcap', version : '>=1.0')
cups_dep = dependency('cups', version : '>=1.4')
llvm_dep = dependency('llvm', version : '>=4.0')
libgcrypt_dep = dependency('libgcrypt', version: '>= 1.8')
gpgme_dep = dependency('gpgme', version: '>= 1.0')
objfw_dep = dependency('objfw', version: '>= 1.0')
```

*Since 0.55.0* Meson won't search $PATH any more for a config tool
Expand Down Expand Up @@ -637,6 +639,36 @@ language-specific, you must specify the requested language using the

Meson uses pkg-config to find NetCDF.

## ObjFW

*(added 1.5.0)*

Meson has native support for ObjFW, including support for ObjFW packages.

In order to use ObjFW, simply create the dependency:

```meson
objfw_dep = dependency('objfw')
```

In order to also use ObjFW packages, simply specify them as modules:

```meson
objfw_dep = dependency('objfw', modules: ['SomePackage'])
```

If you need a dependency with and without packages, e.g. because your tests
want to use ObjFWTest, but you don't want to link your application against the
tests, simply get two dependencies and use them as appropriate:

```meson
objfw_dep = dependency('objfw', modules: ['SomePackage'])
objfwtest_dep = dependency('objfw', modules: ['ObjFWTest'])
```

Then use `objfw_dep` for your library and only `objfwtest_dep` (not both) for
your tests.

## OpenMP

*(added 0.46.0)*
Expand Down
24 changes: 24 additions & 0 deletions docs/markdown/snippets/objfw_dep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## A new dependency for ObjFW is now supported

For example, you can create a simple application written using ObjFW like this:

```meson
project('SimpleApp', 'objc')
objfw_dep = dependency('objfw', version: '>= 1.0')
executable('SimpleApp', 'SimpleApp.m',
dependencies: [objfw_dep])
```

Modules are also supported. A test case using ObjFWTest can be created like
this:

```meson
project('Tests', 'objc')
objfwtest_dep = dependency('objfw', version: '>= 1.1', modules: ['ObjFWTest'])
executable('Tests', ['FooTest.m', 'BarTest.m'],
dependencies: [objfwtest_dep])
```
1 change: 1 addition & 0 deletions mesonbuild/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
'openssl': 'misc',
'libcrypto': 'misc',
'libssl': 'misc',
'objfw': 'misc',

# From platform:
'appleframeworks': 'platform',
Expand Down
26 changes: 26 additions & 0 deletions mesonbuild/dependencies/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,30 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
self.link_args.extend(sublib)


class ObjFWDependency(ConfigToolDependency):

tools = ['objfw-config']
tool_name = 'objfw-config'

def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]):
super().__init__('objfw', environment, kwargs)
self.feature_since = ('1.5.0', '')
if not self.is_found:
return

# TODO: Expose --reexport
# TODO: Expose --framework-libs
extra_flags = []

for module in mesonlib.stringlistify(mesonlib.extract_as_list(kwargs, 'modules')):
extra_flags.append('--package')
extra_flags.append(module)

# TODO: Once Meson supports adding flags per language, only add --objcflags to ObjC
self.compile_args = self.get_config_value(['--cppflags', '--cflags', '--objcflags'] + extra_flags, 'compile_args')
self.link_args = self.get_config_value(['--ldflags', '--libs'] + extra_flags, 'link_args')


@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM})
def curses_factory(env: 'Environment',
for_machine: 'mesonlib.MachineChoice',
Expand Down Expand Up @@ -616,3 +640,5 @@ def shaderc_factory(env: 'Environment',
system_class=OpensslSystemDependency,
cmake_class=CMakeDependencyFactory('OpenSSL', modules=['OpenSSL::SSL']),
)

packages['objfw'] = ObjFWDependency
10 changes: 10 additions & 0 deletions test cases/objc/5 objfw/SimpleTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import <ObjFW/ObjFW.h>
#import <ObjFWTest/ObjFWTest.h>

@interface SimpleTest: OTTestCase
@end

@implementation SimpleTest
- (void)testMeson {
}
@end
12 changes: 12 additions & 0 deletions test cases/objc/5 objfw/TestApplication.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import <ObjFW/ObjFW.h>

@interface TestApplication: OFObject <OFApplicationDelegate>
@end

OF_APPLICATION_DELEGATE(TestApplication)

@implementation TestApplication
- (void)applicationDidFinishLaunching: (OFNotification *)notification {
[OFApplication terminate];
}
@end
14 changes: 14 additions & 0 deletions test cases/objc/5 objfw/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
project('objfw build tests', 'objc')

objfw_dep = dependency('objfw', required: false)
objfwtest_dep = dependency('objfw', modules: ['ObjFWTest'], required: false)

if not objfw_dep.found() or not objfwtest_dep.found()
error('MESON_SKIP_TEST: Need objfw dependency')
endif

executable('TestApplication', 'TestApplication.m',
dependencies: [objfw_dep])

executable('SimpleTest', 'SimpleTest.m',
dependencies: [objfwtest_dep])
10 changes: 10 additions & 0 deletions test cases/objcpp/3 objfw/SimpleTest.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import <ObjFW/ObjFW.h>
#import <ObjFWTest/ObjFWTest.h>

@interface SimpleTest: OTTestCase
@end

@implementation SimpleTest
- (void)testMeson {
}
@end
12 changes: 12 additions & 0 deletions test cases/objcpp/3 objfw/TestApplication.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import <ObjFW/ObjFW.h>

@interface TestApplication: OFObject <OFApplicationDelegate>
@end

OF_APPLICATION_DELEGATE(TestApplication)

@implementation TestApplication
- (void)applicationDidFinishLaunching: (OFNotification *)notification {
[OFApplication terminate];
}
@end
14 changes: 14 additions & 0 deletions test cases/objcpp/3 objfw/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
project('objfw build tests', 'objcpp')

objfw_dep = dependency('objfw', required: false)
objfwtest_dep = dependency('objfw', modules: ['ObjFWTest'], required: false)

if not objfw_dep.found() or not objfwtest_dep.found()
error('MESON_SKIP_TEST: Need objfw dependency')
endif

executable('TestApplication', 'TestApplication.mm',
dependencies: [objfw_dep])

executable('SimpleTest', 'SimpleTest.mm',
dependencies: [objfwtest_dep])

0 comments on commit ed71e8b

Please sign in to comment.