source: CLRX/CLRadeonExtender/trunk/CMakeLists.txt @ 3200

Last change on this file since 3200 was 3200, checked in by matszpk, 3 years ago

CLRadeonExtender: Remove DEFAULT_AMDOCLPATH and introduce its runtime detection.

  • Property svn:mime-type set to text/plain
File size: 13.7 KB
Line 
1####
2#  CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
3#  Copyright (C) 2014-2017 Mateusz Szpakowski
4#
5#  This library is free software; you can redistribute it and/or
6#  modify it under the terms of the GNU Lesser General Public
7#  License as published by the Free Software Foundation; either
8#  version 2.1 of the License, or (at your option) any later version.
9#
10#  This library is distributed in the hope that it will be useful,
11#  but WITHOUT ANY WARRANTY; without even the implied warranty of
12#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13#  Lesser General Public License for more details.
14#
15#  You should have received a copy of the GNU Lesser General Public
16#  License along with this library; if not, write to the Free Software
17#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18####
19
20CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
21
22PROJECT(CLRadeonExtender)
23
24SET(CLRX_VERSION 0.1.4)
25SET(CLRX_MAJOR_VERSION 0)
26SET(CLRX_MINOR_VERSION 1)
27SET(CLRX_MICRO_VERSION 4)
28
29ENABLE_LANGUAGE(CXX)
30
31#####
32# packacing
33SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Unofficial OpenCL Radeon extensions")
34SET(CPACK_PACKAGE_VENDOR "matszpk")
35SET(CPACK_PACKAGE_MAINTAINER "matszpk")
36SET(CPACK_PACKAGE_VERSION_MAJOR ${CLRX_MAJOR_VERSION})
37SET(CPACK_PACKAGE_VERSION_MINOR ${CLRX_MINOR_VERSION})
38SET(CPACK_PACKAGE_VERSION_PATCH ${CLRX_MICRO_VERSION})
39SET(CPACK_PACKAGE_VERSION ${CLRX_VERSION})
40SET(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
41IF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
42SET(CPACK_PACKAGE_FILE_NAME CLRadeonExtender-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}-x64)
43ELSE((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
44SET(CPACK_PACKAGE_FILE_NAME CLRadeonExtender-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}-x86)
45ENDIF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
46
47INCLUDE(CPack)
48
49######
50## end packaging
51
52LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
53
54INCLUDE(CheckFunctionExists)
55INCLUDE(CheckLibraryExists)
56INCLUDE(CheckIncludeFileCXX)
57INCLUDE(CheckCCompilerFlag)
58INCLUDE(CheckCXXCompilerFlag)
59
60CHECK_CXX_COMPILER_FLAG("-std=gnu++11" HAVE_GNU11_FLAG)
61
62# workaround for
63SET(CMAKE_REQUIRED_FLAGS "-std=gnu++11")
64CHECK_INCLUDE_FILE_CXX(iostream HAVE_GNU11_IOSTREAM)
65UNSET(CMAKE_REQUIRED_FLAGS)
66
67IF(HAVE_GNU11_FLAG AND HAVE_GNU11_IOSTREAM)
68    SET(CPP_STANDARD "-std=gnu++11")
69    SET(HAVE_GNU11 1)
70ELSE(HAVE_GNU11_FLAG AND HAVE_GNU11_IOSTREAM)
71    SET(CPP_STANDARD "-std=c++11")
72ENDIF(HAVE_GNU11_FLAG AND HAVE_GNU11_IOSTREAM)
73
74MESSAGE(STATUS "Use standard ${CPP_STANDARD} for ${CMAKE_CXX_COMPILER}")
75
76### 32-bit compilation option
77OPTION(BUILD_32BIT "Build 32-bit version" OFF)
78
79IF(NOT LIB_INSTALL_DIR)
80    IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND
81        CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT BUILD_32BIT)
82        SET(LIB_INSTALL_DIR "lib64")
83    ELSE(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND
84        CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT BUILD_32BIT)
85        SET(LIB_INSTALL_DIR "lib")
86    ENDIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND
87        CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT BUILD_32BIT)
88    MESSAGE("Using library install dirname ${LIB_INSTALL_DIR}")
89ENDIF(NOT LIB_INSTALL_DIR)
90
91IF(BUILD_32BIT)
92    SET(CMAKE_CXX_FLAGS "-Wall -m32 ${CPP_STANDARD}")
93    SET(CMAKE_CXX_FLAGS_DEBUG "-Wall -m32 ${CPP_STANDARD} -g -O0 -DDEBUG=1")
94    SET(CMAKE_CXX_FLAGS_DEBUGCOV "-Wall -m32 ${CPP_STANDARD} -g -O0 -DDEBUG=1 --coverage")
95    SET(CMAKE_CXX_FLAGS_GCCSAN
96    "-Wall -m32 ${CPP_STANDARD} -g -O0 -DDEBUG=1 -fstack-protector-all -fsanitize=address")
97    SET(CMAKE_CXX_FLAGS_GCCSSP
98        "-Wall -m32 ${CPP_STANDARD} -g -O0 -DDEBUG=1 -fstack-protector-all")
99    SET(CMAKE_CXX_FLAGS_RELEASE "-Wall -m32 ${CPP_STANDARD} -O2 -fomit-frame-pointer")
100    SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
101        "-Wall -m32 ${CPP_STANDARD} -g -O2 -funroll-loops -DDEBUG=1")
102    SET(CMAKE_CXX_FLAGS_RELWITHPROFILE
103        "-Wall -m32 ${CPP_STANDARD} -g -O2 -pg -funroll-loops")
104ELSE(BUILD_32BIT)
105    IF(MSVC)
106    SET(CMAKE_CXX_FLAGS "/W1 /EHsc")
107    SET(CMAKE_CXX_FLAGS_DEBUG "/W1 /EHsc /Zi /Od /DDEBUG=1")
108    SET(CMAKE_CXX_FLAGS_RELEASE "/W1 /EHsc /O2")
109    SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/W1 /EHsc /Zi /O2 /DDEBUG=1")
110    ELSE(MSVC)
111    SET(CMAKE_CXX_FLAGS "-Wall ${CPP_STANDARD}")
112    SET(CMAKE_CXX_FLAGS_DEBUG "-Wall ${CPP_STANDARD} -g -O0 -DDEBUG=1")
113    SET(CMAKE_CXX_FLAGS_DEBUGCOV "-Wall ${CPP_STANDARD} -g -O0 -DDEBUG=1 --coverage")
114    SET(CMAKE_CXX_FLAGS_GCCSAN
115        "-Wall ${CPP_STANDARD} -g -O0 -DDEBUG=1 -fstack-protector-all -fsanitize=address")
116    SET(CMAKE_CXX_FLAGS_GCCSSP
117        "-Wall ${CPP_STANDARD} -g -O0 -DDEBUG=1 -fstack-protector-all")
118    SET(CMAKE_CXX_FLAGS_RELEASE "-Wall ${CPP_STANDARD} -O2 -fomit-frame-pointer")
119    SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
120        "-Wall ${CPP_STANDARD} -g -O2 -funroll-loops -DDEBUG=1")
121    SET(CMAKE_CXX_FLAGS_RELWITHPROFILE "-Wall ${CPP_STANDARD} -g -O2 -pg -funroll-loops")
122    ENDIF(MSVC)
123ENDIF(BUILD_32BIT)
124
125IF(IS_DIRECTORY "/usr/lib/x86_64-linux-gnu/amdgpu-pro" OR
126    IS_DIRECTORY "/usr/lib/i386-linux-gnu/amdgpu-pro")
127    SET(HAVE_UBUNTU_GPUPRO TRUE)
128    MESSAGE(STATUS "AMDGPU-PRO for Ubuntu is found")
129ENDIF(IS_DIRECTORY "/usr/lib/x86_64-linux-gnu/amdgpu-pro" OR
130    IS_DIRECTORY "/usr/lib/i386-linux-gnu/amdgpu-pro")
131IF(IS_DIRECTORY "/opt/amdgpu-pro/lib/x86_64-linux-gnu" OR
132        IS_DIRECTORY "/opt/amdgpu-pro/lib/i386-linux-gnu")
133    SET(HAVE_GPUPRO_NEW TRUE)
134    MESSAGE(STATUS "New AMDGPU-PRO is found")
135ENDIF(IS_DIRECTORY "/opt/amdgpu-pro/lib/x86_64-linux-gnu" OR
136        IS_DIRECTORY "/opt/amdgpu-pro/lib/i386-linux-gnu")
137IF (NOT HAVE_GPUPRO_NEW AND NOT HAVE_UBUNTU_GPUPRO)
138    IF(IS_DIRECTORY "/opt/amdgpu-pro/lib64" OR IS_DIRECTORY "/opt/amdgpu-pro/lib")
139        SET(HAVE_GPUPRO_SLES TRUE)
140        MESSAGE(STATUS "SLES AMDGPU-PRO is found")
141    ENDIF(IS_DIRECTORY "/opt/amdgpu-pro/lib64" OR IS_DIRECTORY "/opt/amdgpu-pro/lib")
142ENDIF(NOT HAVE_GPUPRO_NEW AND NOT HAVE_UBUNTU_GPUPRO)
143
144IF("${PROJECT_SOURCE_DIR}" MATCHES "${PROJECT_BINARY_DIR}")
145    MESSAGE("Please do an out-of-tree build:")
146    MESSAGE("rm -f CMakeCache.txt; mkdir -p default; cd default; cmake ..; make")
147    MESSAGE(FATAL_ERROR "in-tree-build detected")
148ENDIF("${PROJECT_SOURCE_DIR}" MATCHES "${PROJECT_BINARY_DIR}")
149
150SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
151SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
152
153OPTION(NO_STATIC "Disable static during compiling" OFF)
154
155INCLUDE(PortUtils)
156IF(WIN32)
157  SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
158ENDIF(WIN32)
159
160####
161# Documentation
162####
163OPTION(BUILD_DOCUMENTATION "Build whole documentation" OFF)
164OPTION(BUILD_DOXYGEN "Use Doxygen to create the HTML based API documentation" OFF)
165OPTION(BUILD_MANUAL "Use Pod2Man to create the Unix manuals" OFF)
166OPTION(BUILD_CLRXDOC "Use markdown_py to create offline wiki pages" OFF)
167
168IF(BUILD_DOCUMENTATION)
169  SET(BUILD_DOXYGEN ON)
170  SET(BUILD_MANUAL ON)
171  SET(BUILD_CLRXDOC ON)
172ENDIF(BUILD_DOCUMENTATION)
173
174####
175# rules to build doxygen and clrx doc is in proper CMakeLists.txt files in subdirectories
176####
177
178IF(BUILD_MANUAL)
179    INCLUDE(Pod2Man)
180    ADD_MANPAGE_TARGET()
181ENDIF(BUILD_MANUAL)
182####
183# Documentation
184####
185
186INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}")
187INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
188
189OPTION(NO_OPENCL "Do not use OpenCL" OFF)
190OPTION(NO_CLWRAPPER "Do not enable CLRXWrapper" OFF)
191
192####
193# OpenCL find
194####
195SET(OPENCL_DIST_DIR "" CACHE PATH "OpenCL Distribution directory")
196
197IF(NOT OPENCL_DIST_DIR AND NOT NO_OPENCL)
198    IF(EXISTS /opt/AMDAPP)
199        SET(OPENCL_DIST_DIR "/opt/AMDAPP")
200        MESSAGE(STATUS "OpenCL AMDAPP found")
201    ELSEIF(EXISTS "/Program Files (x86)/AMD APP SDK")
202        FILE(GLOB OPENCL_DIST_DIR "/Program Files (x86)/AMD APP SDK/*")
203        MESSAGE(STATUS "OpenCL AMDAPP found")
204    ELSEIF(EXISTS "/Program Files/AMD APP SDK")
205        FILE(GLOB OPENCL_DIST_DIR "/Program Files/AMD APP SDK/*")
206        MESSAGE(STATUS "OpenCL AMDAPP found")
207    ELSEIF(EXISTS /usr/include/CL)
208        SET(OPENCL_DIST_DIR "/usr")
209        MESSAGE(STATUS "Standard OpenCL found.")
210    ENDIF(EXISTS /opt/AMDAPP)
211ENDIF(NOT OPENCL_DIST_DIR AND NOT NO_OPENCL)
212
213IF (NOT NO_OPENCL AND OPENCL_DIST_DIR)
214    SET(OPENCL_LIBRARY_DIRS "")
215    SET(OPENCL_INCLUDE_DIRS "${OPENCL_DIST_DIR}/include")
216    SET(OPENCL_LIBRARIES "OpenCL")
217    SET(HAVE_OPENCL 1)
218ENDIF(NOT NO_OPENCL AND OPENCL_DIST_DIR)
219
220# check for AMDAPP lib/x86 or lib/x86_64 libOpenCL.so file
221IF(HAVE_OPENCL)
222    IF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
223        IF(EXISTS ${OPENCL_DIST_DIR}/lib/x86_64/libOpenCL.so OR
224            EXISTS ${OPENCL_DIST_DIR}/lib/x86_64/OpenCL.lib)
225            SET(OPENCL_LIBRARY_DIRS "${OPENCL_DIST_DIR}/lib/x86_64")
226        ENDIF(EXISTS ${OPENCL_DIST_DIR}/lib/x86_64/libOpenCL.so OR
227            EXISTS ${OPENCL_DIST_DIR}/lib/x86_64/OpenCL.lib)
228    ELSEIF(NOT CMAKE_CL_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL "i386" OR
229            CMAKE_SYSTEM_PROCESSOR STREQUAL "i486" OR
230            CMAKE_SYSTEM_PROCESSOR STREQUAL "i586" OR
231            CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" OR
232            CMAKE_SYSTEM_PROCESSOR STREQUAL "x86" OR BUILD_32BIT)
233        IF(EXISTS ${OPENCL_DIST_DIR}/lib/x86/libOpenCL.so OR
234            EXISTS ${OPENCL_DIST_DIR}/lib/x86/OpenCL.lib)
235            SET(OPENCL_LIBRARY_DIRS "${OPENCL_DIST_DIR}/lib/x86")
236        ENDIF(EXISTS ${OPENCL_DIST_DIR}/lib/x86/libOpenCL.so OR
237            EXISTS ${OPENCL_DIST_DIR}/lib/x86/OpenCL.lib)
238    ENDIF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
239    IF(HAVE_UBUNTU_GPUPRO)
240        IF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
241            SET(OPENCL_LIBRARY_DIRS "/usr/lib/x86_64-linux-gnu/amdgpu-pro")
242        ELSE((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
243            SET(OPENCL_LIBRARY_DIRS "/usr/lib/i386-linux-gnu/amdgpu-pro")
244        ENDIF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
245    ENDIF(HAVE_UBUNTU_GPUPRO)
246    IF(HAVE_GPUPRO_NEW)
247        IF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
248            SET(OPENCL_LIBRARY_DIRS "/opt/amdgpu-pro/lib/x86_64-linux-gnu")
249        ELSE((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
250            SET(OPENCL_LIBRARY_DIRS "/opt/amdgpu-pro/lib/i386-linux-gnu")
251        ENDIF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
252    ENDIF(HAVE_GPUPRO_NEW)
253    IF(HAVE_GPUPRO_SLES)
254        IF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
255            SET(OPENCL_LIBRARY_DIRS "/opt/amdgpu-pro/lib64")
256        ELSE((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
257            SET(OPENCL_LIBRARY_DIRS "/opt/amdgpu-pro/lib")
258        ENDIF((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_CL_64) AND NOT BUILD_32BIT)
259    ENDIF(HAVE_GPUPRO_SLES)
260ENDIF(HAVE_OPENCL)
261
262###
263# end of OpenCL config
264###
265
266IF(HAVE_OPENCL)
267    MESSAGE(STATUS "OpenCL found")
268    MESSAGE(STATUS "OpenCL library dirs: " ${OPENCL_LIBRARY_DIRS})
269    MESSAGE(STATUS "OpenCL libraries: " ${OPENCL_LIBRARIES})
270    MESSAGE(STATUS "OpenCL include dirs: " ${OPENCL_INCLUDE_DIRS})
271ELSE(HAVE_OPENCL)
272    MESSAGE(WARNING "OpenCL not found")
273ENDIF(HAVE_OPENCL)
274
275SET(CMAKE_THREAD_PREFER_PTHREAD 1)
276FIND_PACKAGE(Threads)
277
278IF(BUILD_32BIT)
279    MESSAGE(STATUS "This is 32-bit")
280    TRY_COMPILE(HAVE_INT128 "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/Int128Detect.c"
281        COMPILE_DEFINITIONS "-m32")
282ELSE(BUILD_32BIT)
283    TRY_COMPILE(HAVE_INT128 "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/Int128Detect.c")
284ENDIF(BUILD_32BIT)
285
286IF(HAVE_INT128)
287    MESSAGE(STATUS "128-bit integer arithmetic detected")
288ELSE(HAVE_INT128)
289    MESSAGE(STATUS "128-bit integer arithmetic not supported by compiler")
290ENDIF(HAVE_INT128)
291
292###
293# other dependencies and checks
294###
295
296FIND_PACKAGE(PNG)
297
298IF(PNG_FOUND)
299    MESSAGE(STATUS "Png found ${PNG_INCLUDE_DIRS}")
300ENDIF(PNG_FOUND)
301
302###
303# end of other dependencies and checks
304###
305
306IF(NOT WIN32)
307    SET(MATHLIB "m")
308ENDIF(NOT WIN32)
309
310CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/CLRX/Config.h.in"
311        "${PROJECT_BINARY_DIR}/CLRX/Config.h")
312
313OPTION(BUILD_TESTS "Compile tests" OFF)
314OPTION(BUILD_SAMPLES "Compile samples" OFF)
315OPTION(BUILD_STATIC_EXE "Compile static executables instead shared" OFF)
316
317IF(BUILD_STATIC_EXE)
318    SET(PROGRAM_LIB_SUFFIX "Static")
319ELSE(BUILD_STATIC_EXE)
320    SET(PROGRAM_LIB_SUFFIX "")
321ENDIF(BUILD_STATIC_EXE)
322
323IF(BUILD_TESTS)
324    ENABLE_TESTING()
325ENDIF(BUILD_TESTS)
326
327INCLUDE_DIRECTORIES(${OPENCL_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS})
328
329LINK_DIRECTORIES("${OPENCL_LIBRARY_DIRS}")
330
331ADD_SUBDIRECTORY(CLRX)
332ADD_SUBDIRECTORY(utils)
333IF(HAVE_OPENCL AND NOT NO_CLWRAPPER)
334    ADD_SUBDIRECTORY(clwrapper)
335ENDIF(HAVE_OPENCL AND NOT NO_CLWRAPPER)
336ADD_SUBDIRECTORY(amdbin)
337ADD_SUBDIRECTORY(amdasm)
338IF (BUILD_TESTS)
339    ADD_SUBDIRECTORY(tests)
340ENDIF(BUILD_TESTS)
341
342ADD_SUBDIRECTORY(editors)
343ADD_SUBDIRECTORY(programs)
344IF (BUILD_SAMPLES AND HAVE_OPENCL)
345    ADD_SUBDIRECTORY(samples)
346ENDIF(BUILD_SAMPLES AND HAVE_OPENCL)
347
348ADD_SUBDIRECTORY(doc)
349
350SET(DOCINSTALLDIR share/doc/CLRX)
351INSTALL(FILES "${PROJECT_SOURCE_DIR}/AUTHORS" DESTINATION "${DOCINSTALLDIR}")
352INSTALL(FILES "${PROJECT_SOURCE_DIR}/CONTRIBUTORS" DESTINATION "${DOCINSTALLDIR}")
353INSTALL(FILES "${PROJECT_SOURCE_DIR}/COPYING" DESTINATION "${DOCINSTALLDIR}")
354INSTALL(FILES "${PROJECT_SOURCE_DIR}/ChangeLog" DESTINATION "${DOCINSTALLDIR}")
355INSTALL(FILES "${PROJECT_SOURCE_DIR}/COPYING.LIB" DESTINATION "${DOCINSTALLDIR}")
356INSTALL(FILES "${PROJECT_SOURCE_DIR}/COPYING.DOC" DESTINATION "${DOCINSTALLDIR}")
357INSTALL(FILES "${PROJECT_SOURCE_DIR}/INSTALL" DESTINATION "${DOCINSTALLDIR}")
358INSTALL(FILES "${PROJECT_SOURCE_DIR}/README" DESTINATION "${DOCINSTALLDIR}")
359INSTALL(FILES "${PROJECT_SOURCE_DIR}/README.md" DESTINATION "${DOCINSTALLDIR}")
Note: See TracBrowser for help on using the repository browser.