-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
93 lines (75 loc) · 2.86 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
cmake_minimum_required(VERSION 3.15...3.26)
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)
find_package(
Python
COMPONENTS Interpreter Development.Module
REQUIRED)
add_compile_definitions(_CPMODULE)
# TODO: document this change
if (DEFINED ENV{CP_ENABLE_NATIVE} OR DEFINED CP_ENABLE_NATIVE)
message(STATUS "Building Caterpillar C extension")
python_add_library(
_C
MODULE
src/ccaterpillar/arch.c
src/ccaterpillar/atomobj.c
src/ccaterpillar/context.c
src/ccaterpillar/option.c
src/ccaterpillar/module.c
src/ccaterpillar/context.c
src/ccaterpillar/state.c
src/ccaterpillar/struct.c
src/ccaterpillar/layer.c
src/ccaterpillar/default.c
src/ccaterpillar/parsing_typeof.c
src/ccaterpillar/parsing_sizeof.c
src/ccaterpillar/parsing_pack.c
src/ccaterpillar/parsing_unpack.c
src/ccaterpillar/atomimpl/int.c
src/ccaterpillar/atomimpl/float.c
src/ccaterpillar/atomimpl/bool.c
src/ccaterpillar/atomimpl/char.c
src/ccaterpillar/atomimpl/pad.c
src/ccaterpillar/atomimpl/string.c
src/ccaterpillar/atomimpl/const.c
src/ccaterpillar/atomimpl/bytes.c
src/ccaterpillar/atomimpl/pstring.c
src/ccaterpillar/atomimpl/enum.c
src/ccaterpillar/atomimpl/varint.c
src/ccaterpillar/atomimpl/computed.c
src/ccaterpillar/atomimpl/lazy.c
src/ccaterpillar/atomimpl/cstring.c
src/ccaterpillar/atomimpl/builtins/builtin.c
src/ccaterpillar/atomimpl/builtins/repeated.c
src/ccaterpillar/atomimpl/builtins/condition.c
src/ccaterpillar/atomimpl/builtins/switch.c
src/ccaterpillar/atomimpl/builtins/atoffset.c
src/ccaterpillar/atomimpl/builtins/primitive.c
WITH_SOABI
)
target_include_directories(_C PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpillar/include)
message(STATUS "CMake ${CMAKE_VERSION}")
message(STATUS "Python ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}")
set (CP_GENAPI_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/src/code_gen/genapi.py)
set (CP_CAPI_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpillar/include/caterpillar/caterpillarapi.h.in)
set (CP_CAPI_CSRC ${CMAKE_CURRENT_SOURCE_DIR}/src/ccaterpillar/caterpillarapi.c.in)
set (CP_CAPI_HEADER_OUT ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpillar/include/caterpillar/caterpillarapi.h)
set (CP_CAPI_CSRC_OUT ${CMAKE_CURRENT_SOURCE_DIR}/src/ccaterpillar/caterpillarapi.c)
add_custom_target(
genapi ALL
# execute python ./src/code_gen/genapi.py ./src/caterpillar/include/caterpillar/caterpillarapi.h.in ./src/ccaterpillar/caterpillarapi.c.in
# in the root directory
COMMAND ${PYTHON_EXECUTABLE} ${CP_GENAPI_SCRIPT} ${CP_CAPI_HEADER} ${CP_CAPI_CSRC}
BYPRODUCTS ${CP_CAPI_HEADER_OUT} ${CP_CAPI_CSRC_OUT}
COMMENT "Generating Public Caterpillar API"
)
add_dependencies(_C genapi)
install(TARGETS _C DESTINATION caterpillar)
else()
MESSAGE(STATUS "Ignoring Caterpillar C extension")
endif()
if(DEFINED ENV{CP_ENABLE_TOOLS})
# install native extensions for tools (TODO)
else()
MESSAGE(STATUS "Ignoring tools")
endif()