forked from otherlab/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeodeSupport.cmake
More file actions
203 lines (175 loc) · 5.17 KB
/
Copy pathGeodeSupport.cmake
File metadata and controls
203 lines (175 loc) · 5.17 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
include(CheckCXXCompilerFlag)
option(GEODE_NATIVE_ARCH "Compile with -march=native -mtune=native" ON)
# ARM64 / NEON detection
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64" OR
(APPLE AND CMAKE_OSX_ARCHITECTURES MATCHES "arm64"))
set(GEODE_ARCH_ARM64 TRUE)
set(GEODE_NEON TRUE)
message(STATUS "ARM64 target detected -- NEON enabled")
endif()
# Workaround: on macOS with CommandLineTools, the toolchain's incomplete
# c++/v1 directory can shadow the SDK's full headers. Detect and fix.
if(APPLE)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -print-sysroot
OUTPUT_VARIABLE _sysroot OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT _sysroot)
execute_process(
COMMAND xcrun --show-sdk-path
OUTPUT_VARIABLE _sysroot OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
if(_sysroot AND EXISTS "${_sysroot}/usr/include/c++/v1/cstdint")
# Test if the default search path can find cstdint
include(CheckIncludeFileCXX)
check_include_file_cxx(cstdint _HAS_CSTDINT)
if(NOT _HAS_CSTDINT)
message(STATUS "Fixing C++ stdlib include path: ${_sysroot}/usr/include/c++/v1")
add_compile_options(-nostdinc++ -isystem ${_sysroot}/usr/include/c++/v1)
endif()
endif()
endif()
function(add_python_module _name)
add_library(
${_name} MODULE ${ARGN}
)
target_include_directories(
${_name}
PUBLIC
${PYTHON_INCLUDE_DIRS}
${NUMPY_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}
)
target_link_libraries(
${_name}
PUBLIC
${PYTHON_LIBRARIES}
)
set_target_properties(
${_name}
PROPERTIES
PREFIX ""
)
endfunction()
set(GEODE_MODULES)
macro(INSTALL_GEODE_HEADERS _name)
install(FILES ${ARGN} DESTINATION include/geode/${_name}/)
endmacro(INSTALL_GEODE_HEADERS)
macro(ADD_GEODE_MODULE _name)
option(BUILD_GEODE_${_name} "Build the ${_name} module" TRUE)
if (BUILD_GEODE_${_name})
message(STATUS "Building ${_name} module.")
# Handle the NO_MODULE argument
# If it exists in the source list, remove it and don't add module.cpp
# If it doesn't, do nothing and add module.cpp
set(_srcs ${ARGN})
list(FIND _srcs NO_MODULE _no_module)
if (_no_module EQUAL -1)
list(APPEND _srcs module.cpp)
else()
list(REMOVE_AT _srcs ${_no_module})
endif()
add_library(
${_name} OBJECT ${_srcs}
)
set(GEODE_MODULE_OBJECTS ${GEODE_MODULE_OBJECTS} $<TARGET_OBJECTS:${_name}> PARENT_SCOPE)
set_property(
TARGET ${_name}
PROPERTY CXX_STANDARD 17
)
target_compile_definitions(
${_name}
PRIVATE
BUILDING_geode
)
if(GEODE_NEON)
target_compile_definitions(${_name} PUBLIC GEODE_NEON)
endif()
target_include_directories(
${_name}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../
${CMAKE_CURRENT_BINARY_DIR}/../../
)
if (GMP_FOUND)
target_include_directories(
${_name}
PUBLIC
${GMP_INCLUDE}
)
endif()
if (JPEG_FOUND)
target_include_directories(${_name} PUBLIC ${JPEG_INCLUDE_DIR})
endif()
if (PNG_FOUND)
target_include_directories(${_name} PUBLIC ${PNG_INCLUDE_DIRS})
endif()
if(GEODE_NATIVE_ARCH AND NOT CMAKE_CROSSCOMPILING)
target_compile_options(${_name} PUBLIC -march=native -mtune=native)
endif()
target_compile_options(
${_name}
PUBLIC
-O3
-funroll-loops
-Wall
-Winit-self
-Woverloaded-virtual
-Wsign-compare
-fno-strict-aliasing
# -Werror
-Wno-unused-function
-Wno-array-bounds
-Wno-unknown-pragmas
-Wno-deprecated
-Wno-format-security
-Wno-attributes
-Wno-unused-variable
-Wno-ignored-attributes
-Wno-unused-result
-fPIC
)
CHECK_CXX_COMPILER_FLAG(-Wno-undefined-var-template COMPILER_CHECKS_UNDEFINED_VAR_TEMPLATE)
if (COMPILER_CHECKS_UNDEFINED_VAR_TEMPLATE)
target_compile_options(
${_name}
PUBLIC
-Wno-undefined-var-template
)
endif()
CHECK_CXX_COMPILER_FLAG(-Wno-misleading-indentation COMPILER_CHECKS_MISLEADING_INDENTATION)
if (COMPILER_CHECKS_MISLEADING_INDENTATION)
target_compile_options(
${_name}
PUBLIC
-Wno-misleading-indentation
)
endif()
if (GEODE_PYTHON)
target_include_directories(
${_name}
PUBLIC
${PYTHON_INCLUDE_DIRS}
${NUMPY_INCLUDE_DIRS}
)
file(GLOB _python_bits *.py)
set(_pytargets "")
foreach(_python_bit ${_python_bits})
get_filename_component(_pyfile ${_python_bit} NAME)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_pyfile}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${_pyfile}" "${CMAKE_CURRENT_BINARY_DIR}/${_pyfile}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_pyfile}"
COMMENT "Copying ${_pyfile} to build tree"
)
list(APPEND _pytargets "${CMAKE_CURRENT_BINARY_DIR}/${_pyfile}")
endforeach()
add_custom_target(${_name}-python
ALL DEPENDS ${_pytargets}
)
endif()
endif()
endmacro(ADD_GEODE_MODULE)