forked from alpaka-group/cupla
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cuplaConfig.cmake
307 lines (269 loc) · 11.7 KB
/
cuplaConfig.cmake
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
#
# Copyright 2016 Rene Widera, Benjamin Worpitz
#
# This file is part of cupla.
#
# cupla 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 3 of the License, or
# (at your option) any later version.
#
# cupla 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 cupla.
# If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
# Required cmake version.
################################################################################
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
################################################################################
# cupla
################################################################################
# Return values.
unset(cupla_FOUND)
unset(cupla_VERSION)
unset(cupla_COMPILE_OPTIONS)
unset(cupla_COMPILE_DEFINITIONS)
unset(cupla_DEFINITIONS)
unset(cupla_INCLUDE_DIR)
unset(cupla_INCLUDE_DIRS)
unset(cupla_SOURCE_DIR)
unset(cupla_SOURCE_DIRS)
unset(cupla_LIBRARY)
unset(cupla_LIBRARIES)
unset(cupla_SOURCE_FILES)
# Internal usage.
unset(_cupla_FOUND)
unset(_cupla_VERSION)
unset(_cupla_COMPILE_OPTIONS_PUBLIC)
unset(_cupla_COMPILE_DEFINITIONS_PUBLIC)
unset(_cupla_INCLUDE_DIR)
unset(_cupla_INCLUDE_DIRECTORIES_PUBLIC)
unset(_cupla_SOURCE_DIR)
unset(_cupla_SOURCE_DIRECTORIES_PUBLIC)
unset(_cupla_LINK_LIBRARIES_PUBLIC)
unset(_cupla_FILES_HEADER)
unset(_cupla_FILES_SOURCE)
unset(_cupla_FILES_OTHER)
################################################################################
# Directory of this file.
################################################################################
set(_cupla_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
# Normalize the path (e.g. remove ../)
get_filename_component(_cupla_ROOT_DIR "${_cupla_ROOT_DIR}" ABSOLUTE)
################################################################################
# Set found to true initially and set it on false if a required dependency is missing.
################################################################################
set(_cupla_FOUND TRUE)
################################################################################
# Common.
################################################################################
# own modules for find_packages
list(APPEND CMAKE_MODULE_PATH "${_cupla_ROOT_DIR}")
#list(APPEND CMAKE_MODULE_PATH "$ENV{ALPAKA_ROOT}")
################################################################################
# Find alpaka
# NOTE: Do this first, because it declares `list_add_prefix` and `append_recursive_files_add_to_src_group` used later on.
################################################################################
# disable all accelerators by default
OPTION(ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE "Enable the serial CPU accelerator" OFF)
OPTION(ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE "Enable the threads CPU block thread accelerator" OFF)
OPTION(ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE "Enable the fibers CPU block thread accelerator" OFF)
OPTION(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE "Enable the OpenMP 2.0 CPU grid block accelerator" OFF)
OPTION(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE "Enable the OpenMP 2.0 CPU block thread accelerator" OFF)
OPTION(ALPAKA_ACC_CPU_BT_OMP4_ENABLE "Enable the OpenMP 4.0 CPU block and block thread accelerator" OFF)
OPTION(ALPAKA_ACC_GPU_CUDA_ENABLE "Enable the CUDA GPU accelerator" OFF)
if("$ENV{ALPAKA_ROOT}" STREQUAL "")
if(NOT EXISTS "${_cupla_ROOT_DIR}/alpaka/Findalpaka.cmake")
# Init the sub molules
execute_process (COMMAND git submodule init WORKING_DIRECTORY ${_cupla_ROOT_DIR})
# Update the sub modules
execute_process (COMMAND git submodule update WORKING_DIRECTORY ${_cupla_ROOT_DIR})
endif()
endif()
find_package(alpaka HINTS $ENV{ALPAKA_ROOT} "${_cupla_ROOT_DIR}/alpaka")
if(NOT alpaka_FOUND)
message(WARNING "Required cupla dependency alpaka could not be found!")
set(_cupla_FOUND FALSE)
else()
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC ${alpaka_COMPILE_OPTIONS})
list(APPEND _cupla_COMPILE_DEFINITIONS_PUBLIC ${alpaka_COMPILE_DEFINITIONS})
list(APPEND _cupla_INCLUDE_DIRECTORIES_PUBLIC ${alpaka_INCLUDE_DIRS})
list(APPEND _cupla_LINK_LIBRARIES_PUBLIC ${alpaka_LIBRARIES})
endif()
################################################################################
# Compiler settings.
################################################################################
if(MSVC)
# Empty append to define it if it does not already exist.
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC)
else()
# GNU
if(CMAKE_COMPILER_IS_GNUCXX)
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wall")
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wextra")
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-unknown-pragmas")
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-unused-parameter")
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-unused-local-typedefs")
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-attributes")
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-reorder")
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-sign-compare")
# ICC
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wall")
# PGI
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "PGI")
list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Minform=inform")
endif()
endif()
################################################################################
# cupla.
################################################################################
set(_cupla_INCLUDE_DIR "${_cupla_ROOT_DIR}/include")
list(APPEND _cupla_INCLUDE_DIRECTORIES_PUBLIC ${_cupla_INCLUDE_DIR})
set(_cupla_SUFFIXED_INCLUDE_DIR "${_cupla_INCLUDE_DIR}")
set(_cupla_SOURCE_DIR "${_cupla_ROOT_DIR}/src")
list(APPEND _cupla_SOURCE_DIRECTORIES_PUBLIC ${_cupla_SOURCE_DIR})
set(_cupla_SUFFIXED_SOURCE_DIR "${_cupla_SOURCE_DIR}")
set(_cupla_LINK_LIBRARY)
list(APPEND _cupla_LINK_LIBRARIES_PUBLIC ${_cupla_LINK_LIBRARY})
set(_cupla_FILES_OTHER "${_cupla_ROOT_DIR}/Findcupla.cmake" "${_cupla_ROOT_DIR}/cuplaConfig.cmake")
# Add all the include files in all recursive subdirectories and group them accordingly.
append_recursive_files_add_to_src_group("${_cupla_SUFFIXED_INCLUDE_DIR}" "${_cupla_SUFFIXED_INCLUDE_DIR}" "hpp" _cupla_FILES_HEADER)
append_recursive_files_add_to_src_group("${_cupla_SUFFIXED_INCLUDE_DIR}" "${_cupla_SUFFIXED_INCLUDE_DIR}" "h" _cupla_FILES_HEADER)
append_recursive_files_add_to_src_group("${_cupla_SUFFIXED_SOURCE_DIR}" "${_cupla_SUFFIXED_SOURCE_DIR}" "cpp" _cupla_FILES_SOURCE)
################################################################################
# Target.
################################################################################
if(NOT TARGET cupla)
add_library(
"cupla"
${_cupla_FILES_HEADER} ${_cupla_FILES_OTHER})
# Even if there are no sources CMAKE has to know the language.
set_target_properties("cupla" PROPERTIES LINKER_LANGUAGE CXX)
# Compile options.
message(STATUS "_cupla_COMPILE_OPTIONS_PUBLIC: ${_cupla_COMPILE_OPTIONS_PUBLIC}")
list(
LENGTH
_cupla_COMPILE_optionS_PUBLIC
_cupla_COMPILE_optionS_PUBLIC_LENGTH)
if("${_cupla_COMPILE_optionS_PUBLIC_LENGTH}")
TARGET_COMPILE_optionS(
"cupla"
PUBLIC ${_cupla_COMPILE_optionS_PUBLIC})
endif()
# Compile definitions.
message(STATUS "_cupla_COMPILE_DEFINITIONS_PUBLIC: ${_cupla_COMPILE_DEFINITIONS_PUBLIC}")
list(
LENGTH
_cupla_COMPILE_DEFINITIONS_PUBLIC
_cupla_COMPILE_DEFINITIONS_PUBLIC_LENGTH)
if("${_cupla_COMPILE_DEFINITIONS_PUBLIC_LENGTH}")
TARGET_COMPILE_DEFINITIONS(
"cupla"
PUBLIC ${_cupla_COMPILE_DEFINITIONS_PUBLIC})
endif()
# Include directories.
message(STATUS "_cupla_INCLUDE_DIRECTORIES_PUBLIC: ${_cupla_INCLUDE_DIRECTORIES_PUBLIC}")
list(
LENGTH
_cupla_INCLUDE_DIRECTORIES_PUBLIC
_cupla_INCLUDE_DIRECTORIES_PUBLIC_LENGTH)
if("${_cupla_INCLUDE_DIRECTORIES_PUBLIC_LENGTH}")
TARGET_INCLUDE_DIRECTORIES(
"cupla"
PUBLIC ${_cupla_INCLUDE_DIRECTORIES_PUBLIC})
endif()
# Link libraries.
message(STATUS "_cupla_LINK_LIBRARIES_PUBLIC: ${_cupla_LINK_LIBRARIES_PUBLIC}")
list(
LENGTH
_cupla_LINK_LIBRARIES_PUBLIC
_cupla_LINK_LIBRARIES_PUBLIC_LENGTH)
if("${_cupla_LINK_LIBRARIES_PUBLIC_LENGTH}")
target_link_libraries(
"cupla"
PUBLIC alpaka ${_cupla_LINK_LIBRARIES_PUBLIC})
endif()
endif()
################################################################################
# Find cupla version.
################################################################################
# FIXME: Add a version.hpp
set(_cupla_VERSION "0.1.0")
################################################################################
# Set return values.
################################################################################
set(cupla_VERSION ${_cupla_VERSION})
set(cupla_COMPILE_OPTIONS ${_cupla_COMPILE_OPTIONS_PUBLIC})
set(cupla_COMPILE_DEFINITIONS ${_cupla_COMPILE_DEFINITIONS_PUBLIC})
# Add '-D' to the definitions
set(cupla_DEFINITIONS ${_cupla_COMPILE_DEFINITIONS_PUBLIC})
list_add_prefix("-D" cupla_DEFINITIONS)
# Add the compile options to the definitions.
list(APPEND cupla_DEFINITIONS ${_cupla_COMPILE_OPTIONS_PUBLIC})
set(cupla_INCLUDE_DIR ${_cupla_INCLUDE_DIR})
set(cupla_INCLUDE_DIRS ${_cupla_INCLUDE_DIRECTORIES_PUBLIC})
set(cupla_LIBRARY ${_cupla_LINK_LIBRARY})
set(cupla_LIBRARIES ${_cupla_LINK_LIBRARIES_PUBLIC})
set(cupla_SOURCE_FILES ${_cupla_FILES_SOURCE})
# Unset already set variables if not found.
if(NOT _cupla_FOUND)
unset(cupla_FOUND)
unset(cupla_VERSION)
unset(cupla_COMPILE_OPTIONS)
unset(cupla_COMPILE_DEFINITIONS)
unset(cupla_DEFINITIONS)
unset(cupla_INCLUDE_DIR)
unset(cupla_INCLUDE_DIRS)
unset(cupla_SOURCE_DIR)
unset(cupla_SOURCE_DIRS)
unset(cupla_LIBRARY)
unset(cupla_LIBRARIES)
unset(cupla_SOURCE_FILES)
unset(_cupla_FOUND)
unset(_cupla_COMPILE_OPTIONS_PUBLIC)
unset(_cupla_COMPILE_DEFINITIONS_PUBLIC)
unset(_cupla_INCLUDE_DIR)
unset(_cupla_INCLUDE_DIRECTORIES_PUBLIC)
unset(_cupla_SOURCE_DIR)
unset(_cupla_SOURCE_DIRECTORIES_PUBLIC)
unset(_cupla_LINK_LIBRARY)
unset(_cupla_LINK_LIBRARIES_PUBLIC)
unset(_cupla_FILES_HEADER)
unset(_cupla_FILES_SOURCE)
unset(_cupla_FILES_OTHER)
unset(_cupla_VERSION)
else()
# Make internal variables advanced options in the GUI.
MARK_AS_ADVANCED(
cupla_INCLUDE_DIR
cupla_LIBRARY
_cupla_FOUND
_cupla_COMPILE_OPTIONS_PUBLIC
_cupla_COMPILE_DEFINITIONS_PUBLIC
_cupla_INCLUDE_DIR
_cupla_INCLUDE_DIRECTORIES_PUBLIC
_cupla_LINK_LIBRARY
_cupla_LINK_LIBRARIES_PUBLIC
_cupla_FILES_HEADER
_cupla_FILES_SOURCE
_cupla_FILES_OTHER
_cupla_VERSION)
endif()
###############################################################################
# FindPackage options
###############################################################################
# Handles the REQUIRED, QUIET and version-related arguments for find_package.
# NOTE: We do not check for cupla_LIBRARIES and cupla_DEFINITIONS because they can be empty.
INCLUDE(FindPackageHandleStandardArgs)
find_package_HANDLE_STANDARD_ARGS(
"cupla"
FOUND_VAR cupla_FOUND
REQUIRED_VARS cupla_INCLUDE_DIR
VERSION_VAR cupla_VERSION)