-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
353 lines (319 loc) · 12.9 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#
# Copyright (c) 2018-2019, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ispc CMakeLists.txt
#
cmake_minimum_required(VERSION 3.8)
if (UNIX)
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
endif()
set(PROJECT_NAME ispc)
set(ISPC_BUILD TRUE)
project(${PROJECT_NAME})
option(ARM_ENABLED "Enable ARM support" OFF)
option(NVPTX_ENABLED "Enable NVPTX support" OFF)
option(ISPC_INCLUDE_EXAMPLES "Generate build targets for the ISPC examples" ON)
option(ISPC_INCLUDE_TESTS "Generate build targets for the ISPC tests." ON)
option(ISPC_INCLUDE_UTILS "Generate build targets for the utils." ON)
option(ISPC_PREPARE_PACKAGE "Generate build targets for ispc package" OFF)
if (UNIX)
option(ISPC_STATIC_STDCXX_LINK "Link statically with libstdc++ and libgcc" OFF)
if (ISPC_PREPARE_PACKAGE AND (NOT APPLE))
option(ISPC_STATIC_LINK "Link statically" ON)
else()
option(ISPC_STATIC_LINK "Link statically" OFF)
endif()
option(ISPC_USE_ASAN "Build ispc with address sanitizer instrumentation using clang compiler" OFF)
endif()
# Use solution folders.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(OUTPUT_DEBUG Debug/bin)
set(OUTPUT_RELEASE Release/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin )
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: Use Release by default.")
endif(NOT CMAKE_BUILD_TYPE)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FixWindowsPath.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/LLVMConfig.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Git.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateBuiltins.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Stdlib.cmake)
find_package(PythonInterp 2.7 REQUIRED)
if (NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR "Python interpreter is not found")
endif()
find_package(BISON 2.4 REQUIRED)
if (BISON_FOUND)
set(BISON_INPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/parse.yy)
set(BISON_CPP_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/parse.cc)
set(BISON_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/parse.hh
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/parse.output)
if (WIN32)
win_path_to_cygwin(${BISON_INPUT} ${BISON_EXECUTABLE} BISON_INPUT)
endif()
add_custom_command (
OUTPUT ${BISON_CPP_OUTPUT} ${BISON_OUTPUT}
COMMAND ${BISON_EXECUTABLE} -d -t -v
--output=${BISON_CPP_OUTPUT}
${BISON_INPUT}
COMMENT "Generating parse.cc"
)
endif()
find_package(FLEX 2.5 REQUIRED)
if (FLEX_FOUND)
set(FLEX_INPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/lex.ll)
set(FLEX_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lex.cpp)
if (WIN32)
win_path_to_cygwin(${FLEX_INPUT} ${FLEX_EXECUTABLE} FLEX_INPUT)
endif()
add_custom_command(
OUTPUT ${FLEX_OUTPUT}
COMMAND ${FLEX_EXECUTABLE}
--outfile=${FLEX_OUTPUT}
${FLEX_INPUT}
COMMENT "Generating lex.cpp"
)
endif()
set (ISPC_MASKS 1 8 16 32 64)
set (ISPC_TARGETS avx2-i64x4 avx11-i64x4 avx1-i64x4 avx1 avx1-x2 avx11 avx11-x2 avx2 avx2-x2
sse2 sse2-x2 sse4-8 sse4-16 sse4 sse4-x2
generic-4 generic-8 generic-16 generic-32 generic-64 generic-1 knl skx)
set(CLANG_LIBRARY_LIST clangFrontend clangDriver clangSerialization clangParse clangSema clangAnalysis clangAST clangBasic clangEdit clangLex)
set(LLVM_COMPONENTS engine ipo bitreader bitwriter instrumentation linker)
# Component "option" was introduced in 3.3 and starting with 3.4 it is required for the link step.
if (${LLVM_VERSION_NUMBER} VERSION_GREATER "3.3.0")
set(LLVM_COMPONENTS ${LLVM_COMPONENTS} option)
endif()
if (ARM_ENABLED)
list(APPEND LLVM_COMPONENTS arm)
list(APPEND ISPC_TARGETS neon-32 neon-16 neon-8)
endif()
if (NVPTX_ENABLED)
list(APPEND LLVM_COMPONENTS nvptx)
list(APPEND ISPC_TARGETS nvptx)
endif()
get_llvm_libfiles(LLVM_LIBRARY_LIST ${LLVM_COMPONENTS})
get_llvm_cppflags(LLVM_CPP_FLAGS)
generate_target_builtins(BUILTIN_FILES ${ISPC_TARGETS})
generate_common_builtins(BUILTIN_CPP_FILES)
generate_stdlib(STDLIB_FILES ${ISPC_MASKS})
add_executable(${PROJECT_NAME} ${BUILTIN_FILES} ${BUILTIN_CPP_FILES}
${STDLIB_FILES} ${BISON_CPP_OUTPUT} ${FLEX_OUTPUT}
${CMAKE_CURRENT_SOURCE_DIR}/stdlib.ispc)
target_sources(${PROJECT_NAME}
PRIVATE
"src/ast.cpp"
"src/ast.h"
"src/builtins.cpp"
"src/builtins.h"
"src/cbackend.cpp"
"src/ctx.cpp"
"src/ctx.h"
"src/decl.cpp"
"src/decl.h"
"src/expr.cpp"
"src/expr.h"
"src/func.cpp"
"src/func.h"
"src/ispc.cpp"
"src/ispc.h"
"src/ispc_version.h"
"src/llvmutil.cpp"
"src/llvmutil.h"
"src/main.cpp"
"src/module.cpp"
"src/module.h"
"src/opt.cpp"
"src/opt.h"
"src/stmt.cpp"
"src/stmt.h"
"src/sym.cpp"
"src/sym.h"
"src/type.cpp"
"src/type.h"
"src/util.cpp"
"src/util.h"
"src/parse.yy"
"src/lex.ll"
)
# To show stdlib.ispc in VS solution:
if (WIN32)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/stdlib.ispc" PROPERTIES HEADER_FILE_ONLY TRUE)
source_group("ISPC" FILES "${CMAKE_CURRENT_SOURCE_DIR}/stdlib.ispc")
endif()
# Build definitions
target_compile_definitions(${PROJECT_NAME} PRIVATE ${LLVM_VERSION})
if (UNIX)
string(TIMESTAMP BUILD_DATE "%Y%m%d")
target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_DATE=\"${BUILD_DATE}\"
BUILD_VERSION=\"${GIT_COMMIT_HASH}\")
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE NOMINMAX)
if (NOT CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
target_compile_definitions(${PROJECT_NAME} PRIVATE NDEBUG)
endif()
endif()
if (ARM_ENABLED)
target_compile_definitions(${PROJECT_NAME} PRIVATE ISPC_ARM_ENABLED)
endif()
if (NVPTX_ENABLED)
target_compile_definitions(${PROJECT_NAME} PRIVATE ISPC_NVPTX_ENABLED)
endif()
# Include directories
target_include_directories(${PROJECT_NAME} PRIVATE
${LLVM_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
# Compile options
if (UNIX)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-sign-compare -Wno-unused-function -Werror ${LLVM_CPP_FLAGS})
set_source_files_properties("src/cbackend.cpp" PROPERTIES COMPILE_FLAGS "-fno-exceptions")
else()
target_compile_options(${PROJECT_NAME} PRIVATE /W3 /wd4146 /wd4800 /wd4996 /wd4355 /wd4624 /wd4244 /wd4141 /wd4291 /wd4018)
set_source_files_properties(${FLEX_OUTPUT} PROPERTIES COMPILE_FLAGS "/wd4005 /wd4003")
set_source_files_properties(${BISON_OUTPUT} PROPERTIES COMPILE_FLAGS "/wd4005 /wd4065")
endif()
if (${LLVM_VERSION_NUMBER} VERSION_GREATER "3.4.0")
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
if (UNIX)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF)
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-c99-extensions -Wno-deprecated-register -fno-rtti)
if (ISPC_USE_ASAN)
target_compile_options(${PROJECT_NAME} PRIVATE -fsanitize=address)
endif()
endif()
endif()
# Link options
if (WIN32)
if (NOT CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/OPT:REF /OPT:ICF")
endif()
endif()
if (ISPC_STATIC_STDCXX_LINK)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
endif()
if (ISPC_STATIC_LINK)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-static")
endif()
if (ISPC_USE_ASAN)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-fsanitize=address")
endif()
# Link against Clang libraries
foreach(clangLib ${CLANG_LIBRARY_LIST})
find_library(${clangLib}Path NAMES ${clangLib} HINTS ${LLVM_LIBRARY_DIRS})
list(APPEND CLANG_LIBRARY_FULL_PATH_LIST ${${clangLib}Path})
endforeach()
target_link_libraries(${PROJECT_NAME} ${CLANG_LIBRARY_FULL_PATH_LIST})
# Link against LLVM libraries
target_link_libraries(${PROJECT_NAME} ${LLVM_LIBRARY_LIST})
if (WIN32)
target_link_libraries(${PROJECT_NAME} version.lib shlwapi.lib odbc32.lib odbccp32.lib)
else()
target_link_libraries(${PROJECT_NAME} pthread dl)
if (${LLVM_VERSION_NUMBER} VERSION_GREATER "3.4.0")
target_link_libraries(${PROJECT_NAME} z)
endif()
if (APPLE)
target_link_libraries(${PROJECT_NAME} curses)
else()
target_link_libraries(${PROJECT_NAME} tinfo)
if (${LLVM_VERSION_NUMBER} VERSION_GREATER "3.3.0")
target_link_libraries(${PROJECT_NAME} curses)
endif()
endif()
endif()
# Build target for utility checking host ISA
if (ISPC_INCLUDE_UTILS)
add_executable(check_isa "")
target_sources(check_isa PRIVATE check_isa.cpp)
set_target_properties(check_isa PROPERTIES FOLDER "Utils")
if (NOT ISPC_PREPARE_PACKAGE)
install (TARGETS check_isa DESTINATION bin)
endif()
endif()
if (ISPC_INCLUDE_EXAMPLES AND NOT ISPC_PREPARE_PACKAGE)
add_subdirectory(examples)
endif()
if (ISPC_INCLUDE_TESTS)
add_subdirectory(tests)
endif()
# Install
install (TARGETS ${PROJECT_NAME} DESTINATION bin)
if (ISPC_PREPARE_PACKAGE)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/examples/" DESTINATION examples)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/contrib/" DESTINATION contrib)
install (FILES "${PROJECT_SOURCE_DIR}/LICENSE.txt" DESTINATION .)
install (FILES "${PROJECT_SOURCE_DIR}/docs/ReleaseNotes.txt" DESTINATION .)
include(ExternalProject)
ExternalProject_Add(ispc_web
GIT_REPOSITORY https://github.com/ispc/ispc.github.com.git
PREFIX ispc_web
SOURCE_DIR ispc_web/repo
CONFIGURE_COMMAND cmake -E echo "Skipping configure step."
BUILD_COMMAND cmake -E echo "Skipping build step."
INSTALL_COMMAND cmake -E echo "Skipping install step."
)
ExternalProject_Get_Property(ispc_web SOURCE_DIR)
set(ISPC_WEB_SOURCE_DIR "${SOURCE_DIR}")
set(ISPC_DOCS ${ISPC_WEB_SOURCE_DIR}/faq.html
${ISPC_WEB_SOURCE_DIR}/ispc.html
${ISPC_WEB_SOURCE_DIR}/perfguide.html)
install(FILES ${ISPC_DOCS} DESTINATION .)
install(DIRECTORY "${ISPC_WEB_SOURCE_DIR}/css" DESTINATION css)
# CPack configuration
if (WIN32)
set(CPACK_GENERATOR "ZIP")
set(ISPC_SYSTEM_NAME "windows")
else()
set(CPACK_GENERATOR "TGZ")
if (APPLE)
set(ISPC_SYSTEM_NAME "macOS")
else()
set(ISPC_SYSTEM_NAME "linux")
endif()
endif()
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
# Get ispc version
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/ispc_version.h" ispc_ver)
string(REGEX MATCH "ISPC_VERSION \"([0-9]*)\.([0-9]*)\.([0-9]*[a-z]*)" _ ${ispc_ver})
set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
string(CONCAT CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}"
"-v${CPACK_PACKAGE_VERSION_MAJOR}"
".${CPACK_PACKAGE_VERSION_MINOR}"
".${CPACK_PACKAGE_VERSION_PATCH}"
"-${ISPC_SYSTEM_NAME}")
include(CPack)
endif()