-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
277 lines (244 loc) · 10.8 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
cmake_minimum_required(VERSION 3.2.3)
# directly make an error if in-source build
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed.\n"
"Please create a build directory first and execute cmake configuration from "
"this directory. Example: mkdir build && cd build && cmake ..")
endif()
project(KSVD C Fortran)
find_package(Doxygen)
add_subdirectory("docs")
#########################
### VARIABLES ###########
#########################
set( KSVD_LIBNAME ksvd )
option( KSVD_TESTING "Generates testing binaries" OFF)
option( BUILD_SHARED_LIBS "Generates shared libraries instead of static" OFF)
option( SHARED_NETLIBSCALAPACK "Build NETLIB-SCALAPACK as shared library." ${BUILD_SHARED_LIBS})
option( USE_PARALLEL_BLAS "If possible, prefer parallel blas libraries" ON )
set(EXTRA_LIBS "" CACHE STRING "Additional libraries that may be needed to compile/link" )
# Version
SET( KSVD_VERSION_MAJOR 2 )
SET( KSVD_VERSION_MINOR 0 )
SET( KSVD_VERSION_PATCH 0 )
set( KSVD_VERSION "${KSVD_VERSION_MAJOR}.${KSVD_VERSION_MINOR}.${KSVD_VERSION_PATCH}" )
#execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE KSVD_VERSION_RELEASE )
# Set the RPATH config
# --------------------
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, use the install RPATH
# (automated test will need this)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# the RPATH to be used when installing
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
# Packaging (make package)
SET(CPACK_PACKAGE_VERSION ${KSVD_VERSION})
SET(CPACK_GENERATOR "TGZ")
INCLUDE(CPack)
# This project needs C99 standard to compile properly
# (could have used CMAKE_C_FLAGS instead)
#ADD_DEFINITIONS( -std=c99 )
#set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
link_directories( ${CMAKE_INSTALL_PREFIX}/lib )
include_directories( ${CMAKE_SOURCE_DIR}/include )
## CMAKE MODULES :: ECRC
## REQUIRED FOR TESTS TO LINK LIBRARIES
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/cmake_modules/ecrc/modules" )
find_package(Git REQUIRED)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule init WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE _res_init OUTPUT_QUIET ERROR_QUIET)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE _res_update OUTPUT_QUIET ERROR_QUIET)
if( ${_res_init} GREATER 0 OR ${_res_update} GREATER 0 )
message(FATAL_ERROR "ECRC CMake modules were not found.\n"
"We tried: 'git submodule init && git submodule update' and resulted in error" )
endif()
endif()
## ECRC INITIALIZATION
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules/ecrc/modules")
set(ECRC_CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/ecrc/modules )
include(EcrcInit)
# MPI
find_package( MPIEXT REQUIRED )
if( MPI_FOUND )
# TODO check MPI_C_COMPILER
include_directories( ${MPI_C_INCLUDE_PATH} )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_C_LINK_FLAGS}" )
endif()
## BLAS
find_package(BLASEXT)
if(BLAS_FOUND)
# Use parallel blas
if( USE_PARALLEL_BLAS AND NOT "${BLAS_PAR_LIBRARIES}" STREQUAL "" )
message( STATUS "Using Parallel Blas" )
set( BLAS_LIBRARIES "${BLAS_PAR_LIBRARIES}" )
endif()
if (BLAS_LIBRARY_DIRS)
# the RPATH to be used when installing
list( APPEND CMAKE_INSTALL_RPATH ${BLAS_LIBRARY_DIRS})
link_directories( ${BLAS_LIBRARY_DIRS} )
endif()
if(BLAS_LINKER_FLAGS)
list(APPEND CMAKE_EXE_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
list(APPEND CMAKE_SHARED_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
#set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}")
list( REMOVE_DUPLICATES CMAKE_EXE_LINKER_FLAGS )
endif()
else()
message( FATAL_ERROR "BLAS library has not been found")
endif()
# LAPACK
#find_package(LAPACK REQUIRED)
find_package(LAPACKEXT REQUIRED)
if(LAPACK_FOUND)
include_directories(${LAPACK_INCLUDE_DIRS})
if(LAPACK_LIBRARY_DIRS)
# the RPATH to be used when installing
list(APPEND CMAKE_INSTALL_RPATH ${LAPACK_LIBRARY_DIRS})
link_directories( ${LAPACK_LIBRARY_DIRS} )
endif()
if(LAPACK_LINKER_FLAGS)
list( REMOVE_DUPLICATES LAPACK_LINKER_FLAGS )
list( APPEND CMAKE_EXE_LINKER_FLAGS ${LAPACK_LINKER_FLAGS})
list( REMOVE_DUPLICATES CMAKE_EXE_LINKER_FLAGS )
endif()
endif()
# SCALAPACK
find_package( SCALAPACK )
if(SCALAPACK_FOUND)
if (SCALAPACK_LIBRARY_DIRS)
# the RPATH to be used when installing
list(APPEND CMAKE_INSTALL_RPATH ${SCALAPACK_LIBRARY_DIRS})
link_directories(${SCALAPACK_LIBRARY_DIRS})
endif()
if(SCALAPACK_LINKER_FLAGS)
list( REMOVE_DUPLICATES SCALAPACK_LINKER_FLAGS )
list( APPEND CMAKE_EXE_LINKER_FLAGS ${SCALAPACK_LINKER_FLAGS})
list( REMOVE_DUPLICATES CMAKE_EXE_LINKER_FLAGS )
endif()
endif()
include(ExternalProject)
# ELPA
find_package(ELPA)
if( ELPA_FOUND )
include_directories( ${ELPA_INCLUDE_DIRS} )
list(APPEND CMAKE_INSTALL_RPATH ${ELPA_LIBRARY_DIRS})
link_directories( ${ELPA_LIBRARY_DIRS} )
else()
set( ELPA_URL "http://elpa.mpcdf.mpg.de/html/Releases/2015.11.001/elpa-2015.11.001.tar.gz" )
message( FATAL_ERROR "## ELPA not found. ##\n Download ELPA from ${ELPA_URL}, compile it and set PKG_CONFIG_PATH environment variable to the proper location" )
endif( ELPA_FOUND )
# SLTMG - look for sltmg (only used for tests )
if( KSVD_TESTING )
set( SLTMG_LIBRARIES "" CACHE STRING "User provided sltmg library" )
set( _notfound_msg_ "SLTMG not found, NETLIB-SCALAPACK will be downloaded in order to generate libsltmg.a\n If you want to use your own SLTMG, define SLTMG_LIBRARIES and make sure SCALAPACK is found." )
if( SLTMG_LIBRARIES )
set(CMAKE_REQUIRED_LIBRARIES "${SLTMG_LIBRARIES};${SCALAPACK_LIBRARIES}")
check_fortran_function_exists("pdlatms" SLTMG_WORKS)
set(CMAKE_REQUIRED_LIBRARIES)
if( SLTMG_WORKS AND SCALAPACK_FOUND )
message(STATUS "Found SLTMG : ${SLTMG_LIBRARIES}")
else()
message( STATUS "${_notfound_msg_}")
endif()
else()
message( STATUS "${_notfound_msg_}")
endif()
endif()
if( NOT SCALAPACK_FOUND OR ( KSVD_TESTING AND NOT SLTMG_WORKS ) )
# Download NETLIB-SCALAPACK
set( _build_netlib-scalapack )
set( NETLIB_SCALAPACK_URL "http://www.netlib.org/scalapack/scalapack-2.0.2.tgz" CACHE STRING "URL to download NETLIB-SCALAPACK project" )
if(NOT SCALAPACK_FOUND)
set( SCALAPACK_LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/lib")
set( SCALAPACK_LIBRARIES "scalapack")
set( _install_target "install" )
set( _build_target "all" )
set( _patch_file "scalapack-cmake-libsltmg.patch" )
message( "## NETLIB-SCALAPACK will be downloaded from ${NETLIB_SCALAPACK_URL} and built along with libsltmg.a " )
else()
set( _install_target "install.sltmg" )
set( _build_target "sltmg" )
set( _patch_file "scalapack-cmake-libsltmg-only.patch" )
message( "## NETLIB-SCALAPACK will be downloaded from ${NETLIB_SCALAPACK_URL} in order to generate libsltmg.a " )
endif()
# Use the built sltmg
set( SLTMG_LIBRARIES "sltmg" )
# build scalapack for sltmg and or elpa
string(REPLACE ";" " " LAPACK_LIBRARIES_STR "${LAPACK_LIBRARIES}")
ExternalProject_Add( NETLIB-SCALAPACK
PREFIX dependencies
URL ${NETLIB_SCALAPACK_URL}
#URL /tmp/scalapack-2.0.2.tgz
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} -DBUILD_SHARED_LIBS:BOOL=${SHARED_NETLIBSCALAPACK} -DLAPACK_LIBRARIES:STRING='${LAPACK_LIBRARIES_STR}'
PATCH_COMMAND patch -p1 -i ${CMAKE_SOURCE_DIR}/${_patch_file}
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target ${_build_target} -- -j -l ${NUMBER_OF_CPU}
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target ${_install_target} --
#LOG_CONFIGURE 1
#LOG_BUILD 1
#LOG_INSTALL 1
)
if ( NOT ELPA_FOUND )
# Build NETLIB-SCALAPACK before ELPA
add_dependencies(ELPA NETLIB-SCALAPACK)
endif()
endif()
# TESTS
if( KSVD_TESTING )
## LAPACKE
find_package(LAPACKE COMPONENTS LAPACKEXT)
if(LAPACK_FOUND AND LAPACK_LIBRARY_DIRS)
# the RPATH to be used when installing
list(APPEND CMAKE_INSTALL_RPATH ${LAPACK_LIBRARY_DIRS})
else()
message(FATAL_ERROR "A LAPACK library is required but has not been found")
endif()
if(LAPACKE_FOUND)
if ( LAPACKE_INCLUDE_DIRS ) # Not always this variable is set, especially when is included in LAPACK
include_directories(${LAPACKE_INCLUDE_DIRS})
endif()
if(LAPACKE_LIBRARY_DIRS)
# the RPATH to be used when installing
list(APPEND CMAKE_INSTALL_RPATH "${LAPACKE_LIBRARY_DIRS}")
endif()
if(LAPACKE_LINKER_FLAGS)
list(APPEND CMAKE_EXE_LINKER_FLAGS ${LAPACKE_LINKER_FLAGS})
endif()
else()
if(ECRC_VERBOSE_FIND_PACKAGE)
if (LAPACKE_STANDALONE OR NOT LAPACKE_WORKS)
if (NOT LAPACKE_lapacke.h_DIRS)
Print_Find_Header_Status(lapacke lapacke.h)
endif ()
if (NOT LAPACKE_lapacke_LIBRARY)
Print_Find_Library_Status(lapacke liblapacke)
endif ()
endif()
else()
message(WARNING "LAPACKE library has not been found and ECRC_VERBOSE_FIND_PACKAGE is set to OFF"
"Try to activate ECRC_VERBOSE_FIND_PACKAGE option (-DECRC_VERBOSE_FIND_PACKAGE=ON) to get some hints for the detection")
endif()
#message(FATAL_ERROR "A LAPACKE library is required but has not been found")
endif()
## Backend options
set(POLAR_DIR "" CACHE PATH "POLAR installation directory" )
#add_library( polar STATIC IMPORTED )
#set_target_properties( polar PROPERTIES IMPORTED_LOCATION ${POLAR_DIR}/lib/libpolar.a )
link_directories( ${POLAR_DIR}/lib/ )
# BUILD TESTS
enable_testing() # enables ctest
add_definitions(-DHAVE_GETOPT_LONG)
add_subdirectory(testing)
add_subdirectory(timing)
endif()
# KSVD code
add_subdirectory(src)
install( FILES ${CMAKE_SOURCE_DIR}/include/ksvd.h DESTINATION include )
# PKGCONFIG
set(prefix ${CMAKE_INSTALL_PREFIX})
set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
set(PKG_CONFIG_DIR ${libdir}/pkgconfig)
configure_file(${CMAKE_SOURCE_DIR}/ksvd.pc.in ${CMAKE_CURRENT_BINARY_DIR}/ksvd.pc)
install( FILES ${CMAKE_BINARY_DIR}/ksvd.pc
DESTINATION ${PKG_CONFIG_DIR}
)