-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
executable file
·326 lines (256 loc) · 9.66 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
######################################################################
#
# CMakeLists.txt for GPTune
#
######################################################################
# Required version
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
# SET(CMAKE_INSTALL_PREFIX < install_path >)
# Project version numbers
project(gptuneclcm C CXX Fortran)
set(VERSION_MAJOR "3")
set(VERSION_MINOR "0")
set(VERSION_BugFix "0")
set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BugFix})
######################################################################
#
# Load all macros:
#
FILE(GLOB _macro_files "cmake/Macros/*.cmake")
MESSAGE(STATUS "Include ${CMAKE_SOURCE_DIR}/cmake/setup_external_macros.cmake")
FOREACH(_file ${_macro_files})
MESSAGE(STATUS "Include ${_file}")
INCLUDE(${_file})
ENDFOREACH()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/scikit-build/skbuild/resources/cmake/")
######################################################################
#
# Usual initialization stuff
#
######################################################################
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) ## ????
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
#---- For shared library
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# the RPATH to be used when installing
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
#----
if (BUILD_SHARED_LIBS)
message("-- gptuneclcm will be built as a shared library.")
else()
message("-- gptuneclcm will be built as a static library.")
endif()
enable_language (C)
enable_language (CXX)
enable_language (Fortran)
set(CMAKE_C_STANDARD 11)
if (XSDK_ENABLE_Fortran)
enable_language (Fortran)
set(NOFORTRAN FALSE)
endif()
set(gptuneclcm_VERSION "${PROJECT_VERSION}")
set(gptuneclcm_REV "${PROJECT_REV}")
# if (NOT CMAKE_INSTALL_PREFIX)
# set(CMAKE_INSTALL_PREFIX /usr/local)
# endif()
######################################################################
#
# Add compiler-specific compiler flags
#
######################################################################
set(CMAKE_C_FLAGS "-std=c++11 ${CMAKE_C_FLAGS}")
include(CheckCCompilerFlag)
check_c_compiler_flag("-qopt-matmul" qoptmatmul)
if (qoptmatmul)
set(CMAKE_C_FLAGS "-qopt-matmul ${CMAKE_C_FLAGS}")
endif()
######################################################################
#
# Find packages
#
######################################################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_SOURCE_DIR}/cmake/Modules/")
#---------------------- Additional Fortran linker library ---------
SET(_fortran_libs ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
FOREACH(_lib ${_fortran_libs})
# FIND_SYSTEM_LIBRARY(${_lib}_LIBRARY NAMES ${_lib})
set(EXTRA_LIB "-l${_lib} ${EXTRA_LIB}")
ENDFOREACH()
# find_package(PythonExtensions REQUIRED)
#--------------------- OpenMP ---------------------
find_package(OpenMP)
## include(FindOpenMP) # Strumpack uses this
if(OPENMP_FORTRAN_FOUND)
set(CMAKE_Fortran_FLAGS "${OpenMP_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS}")
set(OpenMP_Fortran_FLAGS_EXPORT "${OpenMP_Fortran_FLAGS}")
set(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES} ${OpenMP_Fortran_FLAGS}")
endif()
if(OPENMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
set(OpenMP_CXX_FLAGS_EXPORT "${OpenMP_CXX_FLAGS}")
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${OpenMP_CXX_FLAGS}")
endif()
# #--------------------- BLAS ---------------------
if(TPL_BLAS_LIBRARIES)
set(BLAS_FOUND TRUE)
else()
find_package(BLAS)
if(BLAS_FOUND)
set(TPL_BLAS_LIBRARIES "${BLAS_LIBRARIES}" CACHE FILEPATH
"Set from FindBLAS.cmake BLAS_LIBRARIES." FORCE)
endif()
endif()
if(BLAS_FOUND)
message("-- Using TPL_BLAS_LIBRARIES='${TPL_BLAS_LIBRARIES}'")
set(BLAS_LIB ${TPL_BLAS_LIBRARIES})
# fix up BLAS library name
string (REPLACE ";" " " BLAS_LIB_STR "${BLAS_LIB}")
set(BLAS_LIB_EXPORT ${BLAS_LIB_STR})
endif()
# #--------------------- LAPACK ---------------------
if(TPL_LAPACK_LIBRARIES)
set(LAPACK_FOUND TRUE)
else()
find_package(LAPACK)
if(LAPACK_FOUND)
set(TPL_LAPACK_LIBRARIES "${LAPACK_LIBRARIES}" CACHE FILEPATH
"Set from FindLAPACK.cmake LAPACK_LIBRARIES." FORCE)
endif()
endif()
if(LAPACK_FOUND)
message("-- Using TPL_LAPACK_LIBRARIES='${TPL_LAPACK_LIBRARIES}'")
set(LAPACK_LIB ${TPL_LAPACK_LIBRARIES})
# fix up LAPACK library name
string (REPLACE ";" " " LAPACK_LIB_STR "${LAPACK_LIB}")
set(LAPACK_LIB_EXPORT ${LAPACK_LIB_STR})
endif()
# #--------------------- SCALAPACK ---------------------
if(TPL_SCALAPACK_LIBRARIES)
set(SCALAPACK_FOUND TRUE)
else()
find_package(SCALAPACK)
if(SCALAPACK_FOUND)
set(TPL_SCALAPACK_LIBRARIES "${SCALAPACK_LIBRARIES}" CACHE FILEPATH
"Set from FindSCALAPACK.cmake SCALAPACK_LIBRARIES." FORCE)
endif()
endif()
if(SCALAPACK_FOUND)
message("-- Using TPL_SCALAPACK_LIBRARIES='${TPL_SCALAPACK_LIBRARIES}'")
set(SCALAPACK_LIB ${TPL_SCALAPACK_LIBRARIES})
# fix up LAPACK library name
string (REPLACE ";" " " SCALAPACK_LIB_STR "${SCALAPACK_LIB}")
set(SCALAPACK_LIB_EXPORT ${SCALAPACK_LIB_STR})
endif()
#--------------------- MPI ---------------------
find_package(MPI)
if(MPI_C_FOUND )
set(CMAKE_C_FLAGS "${MPI_C_COMPILE_FLAGS} ${CMAKE_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_C_LINK_FLAGS}" )
endif()
if(MPI_CXX_FOUND )
set(CMAKE_CXX_FLAGS "${MPI_CXX_COMPILE_FLAGS} ${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_CXX_LINK_FLAGS}" )
endif()
# added a few compiler flags for Fortran
include(CheckFortranCompilerFlag)
check_fortran_compiler_flag("-ffree-line-length-none" COMPILER_GNU)
if (COMPILER_GNU)
set(CMAKE_Fortran_FLAGS "-fno-range-check -ffree-line-length-none -ffixed-line-length-none -fimplicit-none -lpthread ${CMAKE_Fortran_FLAGS}")
check_fortran_compiler_flag("-fallow-argument-mismatch" GNU10)
if (GNU10)
set(CMAKE_Fortran_FLAGS "-fallow-argument-mismatch ${CMAKE_Fortran_FLAGS}")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_Fortran_FLAGS "-fno-range-check -fbacktrace -fbounds-check -Wconversion ${CMAKE_Fortran_FLAGS}")
endif()
endif()
# python.
set(Python3_FIND_STRATEGY LOCATION) # Prioritize finding Python based on its location
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
message(STATUS "Python3 interpreter: ${Python3_EXECUTABLE}")
message(STATUS "Python3 installation directory: ${Python3_SITEARCH}")
set(GPTUNE_INSTALL_PATH "" CACHE STRING "GPTune module installation path")
mark_as_advanced(GPTUNE_INSTALL_PATH)
# Set python files
set(GPTUNE_PYTHON_FILES
GPTune/__init__.py
GPTune/__version__.py
GPTune/callhpbandster.py
GPTune/callopentuner.py
GPTune/computer.py
GPTune/database.py
GPTune/data.py
GPTune/gptune.py
GPTune/lcm.py
GPTune/model.py
GPTune/options.py
GPTune/problem.py
GPTune/sample.py
GPTune/search.py
)
# Set C source directory
set(SOURCE_DIR "gptuneclcm")
# Tell CMake that headers are also in SOURCE_DIR
include_directories(${SOURCE_DIR})
set(headers "${SOURCE_DIR}/lcm.h")
set(sources "${SOURCE_DIR}/lcm.c")
add_library(_gptuneclcm ${sources} ${HEADERS})
target_link_libraries(_gptuneclcm
${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES} ${BLAS_LIB} ${LAPACK_LIB} ${SCALAPACK_LIB} m)
set_target_properties(_gptuneclcm PROPERTIES
VERSION ${PROJECT_VERSION} SOVERSION ${VERSION_MAJOR}
)
# Set Fortran source directory
set(SOURCE_DIR_SCALAPACK_EX "${CMAKE_SOURCE_DIR}/examples/Scalapack-PDGEQRF/scalapack-driver/src/")
include_directories(${SOURCE_DIR_SCALAPACK_EX})
#set(sources_scalapack_example "${SOURCE_DIR_SCALAPACK_EX}/pdqrdriver.f ${SOURCE_DIR_SCALAPACK_EX}/pdqrinfo.f")
set(sources_scalapack_example
${SOURCE_DIR_SCALAPACK_EX}/pdqrdriver.f
${SOURCE_DIR_SCALAPACK_EX}/pdqrinfo.f
${SOURCE_DIR_SCALAPACK_EX}/pdmatgen.f
${SOURCE_DIR_SCALAPACK_EX}/pdgeqrrv.f
${SOURCE_DIR_SCALAPACK_EX}/pdlafchk.f
${SOURCE_DIR_SCALAPACK_EX}/pdgeqlrv.f
${SOURCE_DIR_SCALAPACK_EX}/pdgerqrv.f
${SOURCE_DIR_SCALAPACK_EX}/pdtzrzrv.f
${SOURCE_DIR_SCALAPACK_EX}/pdgelqrv.f
${SOURCE_DIR_SCALAPACK_EX}/pmatgeninc.f
)
add_executable(pdqrdriver ${sources_scalapack_example})
target_link_libraries(pdqrdriver ${MPI_Fortran_LIBRARIES} ${BLAS_LIB} ${LAPACK_LIB} ${SCALAPACK_LIB} m)
# # Generate Python module
# add_subdirectory(lib/pybind11)
# pybind11_add_module(GPTune ${sources} ${headers} "${SOURCE_DIR}/bindings.cpp")
# python_extension_module(_gptuneclcm)
# Installation setup.
if(GPTUNE_INSTALL_PATH STREQUAL "")
message(STATUS "GPTune will be installed in the default location: ${Python3_SITEARCH}")
set(_GPTUNE_INSTALL_DIR "${Python3_SITEARCH}/GPTune")
else()
message(STATUS "GPTune will be installed in the custom location: ${GPTUNE_INSTALL_PATH}")
set(_GPTUNE_INSTALL_DIR "${GPTUNE_INSTALL_PATH}/GPTune")
endif()
# Define GNU standard installation directories
include(GNUInstallDirs)
install(TARGETS _gptuneclcm LIBRARY DESTINATION ${_GPTUNE_INSTALL_DIR}
# DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(TARGETS pdqrdriver RUNTIME DESTINATION ${_GPTUNE_INSTALL_DIR}
# DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES ${headers}
DESTINATION ${_GPTUNE_INSTALL_DIR}
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Install the Python files.
install(FILES ${GPTUNE_PYTHON_FILES}
DESTINATION ${_GPTUNE_INSTALL_DIR})
unset(_GPTUNE_INSTALL_DIR)