Skip to content

Commit a5d239d

Browse files
committed
Rewrite CMake support
- Add back macOS and Linux support - Remove Corrosion from tree since it's only an implementation detail - Decouple the Windows example from the top-level CMake project - Add ARM64 support (at least for Windows)
1 parent 2352e98 commit a5d239d

File tree

22 files changed

+107
-4269
lines changed

22 files changed

+107
-4269
lines changed

.github/workflows/bindings.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
8585
- if: startsWith(matrix.os, 'windows')
8686
run: |
87-
mv target/${{ matrix.target }}/release/accesskit.dll.lib artifacts/${{ matrix.path }}/shared/accesskit.lib
87+
mv target/${{ matrix.target }}/release/accesskit.dll.lib artifacts/${{ matrix.path }}/static
8888
mv target/${{ matrix.target }}/release/*.pdb artifacts/${{ matrix.path }}/shared
8989
- if: contains(matrix.path, 'mingw')
9090
run: mv target/${{ matrix.target }}/release/libaccesskit.dll.a artifacts/${{ matrix.path }}/shared/libaccesskit.a
@@ -118,9 +118,8 @@ jobs:
118118
mkdir -p accesskit_c/lib
119119
mv artifacts/headers accesskit_c/include
120120
cp -r artifacts/*/* accesskit_c/lib
121-
cp -r bindings/c/corrosion accesskit_c/
122121
cp -r bindings/c/examples accesskit_c/
123-
cp bindings/c/CMakeLists.txt accesskit_c/
122+
cp bindings/c/accesskit-config.cmake accesskit_c/
124123
cp bindings/c/*.md accesskit_c/
125124
cp LICENSE* accesskit_c/
126125
mv accesskit_c ${{ github.ref_name }}

bindings/c/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build
22
include
3+
lib

bindings/c/CMakeLists.txt

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,30 @@ cmake_minimum_required(VERSION 3.20)
22

33
project(accesskit_c)
44

5-
SET(ACCESSKIT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
6-
SET(ACCESSKIT_IN_REPO ON)
7-
if (EXISTS(${CMAKE_SOURCE_DIR}/lib))
8-
SET(ACCESSKIT_IN_REPO OFF)
9-
if (WIN32)
10-
if (MINGW)
11-
if (CMAKE_SIZEOF_VOID_P MATCHES 8)
12-
SET(ACCESSKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib/windows/x86_64/mingw/static)
13-
else()
14-
SET(ACCESSKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib/windows/x86/mingw/static)
15-
endif()
16-
else()
17-
if (CMAKE_SIZEOF_VOID_P MATCHES 8)
18-
SET(ACCESSKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib/windows/x86_64/msvc/static)
19-
else()
20-
SET(ACCESSKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib/windows/x86/msvc/static)
21-
endif()
22-
endif()
23-
endif()
24-
else()
25-
add_subdirectory(corrosion)
26-
corrosion_import_crate(MANIFEST_PATH Cargo.toml)
5+
include(accesskit-config.cmake)
6+
include(FetchContent)
277

28-
find_program(RUSTUP rustup)
29-
find_program(CBINDGEN cbindgen)
30-
find_program(CLANG_FORMAT clang-format)
8+
FetchContent_Declare(
9+
Corrosion
10+
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
11+
GIT_TAG v0.3.5
12+
)
13+
FetchContent_MakeAvailable(Corrosion)
3114

32-
add_custom_target(headers
33-
COMMAND ${RUSTUP} run nightly ${CBINDGEN} --crate accesskit_c --output "${ACCESSKIT_INCLUDE_DIR}/accesskit.hpp" "${CMAKE_SOURCE_DIR}"
34-
COMMAND ${CLANG_FORMAT} -i "${ACCESSKIT_INCLUDE_DIR}/accesskit.hpp"
35-
COMMAND ${CMAKE_COMMAND} -E rename "${ACCESSKIT_INCLUDE_DIR}/accesskit.hpp" "${ACCESSKIT_INCLUDE_DIR}/accesskit.h"
36-
BYPRODUCTS "${ACCESSKIT_INCLUDE_DIR}/accesskit.h"
37-
)
15+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${ACCESSKIT_LIBRARIES_DIR}static")
16+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${ACCESSKIT_LIBRARIES_DIR}shared")
17+
set(CMAKE_PDB_OUTPUT_DIRECTORY "${ACCESSKIT_LIBRARIES_DIR}shared")
18+
corrosion_import_crate(MANIFEST_PATH Cargo.toml)
3819

39-
add_dependencies(cargo-prebuild_accesskit headers)
40-
endif()
20+
find_program(RUSTUP rustup)
21+
find_program(CBINDGEN cbindgen)
22+
find_program(CLANG_FORMAT clang-format)
4123

42-
option(BUILD_WINDOWS_EXAMPLE "Build the Windows example" OFF)
24+
add_custom_target(headers
25+
COMMAND ${RUSTUP} run nightly ${CBINDGEN} --crate accesskit_c --output "${ACCESSKIT_INCLUDE_DIR}/accesskit.hpp" "${CMAKE_SOURCE_DIR}"
26+
COMMAND ${CLANG_FORMAT} -i "${ACCESSKIT_INCLUDE_DIR}/accesskit.hpp"
27+
COMMAND ${CMAKE_COMMAND} -E rename "${ACCESSKIT_INCLUDE_DIR}/accesskit.hpp" "${ACCESSKIT_INCLUDE_DIR}/accesskit.h"
28+
BYPRODUCTS "${ACCESSKIT_INCLUDE_DIR}/accesskit.h"
29+
)
4330

44-
if (BUILD_WINDOWS_EXAMPLE)
45-
add_subdirectory(examples/windows)
46-
endif()
31+
add_dependencies(cargo-prebuild_accesskit headers)

bindings/c/README.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,47 @@
22

33
These are the bindings to use AccessKit from other languages through FFI such as in C.
44

5-
## Prerequisites
5+
## How to use in a CMake project
6+
7+
Decompress an accesskit_c release and place the resulting folder somewhere:
8+
9+
- already known by CMake,
10+
- listed in your `CMAKE_PREFIX_PATH`,
11+
- indicated by the `ACCESSKIT_DIR` option.
12+
13+
You can then require AccessKit as a dependency by adding this to your `CMakeLists.txt`:
14+
15+
```cmake
16+
find_package(ACCESSKIT REQUIRED)
17+
```
18+
19+
The headers can be added like so:
20+
21+
```cmake
22+
include_directories(YourProject ${ACCESSKIT_INCLUDE_DIR})
23+
```
24+
25+
Finally, link the library to your executable:
26+
27+
```cmake
28+
target_link_libraries(YourExecutable PUBLIC ${ACCESSKIT_LIBRARIES})
29+
```
30+
31+
See [the `examples` directory](https://github.com/AccessKit/accesskit/tree/main/bindings/c/examples) for project integration examples.
32+
33+
## Building from source
34+
35+
Prerequisites:
636

737
- [Rust](https://rustup.rs/)
838
- [CMake](https://cmake.org/), version 3.20 or higher
939
- A nightly Rust toolchain: `rustup install nightly`
1040
- [cbindgen](https://github.com/eqrion/cbindgen): `cargo install cbindgen`
1141
- [clang-format](https://releases.llvm.org/14.0.0/tools/clang/docs/ClangFormat.html), version 14 or higher
1242

13-
## Building
14-
15-
Once inside the `bindings/c` directory, CMake can be used like so:
43+
Once inside the `bindings/c` directory, CMake can be used like this to build the project:
1644

1745
```bash
18-
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release # See below for available configuration options.
19-
cd build
20-
cmake --build .
46+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
47+
cmake --build build
2148
```
22-
23-
Available configuration options:
24-
25-
- `BUILD_WINDOWS_EXAMPLE`: Builds the Windows example program

bindings/c/accesskit-config.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
set(ACCESSKIT_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/include")
2+
if (APPLE)
3+
set(_ACCESSKIT_OS "macos")
4+
elseif (UNIX)
5+
set(_ACCESSKIT_OS "linux")
6+
elseif (WIN32)
7+
set(_ACCESSKIT_OS "windows")
8+
if (MINGW)
9+
set(_ACCESSKIT_TOOLCHAIN "mingw/")
10+
else()
11+
set(_ACCESSKIT_TOOLCHAIN "msvc/")
12+
endif()
13+
if (CMAKE_VS_PLATFORM_NAME)
14+
string(TOLOWER "${CMAKE_VS_PLATFORM_NAME}" LOWER_VS_PLATFORM_NAME)
15+
if ("${LOWER_VS_PLATFORM_NAME}" STREQUAL "arm64")
16+
set(_ACCESSKIT_ARCH "arm64")
17+
set(_ACCESSKIT_TOOLCHAIN "")
18+
endif()
19+
endif()
20+
endif()
21+
if (NOT _ACCESSKIT_TOOLCHAIN)
22+
set(_ACCESSKIT_TOOLCHAIN "")
23+
endif()
24+
if (NOT _ACCESSKIT_ARCH)
25+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|amd64|x86_64)$")
26+
set(_ACCESSKIT_ARCH "x86_64")
27+
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM64|arm64|aarch64)$")
28+
set(_ACCESSKIT_ARCH "arm64")
29+
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(X86|x86|i686)$")
30+
set(_ACCESSKIT_ARCH "x86")
31+
endif()
32+
endif()
33+
set(ACCESSKIT_LIBRARIES_DIR "${CMAKE_CURRENT_LIST_DIR}/lib/${_ACCESSKIT_OS}/${_ACCESSKIT_ARCH}/${_ACCESSKIT_TOOLCHAIN}")
34+
find_library(ACCESSKIT_LIBRARIES accesskit ${ACCESSKIT_LIBRARIES_DIR}/static)

bindings/c/corrosion/.gitignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

bindings/c/corrosion/CMakeLists.txt

Lines changed: 0 additions & 134 deletions
This file was deleted.

bindings/c/corrosion/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

bindings/c/corrosion/README.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)