Skip to content

Commit 2074e56

Browse files
committed
Add CMake support
1 parent afbf4a4 commit 2074e56

22 files changed

+4328
-81
lines changed

.clang-format

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Language: Cpp
33
# BasedOnStyle: Google
44
AccessModifierOffset: -1
55
AlignAfterOpenBracket: Align
6-
AlignArrayOfStructures: None
76
AlignConsecutiveMacros: None
87
AlignConsecutiveAssignments: None
98
AlignConsecutiveBitFields: None
@@ -12,6 +11,7 @@ AlignEscapedNewlines: Left
1211
AlignOperands: Align
1312
AlignTrailingComments: true
1413
AllowAllArgumentsOnNextLine: true
14+
AllowAllConstructorInitializersOnNextLine: true
1515
AllowAllParametersOfDeclarationOnNextLine: true
1616
AllowShortEnumsOnASingleLine: true
1717
AllowShortBlocksOnASingleLine: Never
@@ -59,28 +59,23 @@ BreakAfterJavaFieldAnnotations: false
5959
BreakStringLiterals: true
6060
ColumnLimit: 80
6161
CommentPragmas: '^ IWYU pragma:'
62-
QualifierAlignment: Leave
6362
CompactNamespaces: false
63+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
6464
ConstructorInitializerIndentWidth: 4
6565
ContinuationIndentWidth: 4
6666
Cpp11BracedListStyle: true
6767
DeriveLineEnding: true
6868
DerivePointerAlignment: true
6969
DisableFormat: false
70-
EmptyLineAfterAccessModifier: Never
7170
EmptyLineBeforeAccessModifier: LogicalBlock
7271
ExperimentalAutoDetectBinPacking: false
73-
PackConstructorInitializers: NextLine
74-
BasedOnStyle: ''
75-
ConstructorInitializerAllOnOneLineOrOnePerLine: false
76-
AllowAllConstructorInitializersOnNextLine: true
7772
FixNamespaceComments: true
7873
ForEachMacros:
7974
- foreach
8075
- Q_FOREACH
8176
- BOOST_FOREACH
82-
IfMacros:
83-
- KJ_IF_MAYBE
77+
StatementAttributeLikeMacros:
78+
- Q_EMIT
8479
IncludeBlocks: Regroup
8580
IncludeCategories:
8681
- Regex: '^<ext/.*\.h>'
@@ -101,7 +96,6 @@ IncludeCategories:
10196
CaseSensitive: false
10297
IncludeIsMainRegex: '([-_](test|unittest))?$'
10398
IncludeIsMainSourceRegex: ''
104-
IndentAccessModifiers: false
10599
IndentCaseLabels: true
106100
IndentCaseBlocks: false
107101
IndentGotoLabels: true
@@ -114,7 +108,6 @@ InsertTrailingCommas: None
114108
JavaScriptQuotes: Leave
115109
JavaScriptWrapImports: true
116110
KeepEmptyLinesAtTheStartOfBlocks: false
117-
LambdaBodyIndentation: Signature
118111
MacroBlockBegin: ''
119112
MacroBlockEnd: ''
120113
MaxEmptyLinesToKeep: 1
@@ -128,14 +121,12 @@ PenaltyBreakAssignment: 2
128121
PenaltyBreakBeforeFirstCallParameter: 1
129122
PenaltyBreakComment: 300
130123
PenaltyBreakFirstLessLess: 120
131-
PenaltyBreakOpenParenthesis: 0
132124
PenaltyBreakString: 1000
133125
PenaltyBreakTemplateDeclaration: 10
134126
PenaltyExcessCharacter: 1000000
135127
PenaltyReturnTypeOnItsOwnLine: 200
136128
PenaltyIndentedWhitespace: 0
137129
PointerAlignment: Left
138-
PPIndentWidth: -1
139130
RawStringFormats:
140131
- Language: Cpp
141132
Delimiters:
@@ -164,14 +155,10 @@ RawStringFormats:
164155
- ParseTextProtoOrDie
165156
- ParseTestProto
166157
- ParsePartialTestProto
167-
CanonicalDelimiter: pb
158+
CanonicalDelimiter: ''
168159
BasedOnStyle: google
169-
ReferenceAlignment: Pointer
170160
ReflowComments: true
171-
RemoveBracesLLVM: false
172-
SeparateDefinitionBlocks: Leave
173-
ShortNamespaceLines: 1
174-
SortIncludes: CaseSensitive
161+
SortIncludes: true
175162
SortJavaStaticImport: Before
176163
SortUsingDeclarations: true
177164
SpaceAfterCStyleCast: false
@@ -183,33 +170,20 @@ SpaceBeforeCpp11BracedList: false
183170
SpaceBeforeCtorInitializerColon: true
184171
SpaceBeforeInheritanceColon: true
185172
SpaceBeforeParens: ControlStatements
186-
SpaceBeforeParensOptions:
187-
AfterControlStatements: true
188-
AfterForeachMacros: true
189-
AfterFunctionDefinitionName: false
190-
AfterFunctionDeclarationName: false
191-
AfterIfMacros: true
192-
AfterOverloadedOperator: false
193-
BeforeNonEmptyParentheses: false
194173
SpaceAroundPointerQualifiers: Default
195174
SpaceBeforeRangeBasedForLoopColon: true
196175
SpaceInEmptyBlock: false
197176
SpaceInEmptyParentheses: false
198177
SpacesBeforeTrailingComments: 2
199-
SpacesInAngles: Never
178+
SpacesInAngles: false
200179
SpacesInConditionalStatement: false
201180
SpacesInContainerLiterals: true
202181
SpacesInCStyleCastParentheses: false
203-
SpacesInLineCommentPrefix:
204-
Minimum: 1
205-
Maximum: -1
206182
SpacesInParentheses: false
207183
SpacesInSquareBrackets: false
208184
SpaceBeforeSquareBrackets: false
209185
BitFieldColonSpacing: Both
210186
Standard: Auto
211-
StatementAttributeLikeMacros:
212-
- Q_EMIT
213187
StatementMacros:
214188
- Q_UNUSED
215189
- QT_REQUIRE_VERSION
@@ -223,3 +197,4 @@ WhitespaceSensitiveMacros:
223197
- NS_SWIFT_NAME
224198
- CF_SWIFT_NAME
225199
...
200+

bindings/c/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
2-
include
1+
build
2+
include

bindings/c/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(accesskit_c)
4+
5+
SET(ACCESSKIT_IN_REPO ON)
6+
if (NOT EXISTS(${CMAKE_SOURCE_DIR}/lib))
7+
SET(ACCESSKIT_IN_REPO OFF)
8+
if (WIN32)
9+
if (MINGW)
10+
if (CMAKE_SIZEOF_VOID_P MATCHES 8)
11+
SET(ACCESSKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib/windows/x86_64/mingw/static)
12+
else()
13+
SET(ACCESSKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib/windows/x86/mingw/static)
14+
endif()
15+
else()
16+
if (CMAKE_SIZEOF_VOID_P MATCHES 8)
17+
SET(ACCESSKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib/windows/x86_64/msvc/static)
18+
else()
19+
SET(ACCESSKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib/windows/x86/msvc/static)
20+
endif()
21+
endif()
22+
endif()
23+
endif()
24+
SET(ACCESSKIT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
25+
26+
if (${ACCESSKIT_IN_REPO})
27+
include(ExternalProject)
28+
add_subdirectory(corrosion)
29+
corrosion_import_crate(MANIFEST_PATH Cargo.toml)
30+
31+
add_custom_target(headers
32+
COMMAND rustup run nightly cbindgen --crate accesskit_c --output "${ACCESSKIT_INCLUDE_DIR}/accesskit.hpp" "${CMAKE_SOURCE_DIR}"
33+
COMMAND clang-format -i "${ACCESSKIT_INCLUDE_DIR}/accesskit.hpp"
34+
COMMAND ${CMAKE_COMMAND} -E rename "${ACCESSKIT_INCLUDE_DIR}/accesskit.hpp" "${ACCESSKIT_INCLUDE_DIR}/accesskit.h"
35+
DEPENDS "${ACCESSKIT_INCLUDE_DIR}/accesskit.h"
36+
)
37+
38+
add_dependencies(cargo-prebuild_accesskit headers)
39+
endif()
40+
41+
option(BUILD_WINDOWS_EXAMPLE "Build the Windows example" OFF)
42+
43+
if (BUILD_WINDOWS_EXAMPLE)
44+
add_subdirectory(examples/windows)
45+
endif()

bindings/c/Makefile

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
SHELL = /usr/bin/env bash
2-
.SHELLFLAGS = -o pipefail -c
3-
4-
CFLAGS := -Werror -Wall -Wextra -Wpedantic -g -I src/
5-
6-
PROFILE := release
7-
DESTDIR=/usr/local
8-
9-
ifeq ($(CC), clang)
10-
CFLAGS += -fsanitize=address -fsanitize=undefined
11-
LDFLAGS += -fsanitize=address
12-
endif
13-
14-
ifeq ($(PROFILE), release)
15-
CFLAGS += -O3
16-
CARGOFLAGS += --release
17-
endif
18-
19-
include:
20-
mkdir -p $@
21-
22-
include/accesskit.h: src/*.rs cbindgen.toml include
23-
rustup run nightly cbindgen | clang-format '--assume-filename=*.c' > $@
24-
25-
../../target/$(PROFILE)/libaccesskit.a: src/*.rs Cargo.toml
26-
cargo build $(CARGOFLAGS)
27-
28-
install: ../../target/$(PROFILE)/libaccesskit.a
29-
mkdir -p $(DESTDIR)/lib
30-
install target/$(PROFILE)/libaccesskit.a $(DESTDIR)/lib/libaccesskit.a
31-
mkdir -p $(DESTDIR)/include
32-
install include/accesskit.h $(DESTDIR)/include/
33-
34-
clean:
35-
rm -rf include
36-
rm -rf ../../target
1+
SHELL = /usr/bin/env bash
2+
.SHELLFLAGS = -o pipefail -c
3+
4+
CFLAGS := -Werror -Wall -Wextra -Wpedantic -g -I src/
5+
6+
PROFILE := release
7+
DESTDIR=/usr/local
8+
9+
ifeq ($(CC), clang)
10+
CFLAGS += -fsanitize=address -fsanitize=undefined
11+
LDFLAGS += -fsanitize=address
12+
endif
13+
14+
ifeq ($(PROFILE), release)
15+
CFLAGS += -O3
16+
CARGOFLAGS += --release
17+
endif
18+
19+
include:
20+
mkdir -p $@
21+
22+
include/accesskit.h: src/*.rs cbindgen.toml include
23+
rustup run nightly cbindgen | clang-format '--assume-filename=*.c' > $@
24+
25+
../../target/$(PROFILE)/libaccesskit.a: src/*.rs Cargo.toml
26+
cargo build $(CARGOFLAGS)
27+
28+
install: ../../target/$(PROFILE)/libaccesskit.a
29+
mkdir -p $(DESTDIR)/lib
30+
install target/$(PROFILE)/libaccesskit.a $(DESTDIR)/lib/libaccesskit.a
31+
mkdir -p $(DESTDIR)/include
32+
install include/accesskit.h $(DESTDIR)/include/
33+
34+
clean:
35+
rm -rf include
36+
rm -rf ../../target

bindings/c/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ These are the bindings to use AccessKit from other languages through FFI such as
55
## Prerequisites
66

77
- [Rust](https://rustup.rs/)
8+
- [CMake](https://cmake.org/), version 3.20 or higher
89
- A nightly Rust toolchain: `rustup install nightly`
910
- [cbindgen](https://github.com/eqrion/cbindgen): `cargo install cbindgen`
1011
- [clang-format](https://releases.llvm.org/14.0.0/tools/clang/docs/ClangFormat.html), version 14 or higher
1112

1213
## Building
1314

14-
Inside the `bindings/c` directory, some of the available make recipes include:
15+
Once inside the `bindings/c` directory, CMake can be used like so:
1516

16-
- `make include/accesskit.h`: generate the header files
17-
- `make ../../target/release/libaccesskit.a`: build static and dynamic libraries on Linux
18-
- `make clean`: remove generated artifacts
17+
```
18+
cmake -S . -B build # See below for available configuration options.
19+
cd build
20+
cmake --build .
21+
```
22+
23+
Available configuration options:
24+
25+
- `BUILD_WINDOWS_EXAMPLE`: Builds the Windows example program

bindings/c/corrosion/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
**/target/
3+
**/*.rs.bk
4+
build*/
5+
install*/
6+
.vscode
7+
.idea
8+
cmake-build-*
9+
test/test_header.cmake

0 commit comments

Comments
 (0)