forked from libocca/occa
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
286 lines (229 loc) · 8.35 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
cmake_minimum_required (VERSION 3.12 FATAL_ERROR)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
message(STATUS "Using CMake version ${CMAKE_VERSION}")
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0056 NEW)
# Set project
project (occa
DESCRIPTION "JIT Compilation for Multiple Architectures: C++, OpenMP, CUDA, HIP, OpenCL, Metal"
HOMEPAGE_URL "https://github.com/libocca/occa"
LANGUAGES C CXX)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(ENABLE_OPENMP "Build with OpenMP if available" ON)
option(ENABLE_CUDA "Build with CUDA if available" ON)
option(ENABLE_OPENCL "Build with OpenCL if available" ON)
option(ENABLE_HIP "Build with HIP if available" ON)
option(ENABLE_METAL "Build with Metal if available" ON)
#option(ENABLE_ONEAPI "Build with OneAPI if available" ON)
option(ENABLE_MPI "Build with MPI if available" ON)
option(ENABLE_TESTS "Build tests" OFF)
option(ENABLE_EXAMPLES "Build simple examples" OFF)
option(ENABLE_UTILITY "Build occa utility binary" ON)
option(ENABLE_FORTRAN "Enable Fortran interface" OFF)
if (ENABLE_FORTRAN)
enable_language(Fortran)
endif()
set(OCCA_USING_VS OFF)
set(OCCA_UNSAFE OFF)
# Test Apple first because UNIX==true for Apple and Linux.
if (APPLE)
set(OCCA_OS "OCCA_MACOS_OS")
elseif (UNIX)
set(OCCA_OS "OCCA_LINUX_OS")
else()
set(OCCA_OS "OCCA_WINDOWS_OS")
endif()
include(SetCompilerFlags)
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
message("-- System: ${CMAKE_SYSTEM}")
message("-- Build type: ${CMAKE_BUILD_TYPE}")
message("-- C flags: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
message("-- CXX flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
if (ENABLE_FORTRAN)
message("-- Fortran flags: ${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
endif()
set(OCCA_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(OCCA_BUILD_DIR ${CMAKE_BINARY_DIR})
if (ENABLE_FORTRAN)
set (CMAKE_Fortran_MODULE_DIRECTORY ${OCCA_BUILD_DIR}/mod)
endif()
##############################
# LibOCCA Target
##############################
add_library(libocca SHARED)
# Without this, CMake will create liblibocca.so
set_target_properties(libocca PROPERTIES OUTPUT_NAME occa LIBRARY_OUTPUT_DIRECTORY ${OCCA_BUILD_DIR}/lib)
#Find needed and requested packages
find_package(Threads REQUIRED)
target_link_libraries(libocca PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
target_include_directories(libocca PUBLIC
$<BUILD_INTERFACE:${OCCA_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${OCCA_BUILD_DIR}/include>)
target_compile_definitions(libocca PRIVATE -DUSE_CMAKE)
##############################
# OpenMP
##############################
if (ENABLE_OPENMP)
find_package(OpenMP)
if (OPENMP_CXX_FOUND)
set(OCCA_OPENMP_ENABLED 1)
message("-- OpenMP include dirs: ${OpenMP_CXX_INCLUDE_DIRS}")
message("-- OpenMP libraries: ${OpenMP_CXX_LIBRARIES}")
target_include_directories(libocca PRIVATE ${OpenMP_CXX_INCLUDE_DIRS})
target_link_libraries(libocca PRIVATE ${OpenMP_CXX_LIBRARIES})
else(OPENMP_CXX_FOUND)
set(OCCA_OPENMP_ENABLED 0)
endif(OPENMP_CXX_FOUND)
endif(ENABLE_OPENMP)
##############################
# CUDA
##############################
if (ENABLE_CUDA)
find_package(CUDA)
if (CUDA_FOUND)
set(OCCA_CUDA_ENABLED 1)
#find the shared library, rather than the static that find_package returns
find_library(
CUDA_LIB
NAMES cuda
PATHS
${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib64 lib lib64/stubs lib/stubs
DOC "CUDA driver lib location"
)
message("-- CUDA include dirs: ${CUDA_INCLUDE_DIRS}")
message("-- CUDA driver library: ${CUDA_LIB}")
target_include_directories(libocca PRIVATE ${CUDA_INCLUDE_DIRS})
target_link_libraries(libocca PRIVATE ${CUDA_LIB})
else (CUDA_FOUND)
set(OCCA_CUDA_ENABLED 0)
endif(CUDA_FOUND)
endif(ENABLE_CUDA)
##############################
# OpenCL
##############################
if (ENABLE_OPENCL)
#Look in some default places for OpenCL and set OPENCL_ROOT
# Search in user specified path first
find_path(
OPENCL_ROOT
NAMES include/CL/cl.h
PATHS
ENV OPENCL_PATH
DOC "OPENCL root location"
NO_DEFAULT_PATH
)
# Now search in default path
find_path(
OPENCL_ROOT
NAMES include/CL/cl.h
PATHS
/usr/
/opt/rocm/opencl
/usr/local/cuda
DOC "OPENCL root location"
)
#Trick cmake's default OpenCL module to look in our directory
set(ENV{AMDAPPSDKROOT} ${OPENCL_ROOT})
find_package(OpenCL)
if (OpenCL_FOUND)
set(OCCA_OPENCL_ENABLED 1)
message("-- OpenCL include dirs: ${OpenCL_INCLUDE_DIRS}")
message("-- OpenCL libraries: ${OpenCL_LIBRARIES}")
target_include_directories(libocca PRIVATE ${OpenCL_INCLUDE_DIRS})
target_link_libraries(libocca PRIVATE ${OpenCL_LIBRARIES})
else (OpenCL_FOUND)
set(OCCA_OPENCL_ENABLED 0)
endif(OpenCL_FOUND)
endif(ENABLE_OPENCL)
##############################
# HIP
##############################
if (ENABLE_HIP)
find_package(HIP)
if (HIP_FOUND)
set(OCCA_HIP_ENABLED 1)
message("-- HIP version: ${HIP_VERSION_STRING}")
message("-- HIP platform: ${HIP_PLATFORM}")
message("-- HIP include dirs: ${HIP_INCLUDE_DIRS}")
message("-- HIP libraries: ${HIP_LIBRARIES}")
target_compile_definitions(libocca PRIVATE -D${HIP_RUNTIME_DEFINE})
target_include_directories(libocca PRIVATE ${HIP_INCLUDE_DIRS})
target_link_libraries(libocca PRIVATE ${HIP_LIBRARIES})
else (HIP_FOUND)
set(OCCA_HIP_ENABLED 0)
endif(HIP_FOUND)
endif(ENABLE_HIP)
##############################
# Metal
##############################
if (ENABLE_METAL AND APPLE)
find_library(METAL_LIBRARY Metal)
find_library(CORE_SERVICES CoreServices)
find_library(APP_KIT AppKit)
if (METAL_LIBRARY AND CORE_SERVICES AND APP_KIT)
set(OCCA_METAL_ENABLED 1)
else()
set(OCCA_METAL_ENABLED 0)
endif()
endif()
##############################
# MPI
##############################
if (ENABLE_MPI)
find_package(MPI)
if (MPI_FOUND)
set(OCCA_MPI_ENABLED 1)
message("-- MPI include dirs: ${MPI_CXX_INCLUDE_DIRS}")
message("-- MPI libraries: ${MPI_CXX_LIBRARIES}")
message("-- MPI link flags: ${MPI_CXX_LINK_FLAGS}")
message("-- MPI executable: ${MPIEXEC_EXECUTABLE}")
message("-- MPI numproc flag: ${MPIEXEC_NUMPROC_FLAG}")
target_include_directories(libocca PUBLIC ${MPI_CXX_INCLUDE_DIRS})
target_link_libraries(libocca PUBLIC ${MPI_CXX_LIBRARIES})
else(MPI_FOUND)
set(OCCA_MPI_ENABLED 0)
endif(MPI_FOUND)
endif(ENABLE_MPI)
#Generate CompiledDefines from libraries we found
configure_file(scripts/compiledDefinesTemplate.hpp.in ${OCCA_BUILD_DIR}/include/occa/defines/compiledDefines.hpp)
install(FILES ${OCCA_BUILD_DIR}/include/occa/defines/compiledDefines.hpp DESTINATION include/occa/defines)
#Find source files
file(GLOB_RECURSE OCCA_SRC_cpp RELATIVE ${OCCA_SOURCE_DIR} "src/*.cpp")
list(REMOVE_ITEM OCCA_SRC_cpp src/core/kernelOperators.cpp src/tools/runFunction.cpp)
if (OCCA_OPENMP_ENABLED)
set_source_files_properties(${OCCA_SRC_cpp} PROPERTIES COMPILE_FLAGS ${OpenMP_CXX_FLAGS})
endif()
if (ENABLE_FORTRAN)
file(GLOB_RECURSE OCCA_SRC_Fortran RELATIVE ${OCCA_SOURCE_DIR} "src/*.f90")
if (OCCA_OPENMP_ENABLED)
set_source_files_properties(${OCCA_SRC_Fortran} PROPERTIES COMPILE_FLAGS ${OpenMP_Fortran_FLAGS})
endif()
install (CODE "file(GLOB public-modules ${CMAKE_Fortran_MODULE_DIRECTORY}/*.mod)\n
file(INSTALL DESTINATION ${CMAKE_INSTALL_PREFIX}/include TYPE FILE FILES \${public-modules})")
set_target_properties(libocca PROPERTIES LINKER_LANGUAGE C)
endif()
if (OCCA_METAL_ENABLED)
file(GLOB_RECURSE OCCA_SRC_metal RELATIVE ${OCCA_SOURCE_DIR} "src/*.mm")
endif()
set(OCCA_SRC ${OCCA_SRC_cpp} ${OCCA_SRC_Fortran} ${OCCA_SRC_metal})
target_sources(libocca PRIVATE ${OCCA_SRC})
install(TARGETS libocca DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
if (ENABLE_TESTS)
include(CTest)
add_subdirectory(tests)
endif(ENABLE_TESTS)
if (ENABLE_EXAMPLES)
add_subdirectory(examples)
endif(ENABLE_EXAMPLES)
if (ENABLE_UTILITY)
add_subdirectory(bin)
endif(ENABLE_UTILITY)