-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
277 lines (228 loc) · 11.5 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
# CMakeLists.txt
#
# This file is part of NEST GPU.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST GPU is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST GPU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST GPU. If not, see <http://www.gnu.org/licenses/>
cmake_minimum_required( VERSION 3.17 )
# add cmake modules: for all `include(...)` first look here
list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake )
project( nestgpu LANGUAGES CUDA CXX C )
set( NEST_GPU_USER_EMAIL "[email protected]" )
include( ColorMessages )
# check if the given CMAKE_INSTALL_PREFIX is not empty
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "")
printError("CMAKE_INSTALL_PREFIX cannot be an empty string")
endif()
# handle relative installation prefixes
if( NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX})
# convert relative path to absolute path
get_filename_component(absPath ${CMAKE_INSTALL_PREFIX} ABSOLUTE BASE_DIR ${CMAKE_BINARY_DIR})
set(CMAKE_INSTALL_PREFIX ${absPath})
printInfo("Relative CMAKE_INSTALL_PREFIX has been converted to absolute path ${CMAKE_INSTALL_PREFIX}")
endif()
################################################################################
################## All User Defined options ##################
################################################################################
# select parallelization scheme
set( with-gpu-arch "80" CACHE STRING "Specify the GPU compute architecture [default=80]." )
set( with-mpi ON CACHE STRING "Build with MPI parallelization [default=ON]." )
# external libraries
# libltdl not yet needed but will be useful for NESTML
set( with-ltdl OFF CACHE STRING "Build with ltdl library [default=OFF]. To set a specific ltdl, give the install path. NEST GPU uses ltdl for dynamic loading of external user modules." )
# compiler options; explicit compiler flags can be given.
set( with-optimize ON CACHE STRING "Enable user defined optimizations [default=ON (uses '-O3')]. When OFF, no '-O' flag is passed to the compiler. Separate multiple flags by ';'." )
set( with-warning ON CACHE STRING "Enable user defined warnings [default=ON (uses '-Wall')]. Separate multiple flags by ';'." )
set( with-debug OFF CACHE STRING "Enable user defined debug flags [default=OFF]. When ON, '-g' is used. Separate multiple flags by ';'." )
# CUDA options
set( with-cpp-std OFF CACHE STRING "C++ standard to use for compilation [default=OFF]." )
set( with-libraries OFF CACHE STRING "Link additional libraries [default=OFF]. Give full path. Separate multiple libraries by ';'." )
set( with-includes OFF CACHE STRING "Add additional include paths [default=OFF]. Give full path without '-I'. Separate multiple include paths by ';'." )
set( with-defines OFF CACHE STRING "Additional defines, e.g. '-DXYZ=1' [default=OFF]. Separate multiple defines by ';'." )
set( with-max-rreg-count "55" CACHE STRING "Set a maximum amount of register used when compiling [default=55]. Separate multiple flags by ';'." )
set( with-ptxas-options OFF CACHE STRING "Options for ptxas compiling [default=OFF]. Separate multiple flags by ';'." )
# generic build configuration
set( with-version-suffix OFF CACHE STRING "Set a user defined version suffix [default='']." )
################################################################################
################## Project Directory variables ##################
################################################################################
# In general use the CMAKE_INSTALL_<dir> and CMAKE_INSTALL_FULL_<dir> vars from
# GNUInstallDirs (included after calling nest_process_with_python()), but the
# CMAKE_INSTALL_DATADIR is usually just CMAKE_INSTALL_DATAROOTDIR
# and we want it to be CMAKE_INSTALL_DATAROOTDIR/PROJECT_NAME
set( CMAKE_INSTALL_DATADIR "share/${PROJECT_NAME}" CACHE STRING "Relative directory, where NEST GPU installs its data (share/nest)" )
################################################################################
################## Find utility programs (#TODO adapt for later PR) #########
################################################################################
# needed for pynest test suite
#if ( ${with-python} STREQUAL "ON" )
# find_program( NOSETESTS NAMES nosetests )
#endif ()
# needed for target doc and fulldoc
#find_package( Doxygen )
#find_program( SED NAMES sed gsed )
################################################################################
################## Load includes ##################
################################################################################
# This include checks the symbols, etc.
include( CheckIncludesSymbols )
# These includes publish function names.
include( ProcessOptions )
include( ConfigureSummary )
include( GetTriple )
# get triples arch-vendor-os
get_host_triple( NEST_HOST_TRIPLE NEST_HOST_ARCH NEST_HOST_VENDOR NEST_HOST_OS )
get_target_triple( NEST_TARGET_TRIPLE NEST_TARGET_ARCH NEST_TARGET_VENDOR NEST_TARGET_OS )
include( GNUInstallDirs )
nest_post_process_with_python()
nest_process_with_mpi()
nestgpu_process_cuda_arch()
nest_process_with_libltdl()
nest_process_with_std()
nest_process_with_libraries()
nest_process_with_includes()
nest_process_with_defines()
nestgpu_process_with_max_rreg_count()
nestgpu_process_with_ptxas_options()
# IMPORTANT: Please try to keep these two function calls to be the last functions to call in this Process step.
# Adding wrong keywords to the "-Dwith-optmize" flag might cause wrong errors, and therefore to avoid that
# the step for processing the optmization phase and the debug phase must be the last steps.
nestgpu_pre_process_compile_flags()
nest_process_with_optimize()
nest_process_with_debug()
nest_process_with_warning()
nestgpu_post_process_compile_flags()
nest_process_version_suffix()
################################################################################
################## Create version string ##################
################################################################################
include( VersionInfo )
get_version_info()
printInfo("-- NEST GPU version: ${NEST_GPU_VERSION_STRING}")
################################################################################
################## Enable Testing Targets (#TODO adapt for later PR) #########
################################################################################
#enable_testing()
#set( TEST_OPTS "--with-python=${PYTHON}" )
#add_custom_target( installcheck
# COMMAND ${CMAKE_COMMAND} -E env
# ${CMAKE_INSTALL_FULL_DATADIR}/testsuite/do_tests.sh
# --prefix=${CMAKE_INSTALL_PREFIX}
# --report-dir="${PROJECT_BINARY_DIR}/reports"
# ${TEST_OPTS}
# WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
# COMMENT "Executing NEST's testsuite..."
#)
# N.B. to ensure "make install" is always run before "make installcheck", we
# would ideally like to add:
# add_dependencies( installcheck install )
# However, an issue in CMake at time of writing (May 2020, see
# https://gitlab.kitware.com/cmake/cmake/-/issues/8438) precludes us from doing
# so.
################################################################################
################## Define Subdirectories here ##################
################################################################################
#add_subdirectory( doc )
add_subdirectory( bin )
add_subdirectory( src )
add_subdirectory( libnestutil )
add_subdirectory( pythonlib )
################################################################################
################## Summary of flags ##################
################################################################################
# used in nest-config
# all compiler flags
if ( NOT CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "None" )
set( ALL_CFLAGS "${CMAKE_C_FLAGS}" )
set( ALL_CXXFLAGS "${CMAKE_CXX_FLAGS}" )
set( ALL_CUDA_FLAGS "${CMAKE_CUDA_FLAGS}" )
elseif ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug" )
set( ALL_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}" )
set( ALL_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}" )
set( ALL_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CMAKE_CUDA_FLAGS_DEBUG}" )
elseif ( ${CMAKE_BUILD_TYPE} STREQUAL "Release" )
set( ALL_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}" )
set( ALL_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}" )
set( ALL_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CMAKE_CUDA_FLAGS_RELEASE}" )
elseif ( ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo" )
set( ALL_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELWITHDEBINFO}" )
set( ALL_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" )
set( ALL_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CMAKE_CUDA_FLAGS_RELWITHDEBINFO}" )
elseif ( ${CMAKE_BUILD_TYPE} STREQUAL "MinSizeRel" )
set( ALL_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_MINSIZEREL}" )
set( ALL_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_MINSIZEREL}" )
set( ALL_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CMAKE_CUDA_FLAGS_MINSIZEREL}" )
else ()
printError( "Unknown build type: '${CMAKE_BUILD_TYPE}'" )
endif ()
if ( with-defines )
foreach ( def ${with-defines} )
set( ALL_CFLAGS "${def} ${ALL_CFLAGS}" )
set( ALL_CXXFLAGS "${def} ${ALL_CXXFLAGS}" )
set( ALL_CUDA_FLAGS "${def} ${ALL_CUDA_FLAGS}" )
endforeach ()
endif ()
# libraries required to link extension modules
set( MODULE_LINK_LIBS
"-lnestutil"
"-lsrc" # to be renamed to -lnestgpukernel
"-lcuda"
"-lcudart"
"-lcurand"
"${MPI_CXX_LIBRARIES}"
"${LTDL_LIBRARIES}" )
if ( with-libraries )
set( MODULE_LINK_LIBS "${MODULE_LINK_LIBS};${with-libraries}" )
endif ()
string( REPLACE ";" " " MODULE_LINK_LIBS "${MODULE_LINK_LIBS}" )
# libraries requied to link NEST
set( ALL_LIBS
# "-lnestgpu" # main function is inside src folder, in the future we will separate files following NEST structure
${MODULE_LINK_LIBS} )
# all includes
set( ALL_INCLUDES_tmp
"${CMAKE_INSTALL_FULL_INCLUDEDIR}/nestgpu"
"${CUDAToolkit_LIBRARY_DIR}"
"${MPI_CXX_INCLUDE_PATH}"
"${LTDL_INCLUDE_DIRS}" )
set( ALL_INCLUDES "" )
foreach ( INC ${ALL_INCLUDES_tmp} ${with-includes} )
if ( INC AND NOT INC STREQUAL "" )
set( ALL_INCLUDES "${ALL_INCLUDES} -I${INC}" )
endif ()
endforeach ()
set( ALL_INCLUDES "${ALL_INCLUDES}" )
################################################################################
################## File generation here ##################
################################################################################
configure_file(
"${PROJECT_SOURCE_DIR}/libnestutil/config.h.in"
"${PROJECT_BINARY_DIR}/libnestutil/config.h" @ONLY
)
configure_file(
"${PROJECT_SOURCE_DIR}/bin/nestgpu_vars.sh.in"
"${PROJECT_BINARY_DIR}/bin/nestgpu_vars.sh" @ONLY
)
################################################################################
################## Install Extra Files ##################
################################################################################
install( FILES LICENSE README.md
DESTINATION ${CMAKE_INSTALL_DOCDIR}
)
#TODO adapt for later PR
#add_custom_target( install-nodoc
# COMMAND $(MAKE) NEST_INSTALL_NODOC=true install
#)
nest_print_config_summary()