Skip to content

Commit 9cbf7a8

Browse files
committed
Add options to toggle building headers and libraries
1 parent 1e6d52a commit 9cbf7a8

File tree

1 file changed

+54
-41
lines changed

1 file changed

+54
-41
lines changed

bindings/c/CMakeLists.txt

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,65 @@ cmake_minimum_required(VERSION 3.20)
22

33
project(accesskit_c)
44

5-
include(FetchContent)
5+
option(ACCESSKIT_BUILD_HEADERS "Whether to build header files" ON)
6+
option(ACCESSKIT_BUILD_LIBRARIES "Whether to build libraries" ON)
67

7-
FetchContent_Declare(
8-
Corrosion
9-
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
10-
GIT_TAG v0.3.5
11-
)
12-
FetchContent_MakeAvailable(Corrosion)
8+
if (ACCESSKIT_BUILD_LIBRARIES)
9+
include(FetchContent)
1310

14-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
15-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
16-
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
17-
corrosion_import_crate(MANIFEST_PATH Cargo.toml)
11+
FetchContent_Declare(
12+
Corrosion
13+
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
14+
GIT_TAG v0.3.5
15+
)
16+
FetchContent_MakeAvailable(Corrosion)
1817

19-
find_program(RUSTUP rustup)
20-
find_program(CBINDGEN cbindgen)
21-
find_program(CLANG_FORMAT clang-format)
18+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
19+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
20+
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
21+
corrosion_import_crate(MANIFEST_PATH Cargo.toml)
22+
endif()
2223

23-
add_custom_target(headers
24-
COMMAND ${RUSTUP} run nightly ${CBINDGEN} --crate accesskit_c --output accesskit.hpp "${CMAKE_SOURCE_DIR}"
25-
COMMAND ${CLANG_FORMAT} -i accesskit.hpp
26-
COMMAND ${CMAKE_COMMAND} -E rename accesskit.hpp accesskit.h
27-
BYPRODUCTS accesskit.h
28-
)
24+
if (ACCESSKIT_BUILD_HEADERS)
25+
find_program(RUSTUP rustup)
26+
find_program(CBINDGEN cbindgen)
27+
find_program(CLANG_FORMAT clang-format)
2928

30-
add_dependencies(cargo-prebuild_accesskit headers)
29+
add_custom_target(headers ALL
30+
COMMAND ${RUSTUP} run nightly ${CBINDGEN} --crate accesskit_c --output accesskit.hpp "${CMAKE_SOURCE_DIR}"
31+
COMMAND ${CLANG_FORMAT} -i accesskit.hpp
32+
COMMAND ${CMAKE_COMMAND} -E rename accesskit.hpp accesskit.h
33+
BYPRODUCTS accesskit.h
34+
)
35+
36+
if (ACCESSKIT_BUILD_LIBRARIES)
37+
add_dependencies(cargo-prebuild_accesskit headers)
38+
endif()
39+
endif()
3140

3241
include("accesskit.cmake")
3342

34-
install(FILES
35-
"${CMAKE_CURRENT_BINARY_DIR}/accesskit.h"
36-
DESTINATION "${ACCESSKIT_INCLUDE_DIR}"
37-
)
38-
39-
install(FILES
40-
"$<TARGET_PROPERTY:accesskit-static,IMPORTED_LOCATION>"
41-
DESTINATION "${ACCESSKIT_LIBRARIES_DIR}/static"
42-
)
43-
44-
install(FILES
45-
"$<TARGET_PROPERTY:accesskit-shared,IMPORTED_LOCATION>"
46-
"$<$<STREQUAL:${_accesskit_toolchain},msvc>:${CMAKE_CURRENT_BINARY_DIR}/accesskit.pdb>"
47-
DESTINATION "${ACCESSKIT_LIBRARIES_DIR}/shared"
48-
)
49-
install(FILES
50-
"$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:accesskit-shared,IMPORTED_IMPLIB>,>>:$<TARGET_PROPERTY:accesskit-shared,IMPORTED_IMPLIB>>"
51-
RENAME "accesskit.lib"
52-
DESTINATION "${ACCESSKIT_LIBRARIES_DIR}/shared"
53-
)
43+
if (ACCESSKIT_BUILD_HEADERS)
44+
install(FILES
45+
"${CMAKE_CURRENT_BINARY_DIR}/accesskit.h"
46+
DESTINATION "${ACCESSKIT_INCLUDE_DIR}"
47+
)
48+
endif()
49+
50+
if (ACCESSKIT_BUILD_LIBRARIES)
51+
install(FILES
52+
"$<TARGET_PROPERTY:accesskit-static,IMPORTED_LOCATION>"
53+
DESTINATION "${ACCESSKIT_LIBRARIES_DIR}/static"
54+
)
55+
56+
install(FILES
57+
"$<TARGET_PROPERTY:accesskit-shared,IMPORTED_LOCATION>"
58+
"$<$<STREQUAL:${_accesskit_toolchain},msvc>:${CMAKE_CURRENT_BINARY_DIR}/accesskit.pdb>"
59+
DESTINATION "${ACCESSKIT_LIBRARIES_DIR}/shared"
60+
)
61+
install(FILES
62+
"$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:accesskit-shared,IMPORTED_IMPLIB>,>>:$<TARGET_PROPERTY:accesskit-shared,IMPORTED_IMPLIB>>"
63+
RENAME "accesskit.lib"
64+
DESTINATION "${ACCESSKIT_LIBRARIES_DIR}/shared"
65+
)
66+
endif()

0 commit comments

Comments
 (0)