Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
163 lines (142 loc) · 5.75 KB
/
Copy pathCMakeLists.txt
File metadata and controls
163 lines (142 loc) · 5.75 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
cmake_minimum_required(VERSION 3.20)
project(CppJIT LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(GNUInstallDirs)
# This option won't make a lot of sense since we only ship the shared library in site-packages
# Perhaps this should permanently be OFF and users can build their own CppInterOp if they want to run the tests?
option(CPPJIT_ENABLE_CPPINTEROP_TESTS "enable CppInterOp tests" OFF)
set(CPPINTEROP_GIT_REPOSITORY "https://github.com/compiler-research/CppInterOp.git" CACHE STRING "")
set(CPPINTEROP_GIT_TAG "d3c8cf7aff7796e1539582f8e52910f351a48977" CACHE STRING "")
set(CPPINTEROP_SOURCE_DIR "" CACHE PATH
"Override default CppInterOp built by ExternalProject_Add, with a path to local CppInterOp source")
# The full Development component requires libpython, which manylinux
# images do not ship and extension modules do not need.
set(Python_FIND_VIRTUALENV ONLY)
find_package(Python COMPONENTS Interpreter Development.Module)
if(NOT Python_FOUND)
set(Python_FIND_VIRTUALENV STANDARD)
find_package(Python COMPONENTS Interpreter Development.Module)
endif()
if(NOT Python_Development.Module_FOUND)
message(FATAL_ERROR "Python development headers not found")
endif()
# The LLVM range the pinned CppInterOp supports. Update it with the tag.
set(CPPJIT_LLVM_VERSION_MIN 22)
set(CPPJIT_LLVM_VERSION_MAX 23)
# Runtime fallback anchor for the dispatch (see cppinterop_paths()): the
# installed package under scikit-build-core, the build tree otherwise --
# a plain `cmake --build` yields a runnable tree under <build>/python.
if(SKBUILD)
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_path('platlib'))"
OUTPUT_VARIABLE _python_platlib
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(CPPINTEROP_INSTALL_PREFIX "${_python_platlib}/cppjit")
else()
set(CPPINTEROP_INSTALL_PREFIX "${CMAKE_BINARY_DIR}")
endif()
# CppInterOp stages into the build tree in the runtime layout; the wheel
# ships a subset of it.
set(CPPINTEROP_STAGE_DIR "${CMAKE_BINARY_DIR}/interop")
# Acquire CppInterOp: an external prebuilt one (CppInterOp_DIR /
# CMAKE_PREFIX_PATH), else the pinned ExternalProject. Exports the
# CPPJIT_INTEROP_* coordinates consumed below.
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/AddCppInterOp.cmake)
cppjit_add_cppinterop()
# this libcppjit.so merges both cpyrt and the interop wrapper
file(GLOB CPYRT_SOURCES CONFIGURE_DEPENDS src/cpyrt/*.cxx)
set(INTEROP_SOURCES
src/interop/interop_wrapper.cxx
src/interop/cppinterop_dispatch.cxx
)
add_library(cppjit SHARED ${CPYRT_SOURCES} ${INTEROP_SOURCES})
if(TARGET CppInterOp)
add_dependencies(cppjit CppInterOp)
endif()
# The wrapper anchors these coordinates at its own load location, falling
# back to the install prefix (see cppinterop_paths()); the clang major
# names the versioned compiler probed for the runtime resource dir.
target_compile_definitions(cppjit PRIVATE
CPPINTEROP_INSTALL_PREFIX="${CPPINTEROP_INSTALL_PREFIX}"
CPPINTEROP_LIBRARY="${CPPJIT_INTEROP_LIBRARY}"
CPPINTEROP_INCLUDE_DIR="${CPPJIT_INTEROP_RUNTIME_INCLUDES}"
CPPJIT_CLANG_MAJOR="${CPPJIT_INTEROP_CLANG_MAJOR}"
CPPJIT_CLANG_INCLUDE_DIR="${CPPJIT_INTEROP_CLANG_DIR}"
$<$<BOOL:${CPPJIT_USE_CLING}>:CPPJIT_USE_CLING>
)
target_include_directories(cppjit PRIVATE
# src/ itself resolves the public "cpyrt/*.h" spellings against the
# flattened src/cpyrt/ directory
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/cpyrt
${CMAKE_CURRENT_SOURCE_DIR}/src/interop
${CPPJIT_INTEROP_COMPILE_INCLUDES}
${Python_INCLUDE_DIRS}
)
target_compile_options(cppjit PRIVATE
-Wall -Wno-strict-aliasing -Wno-register
)
if(CMAKE_COMPILER_IS_GNUCXX)
target_link_options(cppjit PRIVATE -Wl,-Bsymbolic-functions)
endif()
# macOS needs to allow undefined Python symbols
if(APPLE)
set_target_properties(cppjit PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup"
SUFFIX ".so"
)
endif()
set_target_properties(cppjit PROPERTIES
OUTPUT_NAME "cppjit"
PREFIX "lib"
)
# A plain build yields a runnable tree: the extension and the python
# sources assemble under <build>/python, beside <build>/interop.
if(NOT SKBUILD)
set_target_properties(cppjit PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python/cppjit"
)
add_custom_target(cppjit-python-tree ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/python/cppjit"
"${CMAKE_BINARY_DIR}/python/cppjit"
)
endif()
# the extension lives inside the package (import cppjit.libcppjit)
install(TARGETS cppjit
LIBRARY DESTINATION cppjit
)
# scikit-build-core ships the python sources itself (wheel.packages); a
# plain CMake install lays them out here so PYTHONPATH=<prefix> works.
if(NOT SKBUILD)
install(DIRECTORY python/cppjit
DESTINATION .
PATTERN "__pycache__" EXCLUDE
)
endif()
# An external CppInterOp is consumed in place and nothing of it ships;
# the bundled one installs with the builtin headers of the build clang,
# laid out as a headers-only resource dir (only include/ ships).
if(TARGET CppInterOp)
install(DIRECTORY "${CPPINTEROP_STAGE_DIR}/lib/"
DESTINATION cppjit/interop/lib
)
install(DIRECTORY "${CPPINTEROP_STAGE_DIR}/include/"
DESTINATION cppjit/interop/include
)
install(DIRECTORY "${CPPJIT_INTEROP_CLANG_RESOURCE_DIR}/include/"
DESTINATION "cppjit/interop/lib/clang/${CPPJIT_INTEROP_CLANG_MAJOR}/include"
)
endif()
# the public cpyrt API headers keep their installed cpyrt/ prefix
install(FILES
src/cpyrt/API.h
src/cpyrt/CommonDefs.h
src/cpyrt/DispatchPtr.h
src/cpyrt/PyException.h
src/cpyrt/Reflex.h
DESTINATION cppjit/interop/include/cpyrt
)