forked from CLRX/CLRX-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
312 lines (262 loc) · 10.6 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
####
# CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
# Copyright (C) 2014-2016 Mateusz Szpakowski
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
####
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
PROJECT(CLRadeonExtender)
SET(CLRX_VERSION 0.1.2)
SET(CLRX_MAJOR_VERSION 0)
SET(CLRX_MINOR_VERSION 1)
SET(CLRX_MICRO_VERSION 2)
ENABLE_LANGUAGE(CXX)
#####
# packacing
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Unofficial OpenCL Radeon extensions")
SET(CPACK_PACKAGE_VENDOR "matszpk")
SET(CPACK_PACKAGE_MAINTAINER "matszpk")
SET(CPACK_PACKAGE_VERSION_MAJOR ${CLRX_MAJOR_VERSION})
SET(CPACK_PACKAGE_VERSION_MINOR ${CLRX_MINOR_VERSION})
SET(CPACK_PACKAGE_VERSION_PATCH ${CLRX_MICRO_VERSION})
INCLUDE(CPack)
######
## end packaging
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
INCLUDE(CheckFunctionExists)
INCLUDE(CheckLibraryExists)
INCLUDE(CheckIncludeFileCXX)
INCLUDE(CheckCCompilerFlag)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=gnu++11" HAVE_GNU11_FLAG)
# workaround for
SET(CMAKE_REQUIRED_FLAGS "-std=gnu++11")
CHECK_INCLUDE_FILE_CXX(iostream HAVE_GNU11_IOSTREAM)
UNSET(CMAKE_REQUIRED_FLAGS)
IF(HAVE_GNU11_FLAG AND HAVE_GNU11_IOSTREAM)
SET(CPP_STANDARD "-std=gnu++11")
SET(HAVE_GNU11 1)
ELSE(HAVE_GNU11_FLAG AND HAVE_GNU11_IOSTREAM)
SET(CPP_STANDARD "-std=c++11")
ENDIF(HAVE_GNU11_FLAG AND HAVE_GNU11_IOSTREAM)
MESSAGE(STATUS "Use standard ${CPP_STANDARD} for ${CMAKE_CXX_COMPILER}")
### 32-bit compilation option
OPTION(BUILD_32BIT "Build 32-bit version" OFF)
IF(NOT LIB_INSTALL_DIR)
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND
CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT BUILD_32BIT)
SET(LIB_INSTALL_DIR "lib64")
ELSE(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND
CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT BUILD_32BIT)
SET(LIB_INSTALL_DIR "lib")
ENDIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND
CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT BUILD_32BIT)
MESSAGE("Using library install dirname ${LIB_INSTALL_DIR}")
ENDIF(NOT LIB_INSTALL_DIR)
IF(BUILD_32BIT)
SET(CMAKE_CXX_FLAGS "-Wall -m32 ${CPP_STANDARD}")
SET(CMAKE_CXX_FLAGS_DEBUG "-Wall -m32 ${CPP_STANDARD} -g -O0 -DDEBUG=1")
SET(CMAKE_CXX_FLAGS_DEBUGCOV "-Wall -m32 ${CPP_STANDARD} -g -O0 -DDEBUG=1 --coverage")
SET(CMAKE_CXX_FLAGS_GCCSAN
"-Wall -m32 ${CPP_STANDARD} -g -O0 -DDEBUG=1 -fstack-protector-all -fsanitize=address")
SET(CMAKE_CXX_FLAGS_GCCSSP
"-Wall -m32 ${CPP_STANDARD} -g -O0 -DDEBUG=1 -fstack-protector-all")
SET(CMAKE_CXX_FLAGS_RELEASE "-Wall -m32 ${CPP_STANDARD} -O2 -fomit-frame-pointer")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"-Wall -m32 ${CPP_STANDARD} -g -O2 -funroll-loops -DDEBUG=1")
SET(CMAKE_CXX_FLAGS_RELWITHPROFILE
"-Wall -m32 ${CPP_STANDARD} -g -O2 -pg -funroll-loops")
ELSE(BUILD_32BIT)
IF(MSVC)
SET(CMAKE_CXX_FLAGS "/W1 /EHsc")
SET(CMAKE_CXX_FLAGS_DEBUG "/W1 /EHsc /Zi /Od /DDEBUG=1")
SET(CMAKE_CXX_FLAGS_RELEASE "/W1 /EHsc /O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/W1 /EHsc /Zi /O2 /DDEBUG=1")
ELSE(MSVC)
SET(CMAKE_CXX_FLAGS "-Wall ${CPP_STANDARD}")
SET(CMAKE_CXX_FLAGS_DEBUG "-Wall ${CPP_STANDARD} -g -O0 -DDEBUG=1")
SET(CMAKE_CXX_FLAGS_DEBUGCOV "-Wall ${CPP_STANDARD} -g -O0 -DDEBUG=1 --coverage")
SET(CMAKE_CXX_FLAGS_GCCSAN
"-Wall ${CPP_STANDARD} -g -O0 -DDEBUG=1 -fstack-protector-all -fsanitize=address")
SET(CMAKE_CXX_FLAGS_GCCSSP
"-Wall ${CPP_STANDARD} -g -O0 -DDEBUG=1 -fstack-protector-all")
SET(CMAKE_CXX_FLAGS_RELEASE "-Wall ${CPP_STANDARD} -O2 -fomit-frame-pointer")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"-Wall ${CPP_STANDARD} -g -O2 -funroll-loops -DDEBUG=1")
SET(CMAKE_CXX_FLAGS_RELWITHPROFILE "-Wall ${CPP_STANDARD} -g -O2 -pg -funroll-loops")
ENDIF(MSVC)
ENDIF(BUILD_32BIT)
IF(IS_DIRECTORY "/usr/lib/x86_64-linux-gnu/amdgpu-pro")
SET(HAVE_UBUNTU_GPUPRO TRUE)
MESSAGE(STATUS "AMDGPU-PRO for Ubuntu is found")
ENDIF(IS_DIRECTORY "/usr/lib/x86_64-linux-gnu/amdgpu-pro")
IF("${PROJECT_SOURCE_DIR}" MATCHES "${PROJECT_BINARY_DIR}")
MESSAGE("Please do an out-of-tree build:")
MESSAGE("rm -f CMakeCache.txt; mkdir -p default; cd default; cmake ..; make")
MESSAGE(FATAL_ERROR "in-tree-build detected")
ENDIF("${PROJECT_SOURCE_DIR}" MATCHES "${PROJECT_BINARY_DIR}")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
OPTION(NO_STATIC "Disable static during compiling" OFF)
INCLUDE(PortUtils)
IF(WIN32)
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
ENDIF(WIN32)
####
# Documentation
####
OPTION(BUILD_DOCUMENTATION "Build whole documentation" OFF)
OPTION(BUILD_DOXYGEN "Use Doxygen to create the HTML based API documentation" OFF)
OPTION(BUILD_MANUAL "Use Pod2Man to create the Unix manuals" OFF)
OPTION(BUILD_CLRXDOC "Use markdown_py to create offline wiki pages" OFF)
IF(BUILD_DOCUMENTATION)
SET(BUILD_DOXYGEN ON)
SET(BUILD_MANUAL ON)
SET(BUILD_CLRXDOC ON)
ENDIF(BUILD_DOCUMENTATION)
####
# rules to build doxygen and clrx doc is in proper CMakeLists.txt files in subdirectories
####
IF(BUILD_MANUAL)
INCLUDE(Pod2Man)
ADD_MANPAGE_TARGET()
ENDIF(BUILD_MANUAL)
####
# Documentation
####
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}")
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
####
# OpenCL find
####
SET(OPENCL_DIST_DIR "" CACHE PATH "OpenCL Distribution directory")
IF(NOT OPENCL_DIST_DIR)
IF(EXISTS /opt/AMDAPP)
SET(OPENCL_DIST_DIR "/opt/AMDAPP")
MESSAGE(STATUS "OpenCL AMDAPP found")
ELSEIF(EXISTS "/Program Files (x86)/AMD APP SDK")
FILE(GLOB OPENCL_DIST_DIR "/Program Files (x86)/AMD APP SDK/*")
MESSAGE(STATUS "OpenCL AMDAPP found")
ELSEIF(EXISTS "/Program Files/AMD APP SDK")
FILE(GLOB OPENCL_DIST_DIR "/Program Files/AMD APP SDK/*")
MESSAGE(STATUS "OpenCL AMDAPP found")
ELSEIF(EXISTS /usr/include/CL)
SET(OPENCL_DIST_DIR "/usr")
MESSAGE(STATUS "Standard OpenCL found.")
ENDIF(EXISTS /opt/AMDAPP)
ENDIF(NOT OPENCL_DIST_DIR)
IF (OPENCL_DIST_DIR)
SET(OPENCL_LIBRARY_DIRS "")
SET(OPENCL_INCLUDE_DIRS "${OPENCL_DIST_DIR}/include")
SET(OPENCL_LIBRARIES "OpenCL")
SET(HAVE_OPENCL 1)
ENDIF(OPENCL_DIST_DIR)
# check for AMDAPP lib/x86 or lib/x86_64 libOpenCL.so file
IF(HAVE_OPENCL)
IF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
IF(EXISTS ${OPENCL_DIST_DIR}/lib/x86_64/libOpenCL.so OR
EXISTS ${OPENCL_DIST_DIR}/lib/x86_64/OpenCL.lib)
SET(OPENCL_LIBRARY_DIRS "${OPENCL_DIST_DIR}/lib/x86_64")
ENDIF(EXISTS ${OPENCL_DIST_DIR}/lib/x86_64/libOpenCL.so OR
EXISTS ${OPENCL_DIST_DIR}/lib/x86_64/OpenCL.lib)
ELSEIF(NOT CMAKE_CL_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL "i386" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "i486" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "i586" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "x86" OR BUILD_32BIT)
IF(EXISTS ${OPENCL_DIST_DIR}/lib/x86/libOpenCL.so OR
EXISTS ${OPENCL_DIST_DIR}/lib/x86/OpenCL.lib)
SET(OPENCL_LIBRARY_DIRS "${OPENCL_DIST_DIR}/lib/x86")
ENDIF(EXISTS ${OPENCL_DIST_DIR}/lib/x86/libOpenCL.so OR
EXISTS ${OPENCL_DIST_DIR}/lib/x86/OpenCL.lib)
ENDIF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
ENDIF(HAVE_OPENCL)
###
# end of OpenCL config
###
IF(HAVE_OPENCL)
MESSAGE(STATUS "OpenCL found")
MESSAGE(STATUS "OpenCL library dirs: " ${OPENCL_LIBRARY_DIRS})
MESSAGE(STATUS "OpenCL libraries: " ${OPENCL_LIBRARIES})
MESSAGE(STATUS "OpenCL include dirs: " ${OPENCL_INCLUDE_DIRS})
ELSE(HAVE_OPENCL)
MESSAGE(WARNING "OpenCL not found")
ENDIF(HAVE_OPENCL)
SET(CMAKE_THREAD_PREFER_PTHREAD 1)
FIND_PACKAGE(Threads)
IF(BUILD_32BIT)
MESSAGE(STATUS "This is 32-bit")
TRY_COMPILE(HAVE_INT128 "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/Int128Detect.c"
COMPILE_DEFINITIONS "-m32")
ELSE(BUILD_32BIT)
TRY_COMPILE(HAVE_INT128 "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/Int128Detect.c")
ENDIF(BUILD_32BIT)
IF(HAVE_INT128)
MESSAGE(STATUS "128-bit integer arithmetic detected")
ELSE(HAVE_INT128)
MESSAGE(STATUS "128-bit integer arithmetic not supported by compiler")
ENDIF(HAVE_INT128)
###
# other dependencies and checks
###
FIND_PACKAGE(PNG)
IF(PNG_FOUND)
MESSAGE(STATUS "Png found ${PNG_INCLUDE_DIRS}")
ENDIF(PNG_FOUND)
###
# end of other dependencies and checks
###
IF(NOT WIN32)
SET(MATHLIB "m")
ENDIF(NOT WIN32)
CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/CLRX/Config.h.in"
"${PROJECT_BINARY_DIR}/CLRX/Config.h")
OPTION(BUILD_TESTS "Compile tests" OFF)
OPTION(BUILD_SAMPLES "Compile samples" OFF)
OPTION(BUILD_STATIC_EXE "Compile static executables instead shared" OFF)
IF(BUILD_STATIC_EXE)
SET(PROGRAM_LIB_SUFFIX "Static")
ELSE(BUILD_STATIC_EXE)
SET(PROGRAM_LIB_SUFFIX "")
ENDIF(BUILD_STATIC_EXE)
IF(BUILD_TESTS)
ENABLE_TESTING()
ENDIF(BUILD_TESTS)
INCLUDE_DIRECTORIES(${OPENCL_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS})
LINK_DIRECTORIES("${OPENCL_LIBRARY_DIRS}")
ADD_SUBDIRECTORY(CLRX)
ADD_SUBDIRECTORY(utils)
IF(HAVE_OPENCL)
ADD_SUBDIRECTORY(clwrapper)
ENDIF(HAVE_OPENCL)
ADD_SUBDIRECTORY(amdbin)
ADD_SUBDIRECTORY(amdasm)
IF (BUILD_TESTS)
ADD_SUBDIRECTORY(tests)
ENDIF(BUILD_TESTS)
ADD_SUBDIRECTORY(programs)
IF (BUILD_SAMPLES)
ADD_SUBDIRECTORY(samples)
ENDIF(BUILD_SAMPLES)
ADD_SUBDIRECTORY(doc)
SET(DOCINSTALLDIR share/doc/CLRX)
INSTALL(FILES "${PROJECT_SOURCE_DIR}/AUTHORS" DESTINATION "${DOCINSTALLDIR}")
INSTALL(FILES "${PROJECT_SOURCE_DIR}/CONTRIBUTORS" DESTINATION "${DOCINSTALLDIR}")
INSTALL(FILES "${PROJECT_SOURCE_DIR}/COPYING" DESTINATION "${DOCINSTALLDIR}")
INSTALL(FILES "${PROJECT_SOURCE_DIR}/COPYING.LIB" DESTINATION "${DOCINSTALLDIR}")
INSTALL(FILES "${PROJECT_SOURCE_DIR}/COPYING.DOC" DESTINATION "${DOCINSTALLDIR}")
INSTALL(FILES "${PROJECT_SOURCE_DIR}/INSTALL" DESTINATION "${DOCINSTALLDIR}")
INSTALL(FILES "${PROJECT_SOURCE_DIR}/README" DESTINATION "${DOCINSTALLDIR}")
INSTALL(FILES "${PROJECT_SOURCE_DIR}/README.md" DESTINATION "${DOCINSTALLDIR}")