forked from jrprice/Oclgrind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
299 lines (252 loc) · 8.44 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
# CMakeLists.txt (Oclgrind)
# Copyright (c) 2013-2015, James Price and Simon McIntosh-Smith,
# University of Bristol. All rights reserved.
#
# This program is provided under a three-clause BSD license. For full
# license terms please see the LICENSE file distributed with this
# source code.
cmake_minimum_required(VERSION 2.8.12)
project(Oclgrind)
set(Oclgrind_VERSION_MAJOR 15)
set(Oclgrind_VERSION_MINOR 5)
include(CheckIncludeFiles)
include(CheckLibraryExists)
# Enable C99 for GCC (required for tests)
if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "-std=c99")
endif()
# Enable rpath on OS X
set(CMAKE_MACOSX_RPATH 1)
# Enable C++11 for Clang/GCC
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(CMAKE_CXX_FLAGS "-std=c++11")
endif()
# Disable min/max macros on Windows
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
add_definitions(-DNOMINMAX)
endif()
# Suppress warnings from OpenCL runtime API headers
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ignored-attributes -Wno-gcc-compat -Wno-availability")
endif()
# Find LLVM
find_package(LLVM REQUIRED CONFIG NO_CMAKE_BUILDS_PATH)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# Check LLVM version
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "3.6")
message(FATAL_ERROR "LLVM version must be >= 3.6")
endif()
set(LLVM_VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR})
# Add flags for LLVM
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
set(CLANG ${LLVM_TOOLS_BINARY_DIR}/clang)
# Get LLVM libraries for linking
llvm_map_components_to_libnames(LLVM_LIBS
bitreader bitwriter core instrumentation ipo irreader
linker mcparser objcarcopts option)
# Check for GNU readline library
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(READLINE_DIR "" CACHE PATH "Location of GNU readline library")
set(CMAKE_REQUIRED_INCLUDES ${READLINE_DIR}/include)
include_directories(${READLINE_DIR}/include)
link_directories(${READLINE_DIR}/lib)
message(STATUS ${CMAKE_REQUIRED_LIBRARIES})
check_include_files("stdio.h;readline/readline.h" HAVE_READLINE_H)
check_include_files("stdio.h;readline/history.h" HAVE_HISTORY_H)
check_library_exists(readline readline "${READLINE_DIR}/lib" HAVE_READLINE_LIB)
check_library_exists(readline add_history "${READLINE_DIR}/lib" HAVE_HISTORY_LIB)
if (HAVE_READLINE_H AND HAVE_HISTORY_H AND
HAVE_READLINE_LIB AND HAVE_HISTORY_LIB)
set(HAVE_READLINE 1)
list(APPEND CORE_EXTRA_LIBS readline)
else()
set(HAVE_READLINE 0)
message(WARNING "GNU readline library not found (set READLINE_DIR)\n"
"The interactive debugger will not have a command history.")
endif()
else()
set(HAVE_READLINE 0)
endif()
# Generate stringified clc.h
add_custom_command(
OUTPUT src/core/clc_h.cpp
COMMAND ${CMAKE_COMMAND} -DSOURCE_FILE=${CMAKE_SOURCE_DIR}/src/core/clc.h
-P ${CMAKE_SOURCE_DIR}/src/core/gen_clc_h.cmake
DEPENDS src/core/clc.h src/core/gen_clc_h.cmake
)
include_directories("src/" "${PROJECT_BINARY_DIR}")
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(CORE_LIB_TYPE "SHARED")
endif()
set(CORE_HEADERS
src/core/common.h
src/core/Context.h
src/core/half.h
src/core/Kernel.h
src/core/KernelInvocation.h
src/core/Memory.h
src/core/Plugin.h
src/core/Program.h
src/core/Queue.h
src/core/WorkItem.h
src/core/WorkGroup.h)
add_library(oclgrind ${CORE_LIB_TYPE}
${CORE_HEADERS}
src/core/clc_h.cpp
src/core/common.cpp
src/core/Context.cpp
src/core/Kernel.cpp
src/core/KernelInvocation.cpp
src/core/Memory.cpp
src/core/Plugin.cpp
src/core/Program.cpp
src/core/Queue.cpp
src/core/WorkItem.cpp
src/core/WorkItemBuiltins.cpp
src/core/WorkGroup.cpp
src/plugins/InstructionCounter.h
src/plugins/InstructionCounter.cpp
src/plugins/InteractiveDebugger.h
src/plugins/InteractiveDebugger.cpp
src/plugins/Logger.h
src/plugins/Logger.cpp
src/plugins/MemCheck.h
src/plugins/MemCheck.cpp
src/plugins/RaceDetector.h
src/plugins/RaceDetector.cpp)
target_link_libraries(oclgrind ${CORE_EXTRA_LIBS}
clangAnalysis clangAST clangBasic clangCodeGen clangDriver clangEdit
clangFrontend clangLex clangParse clangSema clangSerialization
${LLVM_LIBS})
# Sources for OpenCL runtime API frontend
set(RUNTIME_SOURCES
src/runtime/async_queue.h
src/runtime/async_queue.cpp
src/runtime/icd.h
src/runtime/runtime.cpp)
# Add ICD exports on Windows
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
list(APPEND RUNTIME_SOURCES src/runtime/icd.def)
endif()
add_library(oclgrind-rt-icd SHARED ${RUNTIME_SOURCES})
set_target_properties(oclgrind-rt-icd PROPERTIES COMPILE_FLAGS -DOCLGRIND_ICD)
target_link_libraries(oclgrind-rt-icd ${CMAKE_DL_LIBS} oclgrind)
# Add runtime exports on Windows
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
list(APPEND RUNTIME_SOURCES src/runtime/runtime.def)
endif()
add_library(oclgrind-rt SHARED ${RUNTIME_SOURCES})
target_link_libraries(oclgrind-rt ${CMAKE_DL_LIBS} oclgrind)
add_executable(oclgrind-kernel
src/kernel/oclgrind-kernel.cpp
src/kernel/Simulation.h
src/kernel/Simulation.cpp)
target_link_libraries(oclgrind-kernel oclgrind)
set(CLC_HEADERS
${CMAKE_BINARY_DIR}/include/oclgrind/clc.h
${CMAKE_BINARY_DIR}/include/oclgrind/clc32.pch
${CMAKE_BINARY_DIR}/include/oclgrind/clc64.pch
)
add_custom_target(CLC_HEADERS ALL DEPENDS ${CLC_HEADERS})
add_custom_command(
OUTPUT include/oclgrind/clc.h
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy ${CMAKE_SOURCE_DIR}/src/core/clc.h include/oclgrind/clc.h
DEPENDS src/core/clc.h)
# Generate precompiled headers for clc.h
add_custom_command(
OUTPUT include/oclgrind/clc32.pch
POST_BUILD
COMMAND
${CLANG}
-cc1 -x cl -cl-std=CL1.2 -O0 -g -fno-builtin
-emit-pch -triple spir-unknown-unknown
-relocatable-pch -isysroot ${CMAKE_BINARY_DIR}/include/oclgrind/
${CMAKE_BINARY_DIR}/include/oclgrind/clc.h
-o include/oclgrind/clc32.pch
DEPENDS include/oclgrind/clc.h
)
add_custom_command(
OUTPUT include/oclgrind/clc64.pch
POST_BUILD
COMMAND
${CLANG}
-cc1 -x cl -cl-std=CL1.2 -O0 -g -fno-builtin
-emit-pch -triple spir64-unknown-unknown
-relocatable-pch -isysroot ${CMAKE_BINARY_DIR}/include/oclgrind/
${CMAKE_BINARY_DIR}/include/oclgrind/clc.h
-o include/oclgrind/clc64.pch
DEPENDS include/oclgrind/clc.h
)
# Generate config.h
configure_file("cmake_config.h.in" "config.h")
# Install oclgrind script if not on Windows
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
file(READ src/runtime/oclgrind OCLGRIND_SCRIPT)
string(REGEX REPLACE
"__VERSION__" "${Oclgrind_VERSION_MAJOR}.${Oclgrind_VERSION_MINOR}"
OCLGRIND_SCRIPT "${OCLGRIND_SCRIPT}")
file(WRITE ${CMAKE_BINARY_DIR}/oclgrind "${OCLGRIND_SCRIPT}")
# Generate ICD loader
get_property(OCLGRIND_RT_FILENAME TARGET oclgrind-rt-icd PROPERTY LOCATION)
file(WRITE ${CMAKE_BINARY_DIR}/oclgrind.icd "${OCLGRIND_RT_FILENAME}\n")
install(PROGRAMS
${CMAKE_BINARY_DIR}/oclgrind
DESTINATION bin)
endif()
install(TARGETS
oclgrind-kernel
DESTINATION bin)
install(TARGETS
oclgrind oclgrind-rt oclgrind-rt-icd
DESTINATION lib)
install(FILES
${CORE_HEADERS} ${CMAKE_BINARY_DIR}/config.h ${CLC_HEADERS} LICENSE
DESTINATION include/oclgrind)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
install(FILES
src/CL/cl.h
src/CL/cl_d3d10.h
src/CL/cl_d3d11.h
src/CL/cl_dx9_media_sharing.h
src/CL/cl_egl.h
src/CL/cl_ext.h
src/CL/cl_gl.h
src/CL/cl_gl_ext.h
src/CL/cl_platform.h
src/CL/opencl.h
DESTINATION include/CL)
endif()
# Tests
enable_testing()
# Check for Python
find_package(PythonInterp)
if (PYTHONINTERP_FOUND)
# Add kernel tests
file(READ tests/kernels/TESTS KERNEL_TESTS)
string(REPLACE "\n" ";" KERNEL_TESTS ${KERNEL_TESTS})
foreach(test ${KERNEL_TESTS})
add_test(
NAME ${test}
COMMAND
${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/kernels/run_kernel_test.py
$<TARGET_FILE:oclgrind-kernel>
${CMAKE_SOURCE_DIR}/tests/kernels/${test}.sim)
endforeach(${test})
# Set PCH directory
set_tests_properties(${KERNEL_TESTS} PROPERTIES
ENVIRONMENT "OCLGRIND_PCH_DIR=${CMAKE_BINARY_DIR}/include/oclgrind")
# Expected failures
set_tests_properties(
atomics/atomic_intergroup_race
data-race/intragroup_hidden_race
PROPERTIES WILL_FAIL TRUE)
else()
message(WARNING "Kernel tests will not be run (Python required)")
endif()
# Add app tests
add_subdirectory(tests/apps)