forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
250 lines (204 loc) · 7.56 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(ARRAYFIRE)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
INCLUDE(${CMAKE_MODULE_PATH}/UploadCoveralls.cmake)
INCLUDE(AFInstallDirs)
OPTION(BUILD_TEST "Build Tests" ON)
OPTION(BUILD_EXAMPLES "Build Examples" ON)
OPTION(BUILD_GTEST "Download gtest and check for updates. Necessary if you change compilers" ON)
OPTION(BUILD_CPU "Build ArrayFire with a CPU backend" ON)
FIND_PACKAGE(CUDA QUIET)
IF(${CUDA_FOUND})
SET(BUILD_CUDA ON CACHE BOOL "")
ENDIF(${CUDA_FOUND})
OPTION(BUILD_CUDA "Build ArrayFire with a CUDA backend" OFF)
FIND_PACKAGE(OpenCL QUIET)
IF(${OpenCL_FOUND})
SET(BUILD_OPENCL ON CACHE BOOL "")
ENDIF(${OpenCL_FOUND})
OPTION(BUILD_OPENCL "Build ArrayFire with a OpenCL backend" OFF)
OPTION(BUILD_GRAPHICS "Build ArrayFire with Forge Graphics" ON)
OPTION(BUILD_DOCS "Create ArrayFire Documentation" OFF)
OPTION(WITH_COVERAGE "Added code coverage flags" OFF)
OPTION(BUILD_NONFREE "Build ArrayFire nonfree algorithms" OFF)
OPTION(BUILD_SIFT "Build ArrayFire nonfree algorithms" OFF)
MARK_AS_ADVANCED(BUILD_SIFT)
OPTION(BUILD_UNIFIED "Build Backend-Independent ArrayFire API" ON)
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
FIND_PACKAGE(FreeImage)
IF(FREEIMAGE_FOUND)
ADD_DEFINITIONS(-DWITH_FREEIMAGE)
SET(FreeImage_LIBS ${FREEIMAGE_LIBRARY})
MESSAGE(STATUS "Using FreeImage library ${FreeImage_LIBS}")
INCLUDE_DIRECTORIES(${FREEIMAGE_INCLUDE_PATH})
ELSE(FREEIMAGE_FOUND)
MESSAGE(WARNING, "FreeImage not found!")
ENDIF(FREEIMAGE_FOUND)
IF(BUILD_GRAPHICS)
OPTION(USE_SYSTEM_FORGE "Use system Forge" OFF)
IF(USE_SYSTEM_FORGE)
FIND_PACKAGE(Forge)
ELSE(USE_SYSTEM_FORGE)
INCLUDE("${CMAKE_MODULE_PATH}/build_forge.cmake")
ENDIF(USE_SYSTEM_FORGE)
IF(FORGE_FOUND)
ADD_DEFINITIONS(-DGLEW_MX -DWITH_GRAPHICS)
INCLUDE("${CMAKE_MODULE_PATH}/FindGLEWmx.cmake")
INCLUDE_DIRECTORIES(
${FORGE_INCLUDE_DIRECTORIES}
${GLEW_INCLUDE_DIR}
)
SET(FORGE_LIBRARIES ${FORGE_LIBRARIES}
${GLEWmx_LIBRARY}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY})
IF(APPLE)
FIND_PACKAGE(X11 REQUIRED)
INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR})
ENDIF(APPLE)
ELSE(FORGE_FOUND)
MESSAGE(WARNING "Forge not found. Graphics will be disabled")
ENDIF(FORGE_FOUND)
ENDIF(BUILD_GRAPHICS)
IF(BUILD_NONFREE)
MESSAGE(WARNING "Building With NONFREE ON requires the following patents")
SET(BUILD_SIFT ON)
ENDIF(BUILD_NONFREE)
IF(BUILD_SIFT)
ADD_DEFINITIONS(-DAF_BUILD_SIFT)
IF (NOT BUILD_NONFREE)
MESSAGE(WARNING "Building with SIFT requires the following patents")
ENDIF()
MESSAGE("Method and apparatus for identifying scale invariant features"
"in an image and use of same for locating an object in an image,\" David"
"G. Lowe, US Patent 6,711,293 (March 23, 2004). Provisional application"
"filed March 8, 1999. Asignee: The University of British Columbia. For"
"further details, contact David Lowe (lowe@cs.ubc.ca) or the"
"University-Industry Liaison Office of the University of British"
"Columbia.")
ENDIF(BUILD_SIFT)
INCLUDE_DIRECTORIES(
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/src/backend"
"${CMAKE_CURRENT_SOURCE_DIR}/src/api/c"
)
IF(${UNIX})
ADD_DEFINITIONS(-Wall -std=c++11 -fvisibility=hidden)
IF(${WITH_COVERAGE})
SET(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
SET(CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
SET(CMAKE_SHARED_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
SET(CMAKE_STATIC_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
ENDIF(${WITH_COVERAGE})
ENDIF(${UNIX})
# OS Definitions
IF(UNIX)
IF(APPLE) #OSX
ADD_DEFINITIONS(-DOS_MAC)
SET(CMAKE_MACOSX_RPATH ON)
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${AF_INSTALL_LIB_DIR}")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${AF_INSTALL_LIB_DIR}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${AF_INSTALL_LIB_DIR}")
ENDIF("${isSystemDir}" STREQUAL "-1")
ELSE(APPLE) #Linux
ADD_DEFINITIONS(-DOS_LNX)
ENDIF()
ELSE(${UNIX}) #Windows
ADD_DEFINITIONS(-DOS_WIN -DNOMINMAX)
ENDIF()
# Architechture Definitions
INCLUDE(${CMAKE_MODULE_PATH}/TargetArch.cmake)
target_architecture(ARCH)
IF(${ARCH} STREQUAL "x86_64")
ADD_DEFINITIONS(-DARCH_64)
ELSE(${ARCH})
ADD_DEFINITIONS(-DARCH_32)
ENDIF()
INCLUDE(${CMAKE_MODULE_PATH}/Version.cmake)
IF(${BUILD_CPU})
ADD_SUBDIRECTORY(src/backend/cpu)
ENDIF()
IF(${BUILD_CUDA})
ADD_SUBDIRECTORY(src/backend/cuda)
ENDIF()
IF(${BUILD_OPENCL})
ADD_SUBDIRECTORY(src/backend/opencl)
ENDIF()
IF(${BUILD_UNIFIED})
ADD_DEFINITIONS(-DAF_UNIFIED)
ADD_SUBDIRECTORY(src/api/unified)
ENDIF()
IF(${BUILD_DOCS})
ADD_SUBDIRECTORY(docs)
ENDIF()
ADD_EXECUTABLE(bin2cpp ${CMAKE_MODULE_PATH}/bin2cpp.cpp)
IF(${BUILD_TEST})
ENABLE_TESTING()
ADD_SUBDIRECTORY(test)
ENDIF()
IF(${BUILD_EXAMPLES})
ADD_SUBDIRECTORY(examples)
ENDIF()
##
# Installation of headers, and CMake scripts
##
INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION "${AF_INSTALL_INC_DIR}"
COMPONENT headers
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN ".gitignore" EXCLUDE
)
## The ArrayFire version file is generated and won't be included above, install
## it separately.
INSTALL(FILES
${CMAKE_SOURCE_DIR}/include/af/version.h DESTINATION "${AF_INSTALL_INC_DIR}/af/"
COMPONENT headers
)
IF(FORGE_FOUND AND NOT USE_SYSTEM_FORGE)
INSTALL(DIRECTORY "${CMAKE_BINARY_DIR}/third_party/forge/lib/" DESTINATION "${AF_INSTALL_LIB_DIR}"
COMPONENT libraries
)
ENDIF(FORGE_FOUND AND NOT USE_SYSTEM_FORGE)
## configuration to be used from the binary directory directly
SET(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
SET(BACKEND_DIR "src/backend/\${lowerbackend}")
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/ArrayFireConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/ArrayFireConfig.cmake
@ONLY)
## installed cmake configuration
# use a relative dir to keep arrayfire relocatable
STRING(REGEX REPLACE "[^/]+" ".." reldir "${AF_INSTALL_CMAKE_DIR}")
SET(INCLUDE_DIR "\${CMAKE_CURRENT_LIST_DIR}/${reldir}/include")
set(BACKEND_DIR)
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/ArrayFireConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/Install/ArrayFireConfig.cmake
@ONLY)
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/ArrayFireConfigVersion.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/ArrayFireConfigVersion.cmake
@ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/Install/ArrayFireConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/ArrayFireConfigVersion.cmake
DESTINATION ${AF_INSTALL_CMAKE_DIR}
COMPONENT cmake)
IF(APPLE)
INCLUDE("${CMAKE_MODULE_PATH}/osx_install/OSXInstaller.cmake")
ENDIF(APPLE)
##
# Packaging
##
include(${CMAKE_CURRENT_SOURCE_DIR}/CPack.cmake)