Skip to content

Commit 8d0ef48

Browse files
committed
Init
1 parent 284cd57 commit 8d0ef48

File tree

5 files changed

+264
-68
lines changed

5 files changed

+264
-68
lines changed

.clang-format

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
Language: ObjC
3+
BasedOnStyle: LLVM
4+
IndentWidth: 4
5+
TabWidth: 4
6+
ColumnLimit: 100
7+
UseTab: Always
8+
9+
# Objective-C specific settings
10+
ObjCBlockIndentWidth: 4
11+
ObjCSpaceAfterProperty: true
12+
ObjCSpaceBeforeProtocolList: true
13+
14+
# Break constructor initializers before the colon and after commas
15+
BreakConstructorInitializersBeforeComma: false
16+
BreakConstructorInitializers: BeforeColon
17+
18+
# Add a space after C-style casts
19+
SpaceAfterCStyleCast: true
20+
21+
# Break before all operators
22+
BreakBeforeBinaryOperators: NonAssignment
23+
24+
# Pointer alignment
25+
DerivePointerAlignment: false
26+
PointerAlignment: Right
27+
28+
# Keep empty lines at the start of blocks
29+
KeepEmptyLinesAtTheStartOfBlocks: false

.gitignore

+150-68
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,150 @@
1-
# Xcode
2-
#
3-
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4-
5-
## User settings
6-
xcuserdata/
7-
8-
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
9-
*.xcscmblueprint
10-
*.xccheckout
11-
12-
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
13-
build/
14-
DerivedData/
15-
*.moved-aside
16-
*.pbxuser
17-
!default.pbxuser
18-
*.mode1v3
19-
!default.mode1v3
20-
*.mode2v3
21-
!default.mode2v3
22-
*.perspectivev3
23-
!default.perspectivev3
24-
25-
## Obj-C/Swift specific
26-
*.hmap
27-
28-
## App packaging
29-
*.ipa
30-
*.dSYM.zip
31-
*.dSYM
32-
33-
# CocoaPods
34-
#
35-
# We recommend against adding the Pods directory to your .gitignore. However
36-
# you should judge for yourself, the pros and cons are mentioned at:
37-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
38-
#
39-
# Pods/
40-
#
41-
# Add this line if you want to avoid checking in source code from the Xcode workspace
42-
# *.xcworkspace
43-
44-
# Carthage
45-
#
46-
# Add this line if you want to avoid checking in source code from Carthage dependencies.
47-
# Carthage/Checkouts
48-
49-
Carthage/Build/
50-
51-
# fastlane
52-
#
53-
# It is recommended to not store the screenshots in the git repo.
54-
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
55-
# For more information about the recommended setup visit:
56-
# https://docs.fastlane.tools/best-practices/source-control/#source-control
57-
58-
fastlane/report.xml
59-
fastlane/Preview.html
60-
fastlane/screenshots/**/*.png
61-
fastlane/test_output
62-
63-
# Code Injection
64-
#
65-
# After new code Injection tools there's a generated folder /iOSInjectionProject
66-
# https://github.com/johnno1962/injectionforxcode
67-
68-
iOSInjectionProject/
1+
### C ###
2+
# Prerequisites
3+
*.d
4+
5+
# Object files
6+
*.o
7+
*.ko
8+
*.obj
9+
*.elf
10+
11+
# Linker output
12+
*.ilk
13+
*.map
14+
*.exp
15+
16+
# Precompiled Headers
17+
*.gch
18+
*.pch
19+
20+
# Libraries
21+
*.lib
22+
*.a
23+
*.la
24+
*.lo
25+
26+
# Shared objects (inc. Windows DLLs)
27+
*.dll
28+
*.so
29+
*.so.*
30+
*.dylib
31+
32+
# Executables
33+
*.out
34+
35+
# Debug files
36+
*.dSYM/
37+
38+
### Linux ###
39+
*~
40+
41+
# temporary files which can be created if a process still has a handle open of a deleted file
42+
.fuse_hidden*
43+
44+
# KDE directory preferences
45+
.directory
46+
47+
# Linux trash folder which might appear on any partition or disk
48+
.Trash-*
49+
50+
# .nfs files are created when an open file is removed but is still being accessed
51+
.nfs*
52+
53+
### macOS ###
54+
# General
55+
.DS_Store
56+
.AppleDouble
57+
.LSOverride
58+
59+
# Icon must end with two \r
60+
Icon
61+
62+
63+
# Thumbnails
64+
._*
65+
66+
# Files that might appear in the root of a volume
67+
.DocumentRevisions-V100
68+
.fseventsd
69+
.Spotlight-V100
70+
.TemporaryItems
71+
.Trashes
72+
.VolumeIcon.icns
73+
.com.apple.timemachine.donotpresent
74+
75+
# Directories potentially created on remote AFP share
76+
.AppleDB
77+
.AppleDesktop
78+
Network Trash Folder
79+
Temporary Items
80+
.apdisk
81+
82+
### macOS Patch ###
83+
# iCloud generated files
84+
*.icloud
85+
86+
### Vim ###
87+
# Swap
88+
[._]*.s[a-v][a-z]
89+
!*.svg # comment out if you don't need vector files
90+
[._]*.sw[a-p]
91+
[._]s[a-rt-v][a-z]
92+
[._]ss[a-gi-z]
93+
[._]sw[a-p]
94+
95+
# Session
96+
Session.vim
97+
Sessionx.vim
98+
99+
# Temporary
100+
.netrwhist
101+
# Auto-generated tag files
102+
tags
103+
# Persistent undo
104+
[._]*.un~
105+
106+
### Meson ###
107+
# subproject directories
108+
/subprojects/*
109+
!/subprojects/*.wrap
110+
111+
# Meson Directories
112+
meson-logs
113+
meson-private
114+
115+
# Meson Files
116+
meson_benchmark_setup.dat
117+
meson_test_setup.dat
118+
sanitycheckcpp.cc # C++ specific
119+
sanitycheckcpp.exe # C++ specific
120+
121+
# Ninja
122+
build.ninja
123+
.ninja_deps
124+
.ninja_logs
125+
126+
# Misc
127+
compile_commands.json
128+
129+
130+
### VisualStudioCode ###
131+
.vscode/*
132+
!.vscode/settings.json
133+
!.vscode/tasks.json
134+
!.vscode/launch.json
135+
!.vscode/extensions.json
136+
!.vscode/*.code-snippets
137+
138+
# Local History for Visual Studio Code
139+
.history/
140+
141+
# Built Visual Studio Code Extensions
142+
*.vsix
143+
144+
### VisualStudioCode Patch ###
145+
# Ignore all local history of files
146+
.history
147+
.ionide
148+
149+
# objc-boilerplate
150+
build/

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
This boilerplate is a simple example of how to use Objective-C 2.0 and Foundation on Linux with GNUstep.
2+
We use the GNUstep configuration tool `gnustep-config` to get the GNUstep and Objective-C specific compiler
3+
and linker flags.
4+
5+
Make sure to source the `GNUstep.sh` script in your shell before compiling and running the program, otherwise
6+
meson might not be able to locate `gnustep-config`.
7+
8+
If you used the standard FHS installation layout, or did not explicitly set a layout when building GNUstep,
9+
you can source the script like this:
10+
11+
```bash
12+
source /usr/share/GNUstep/Makefiles/GNUstep.sh
13+
```
14+
Note that the Makefiles directory might be located in a different place on your system, depending on your distribution.
15+
16+
Meson also looks for CC, and OBJC environment variables to be set. Use clang as the compiler, as GCC does not
17+
support Objective-C 2.0.
18+
19+
## Dependencies
20+
- A working GNUstep installation with Objective-C 2.0 support (libobjc2, gnustep-make, gnustep-base)
21+
Please note that as of writing this, the GNUstep debian packages do not support Objective-C 2.0, and use the GCC runtime.
22+
23+
## Building
24+
First, setup the meson project and `build/` directory:
25+
```bash
26+
# Source the GNUstep environment script if not already done by your shell configuration (e.g. source /usr/share/GNUstep/Makefiles/GNUstep.sh)
27+
OBJC=clang meson setup build
28+
```
29+
30+
You can now compile and execute the example program:
31+
```bash
32+
ninja -C build
33+
./build/objc-boilerplate
34+
```
35+
36+
If everything worked, you should see an output similar to this:
37+
```bash
38+
2023-10-16 11:28:06.806 objc-boilerplate[40560:40560] Hello, World!
39+
```

meson.build

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
project('objc-boilerplate', 'objc', version : '0.1.0')
2+
3+
# Ensure clang is used for Objective-C
4+
objc_compiler = meson.get_compiler('objc')
5+
if objc_compiler.get_id() != 'clang'
6+
error('Clang is required for this project. Please set CC=clang, and OBJC=clang before running Meson.')
7+
endif
8+
9+
# Objective-C (GNUstep) support from gnustep-config
10+
gnustep_config = find_program('gnustep-config', required: true)
11+
if not gnustep_config.found()
12+
error('GNUstep is required for this project. Please install GNUstep and ensure gnustep-config is in your PATH. You might want to source GNUstep.sh before running Meson.')
13+
endif
14+
15+
gnustep_flags = run_command(gnustep_config, '--objc-flags', check: true).stdout().strip().split()
16+
gnustep_base_libs = run_command(gnustep_config, '--base-libs', check: true).stdout().strip().split()
17+
18+
# Filter out flags that are handled by Meson's built-in options
19+
filtered_objc_flags = []
20+
foreach flag : gnustep_flags
21+
if flag != '-Wall' and flag != '-g' and flag != '-O2'
22+
filtered_objc_flags += flag
23+
endif
24+
endforeach
25+
26+
# Enable ARC (Automatic Reference Counting)
27+
filtered_objc_flags += '-fobjc-arc'
28+
29+
# Add Objective-C flags and libraries
30+
add_project_arguments(filtered_objc_flags, language: 'objc')
31+
add_project_link_arguments(gnustep_base_libs, language: 'objc')
32+
33+
source = [
34+
# Objc files
35+
'src/main.m',
36+
]
37+
38+
executable('objc-boilerplate', source)

src/main.m

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import <Foundation/Foundation.h>
2+
3+
int main(int argc, const char *argv[]) {
4+
@autoreleasepool {
5+
NSLog(@"Hello, World!");
6+
}
7+
return 0;
8+
}

0 commit comments

Comments
 (0)