|
| 1 | +cmake_minimum_required(VERSION 2.8) |
| 2 | +## library versions ## |
| 3 | + |
| 4 | +set(EXTERNAL_TOP_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 5 | + |
| 6 | +set(llvm_VER 3.0) |
| 7 | +set(readline_VER 6.2) |
| 8 | +set(pcre_VER 8.21) |
| 9 | +set(grisu_VER 1.1) |
| 10 | +set(dsfmt_VER 2.1) |
| 11 | +set(openblas_VER v0.1alpha2.5) |
| 12 | +set(lapack_VER 3.4.0) |
| 13 | +set(arpack_VER 3.0.2) |
| 14 | +set(fftw_VER 3.3) |
| 15 | +set(suitesparse_VER 3.7.0) |
| 16 | +set(clp_VER 1.14.5) |
| 17 | +set(unwind_VER 1.0.1) |
| 18 | +set(lightttpd_VER 1.4.29) |
| 19 | + |
| 20 | +## Download Paths (to be replaced by git sumbodules) ## |
| 21 | +set(validExtensions tar gz bz2 tgz) |
| 22 | +set(llvm_URL http://llvm.org/releases/${llvm_VER}/llvm-${llvm_VER}.tar.gz) |
| 23 | +set(readline_URL ftp://ftp.gnu.org/gnu/readline/readline-${readline_VER}.tar.gz) |
| 24 | +set(pcre_URL ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-${pcre_VER}.tar.bz2) |
| 25 | +set(grisu_URL http://double-conversion.googlecode.com/files/double-conversion-${grisu_VER}.tar.gz) |
| 26 | +set(dsfmt_URL http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/dSFMT-src-${dsfmt_VER}.tar.gz) |
| 27 | +set(openblas_URL https://github.com/xianyi/OpenBLAS/tarball/${openblas_VER}) |
| 28 | +set(lapack_URL http://www.netlib.org/lapack/lapack-${lapack_VER}.tgz) |
| 29 | +set(arpack_URL http://forge.scilab.org/index.php/p/arpack-ng/downloads/353/get/) |
| 30 | +set(fftw_URL http://www.fftw.org/fftw-${fftw_VER}.tar.gz) |
| 31 | +set(suitesparse_URL http://www.cise.ufl.edu/research/sparse/SuiteSparse/SuiteSparse-${suitesparse_VER}.tar.gz) |
| 32 | +set(clp_URL http://www.coin-or.org/download/source/Clp/Clp-${clp_URL}.tgz) |
| 33 | +set(unwind_URL http://savannah.spinellicreations.com/libunwind/libunwind-${unwind_VER}.tar.gz) |
| 34 | +set(lighthttp_URL download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-${lighttd_VER}.tar.gz) |
| 35 | + |
| 36 | +## Needs tar command for unzipping - Possibly use cmake tar once strip-components is available ## |
| 37 | +find_program(TarPath "tar" DOC "tar command") |
| 38 | +if(${TarPath} MATCHES "TarPath-NOTFOUND") |
| 39 | + message(FATAL_ERROR "tar command was not found") |
| 40 | +endif() |
| 41 | + |
| 42 | +option(CHECK_CERTIFICATES "Enables certificate checks" OFF) |
| 43 | +if(NOT DEFINED BACKUP_DOWNLOADER) |
| 44 | + find_program(WgetPath "wget" DOC "wget command") |
| 45 | + if(${WgetPath} MATCHES "WgetPath-NOTFOUND") |
| 46 | + message(STATUS "wget command was not found") |
| 47 | + find_program(CUrlPath "curl" DOC "wget command") |
| 48 | + if(${CUrlPath} MATCHES "CUrlPath-NOTFOUND") |
| 49 | + message(STATUS "curl command was not found") |
| 50 | + else(${CUrlPath} MATCHES "CUrlPath-NOTFOUND") |
| 51 | + set(BACKUP_DOWNLOADER "${CUrlPath} -kLo") |
| 52 | + endif() |
| 53 | + else() |
| 54 | + set(BACKUP_DOWNLOADER ${WgetPath} "--no-check-certificate" "-O") |
| 55 | + endif() |
| 56 | +endif(NOT DEFINED BACKUP_DOWNLOADER) |
| 57 | +if(NOT DEFINED BACKUP_DOWNLOADER) |
| 58 | + message(WARNING "No alternate downloader found. Some file downloads may not be supported") |
| 59 | + message(WARNING "You can use -DBACKUP_DOWNLOADER:PATH=<path> to specify an alternative downloader!") |
| 60 | +endif(NOT DEFINED BACKUP_DOWNLOADER) |
| 61 | + |
| 62 | +## Download Packages ## |
| 63 | + |
| 64 | +set(PACKAGES llvm pcre dsfmt openblas lapack arpack fftw suitesparse) |
| 65 | + |
| 66 | +## Linux Specific Packages ## |
| 67 | + |
| 68 | +IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 69 | + set(PACKAGES ${PACKAGES} unwind) |
| 70 | +endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 71 | + |
| 72 | +## Other Packages ## |
| 73 | + |
| 74 | +option(USE_SYSTEM_READLINE "Use the system-provided readline library" OFF) |
| 75 | +IF(NOT USE_SYSTEM_READLINE) |
| 76 | + set(PACKAGES ${PACKAGES} readline) |
| 77 | +ENDIF(NOT USE_SYSTEM_READLINE) |
| 78 | + |
| 79 | +foreach(package ${PACKAGES}) |
| 80 | + message(STATUS "Checking package " ${package}) |
| 81 | + ## Get Version and URL to download ## |
| 82 | + set(versionvar "${package}_VER") |
| 83 | + set(version ${${versionvar}}) |
| 84 | + set(URLvar "${package}_URL") |
| 85 | + set(URL ${${URLvar}}) |
| 86 | + ## Get proper extension ## |
| 87 | + GET_FILENAME_COMPONENT(ext ${URL} EXT) |
| 88 | + ## The extension may contain leftover junk from the version informmation. Clean that up! ## |
| 89 | + |
| 90 | + string(REPLACE "." ";" ext ${ext} "") #Create list of extensions |
| 91 | + set(ext2 "${ext}") #copy list |
| 92 | + list(REMOVE_ITEM ext2 ${validExtensions}) |
| 93 | + list(REMOVE_ITEM ext ${ext2} "") #remove all but valid extensions |
| 94 | + ## Account for missing file extension and assume tar.gz |
| 95 | + list(LENGTH ext count) |
| 96 | + IF(${count} EQUAL 0) |
| 97 | + set(ext "tar;gz") |
| 98 | + endif() |
| 99 | + |
| 100 | + string(REPLACE ";" "." ext "${ext}") #turn list back into string |
| 101 | + |
| 102 | + IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/${package}-${version}.${ext}) |
| 103 | + ## Download the File ## |
| 104 | + message(STATUS "Downloading package " ${package}) |
| 105 | + file(DOWNLOAD ${URL} ${CMAKE_SOURCE_DIR}/${package}-${version}.${ext} STATUS downloadStatus SHOW_PROGRESS) |
| 106 | + list(GET downloadStatus 1 downloadError) |
| 107 | + list(GET downloadStatus 0 downloadStatus) |
| 108 | + IF(downloadStatus EQUAL 1 AND downloadError MATCHES "unsupported protocol") |
| 109 | + message(STATUS "Using alternate downloader from (${BACKUP_DOWNLOADER})") |
| 110 | + execute_process(COMMAND ${BACKUP_DOWNLOADER} ${CMAKE_SOURCE_DIR}/${package}-${version}.${ext} ${URL} RESULT_VARIABLE downloadStatus) |
| 111 | + endif() |
| 112 | + IF(NOT downloadStatus EQUAL 0) |
| 113 | + file(REMOVE ${CMAKE_SOURCE_DIR}/${package}-${version}.${ext}) |
| 114 | + message(STATUS "File:" ${URL}) |
| 115 | + message(STATUS "Error was: ${downloadError} (${downloadStatus})") |
| 116 | + message(FATAL_ERROR "Failed to download package " ${package}) |
| 117 | + else() |
| 118 | + message(STATUS "Download of package " ${package} " succesful") |
| 119 | + endif() |
| 120 | + endif() |
| 121 | + |
| 122 | + IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/${package}-${version}) |
| 123 | + message(STATUS "Decompressing package") |
| 124 | + file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/${package}-${version}) |
| 125 | + execute_process(COMMAND ${TarPath} -C ${package}-${version} --strip-components 1 -xf "${package}-${version}.${ext}" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} RESULT_VARIABLE result) |
| 126 | + IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/${package}-${version} OR result) |
| 127 | + file(REMOVE_RECURSE ${CMAKE_SOURCE_DIR}/${package}-${version}) |
| 128 | + message(FATAL_ERROR "Decompression of package " ${package} " failed") |
| 129 | + else() |
| 130 | + message(STATUS "Decompression of package " ${package} " succesful") |
| 131 | + endif() |
| 132 | + ENDIF() |
| 133 | + |
| 134 | +endforeach(package) |
| 135 | + |
| 136 | +## Duplicate FFTW ## |
| 137 | +IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/fftw-double-${fftw_VER}) |
| 138 | +message(STATUS "creating fftw-double") |
| 139 | +file(COPY fftw-${fftw_VER} DESTINATION ${CMAKE_BINARY_DIR}) |
| 140 | +file(RENAME ${CMAKE_BINARY_DIR}/fftw-${fftw_VER} ${CMAKE_SOURCE_DIR}/fftw-double-${fftw_VER}) |
| 141 | +message(STATUS "creation of fftw-double completed (hopefully)") |
| 142 | +ENDIF() |
| 143 | +## General Setup ## |
| 144 | + |
| 145 | +if(NOT DEFINED CMAKE_INSTALL_PREFIX) |
| 146 | + set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/"root") |
| 147 | +endif(NOT DEFINED CMAKE_INSTALL_PREFIX) |
| 148 | + |
| 149 | +if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE ) |
| 150 | + message(FATAL_ERROR "In-source builds are not allowed. |
| 151 | +Please create a directory and run cmake from there, passing the path |
| 152 | +to this source directory as the last argument. |
| 153 | +This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. |
| 154 | +Please delete them.") |
| 155 | +endif() |
| 156 | + |
| 157 | +## LLVM Setup |
| 158 | + |
| 159 | +set(LLVM_ENABLE_THREADS OFF) |
| 160 | +set(LLVM_TARGETS_TO_BUILD X86) |
| 161 | +add_subdirectory(llvm-${llvm_VER}) |
| 162 | + |
| 163 | +## PCRE Setup |
| 164 | + |
| 165 | +set(PCRE_SUPPORT_UNICODE_PROPERTIES ON) |
| 166 | +set(PCRE_SUPPORT_UTF8 ON) |
| 167 | +set(PCRE_SUPPORT_JIT ON) |
| 168 | +add_subdirectory(pcre-${pcre_VER}) |
| 169 | + |
| 170 | + |
| 171 | +# The Following configure check has been taken from LaPACK |
| 172 | +# Check the usage of the user provided BLAS libraries |
| 173 | +# If none were found, build the OpenBlas libraries |
| 174 | + |
| 175 | +if(BLAS_LIBRARIES) |
| 176 | + include(CheckFortranFunctionExists) |
| 177 | + set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) |
| 178 | + unset( BLAS_FOUND ) |
| 179 | + CHECK_FORTRAN_FUNCTION_EXISTS2("dgemm" BLAS_FOUND) |
| 180 | + unset( CMAKE_REQUIRED_LIBRARIES ) |
| 181 | + if(BLAS_FOUND) |
| 182 | + message(STATUS "--> BLAS supplied by user is WORKING, will use ${BLAS_LIBRARIES}.") |
| 183 | + else(BLAS_FOUND) |
| 184 | + message(ERROR "--> BLAS supplied by user is not WORKING, CANNOT USE ${BLAS_LIBRARIES}.") |
| 185 | + message(ERROR "--> Will use OpenBlas (by default)") |
| 186 | + message(ERROR "--> Or Correct your BLAS_LIBRARIES entry ") |
| 187 | + message(ERROR "--> Or Consider checking USE_OPTIMIZED_BLAS") |
| 188 | + endif(BLAS_FOUND) |
| 189 | + |
| 190 | +# User did not provide a BLAS Library but specified to search for one |
| 191 | +elseif( USE_OPTIMIZED_BLAS ) |
| 192 | + find_package( BLAS ) |
| 193 | +endif (BLAS_LIBRARIES) |
| 194 | + |
| 195 | +set(OpenBlasLIB ${CMAKE_SOURCE_DIR}/openblas-${openblas_VER}/libopenblas.${CMAKE_STATIC_LIBRARY_SUFFIX}) |
| 196 | +# Neither user specified or optimized BLAS libraries can be used |
| 197 | +if(NOT BLAS_FOUND) |
| 198 | + message(STATUS "Using OpenBlas") |
| 199 | + set( BLAS_LIBRARIES ${OpenBlasLIB}) |
| 200 | + set( BUILD_OPENBLAS ON) |
| 201 | + set( BLAS_TARGET openblas) |
| 202 | +else() |
| 203 | + set( CMAKE_EXE_LINKER_FLAGS |
| 204 | + "${CMAKE_EXE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" |
| 205 | + CACHE STRING "Linker flags for executables" FORCE) |
| 206 | + set( CMAKE_MODULE_LINKER_FLAGS |
| 207 | + "${CMAKE_MODULE_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" |
| 208 | + CACHE STRING "Linker flags for modules" FORCE) |
| 209 | + set( CMAKE_SHARED_LINKER_FLAGS |
| 210 | + "${CMAKE_SHARED_LINKER_FLAGS} ${BLAS_LINKER_FLAGS}" |
| 211 | + CACHE STRING "Linker flags for shared libs" FORCE) |
| 212 | +endif( NOT BLAS_FOUND ) |
| 213 | + |
| 214 | +set(BUILD_SHARED_LIBS ON) |
| 215 | +set(BLAS_FOUND 1) #Prevent LaPack from using it's own blas version |
| 216 | +add_subdirectory(lapack-${lapack_VER}) |
| 217 | +set( LAPACK_TARGET lapack-static ) |
| 218 | + |
| 219 | +add_subdirectory(amos) |
| 220 | +##Set ASM Env var -- should not be necessary technically |
| 221 | +include(CMakeDetermineASMCompiler) |
| 222 | +set(CMAKE_ASM_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY}) |
| 223 | + |
| 224 | +add_subdirectory(fdlibm) |
| 225 | +set(LapackLIB lapack) |
| 226 | + |
| 227 | +add_subdirectory(cmake) |
| 228 | + |
| 229 | +set(FFTW_CONFIG --enable-shared --disable-fortran --disable-mpi --disable-openmp --disable-threads --enable-sse2 --enable-fma) |
| 230 | +IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") |
| 231 | +set(FFTW_CONFIG ${FFTW_CONFIG} --with-our-malloc) |
| 232 | +ENDIF() |
| 233 | + |
| 234 | +macro(autoconfTarget name options) |
| 235 | +message(STATUS ${name}) |
| 236 | +set(${name}_SRC_DIR ${CMAKE_SOURCE_DIR}/${name}-${${name}_VER}) |
| 237 | +set(${name}_BINARY_DIR ${CMAKE_BINARY_DIR}/${name}-${${name}_VER}) |
| 238 | +set(${name}_CONFIGURE ${${name}_SRC_DIR}/configure) |
| 239 | +message(STATUS ${name}_SRC_DIR) |
| 240 | +message(STATUS ${${name}_SRC_DIR}) |
| 241 | +message(STATUS ${${name}_BINARY_DIR}) |
| 242 | +file(MAKE_DIRECTORY ${${name}_BINARY_DIR}) |
| 243 | +add_custom_command(OUTPUT ${${name}_BINARY_DIR}/Makefile COMMAND ${${name}_CONFIGURE} --prefix=${CMAKE_INSTALL_PREFIX} ${options} WORKING_DIRECTORY ${${name}_BINARY_DIR}) |
| 244 | +add_custom_command(OUTPUT ${${name}_BINARY_DIR}/BuildDone COMMAND $(MAKE) -C ${${name}_BINARY_DIR} |
| 245 | +COMMAND touch ${${name}_CONFIGURE} |
| 246 | +COMMAND $(MAKE) -C ${${name}_BINARY_DIR} install |
| 247 | +COMMAND touch ${${name}_BINARY_DIR}/BuildDone |
| 248 | +DEPENDS ${${name}_BINARY_DIR}/Makefile |
| 249 | +WORKING_DIRECTORY ${${name}_BINARY_DIR}) |
| 250 | +endmacro() |
| 251 | + |
| 252 | +#set(fftw-double_VER ${fftw_VER}) |
| 253 | +#set(fftwDoubleFeatures --enable-sse --enable-float ${FFTW_CONFIG}) |
| 254 | +#autoconfTarget(fftw-double "${fftwDoubleFeatures}") |
| 255 | +# |
| 256 | +#autoconfTarget(fftw "${FFTW_CONFIG}") |
| 257 | + |
| 258 | +IF(OFF) |
| 259 | +autoconfTarget(clp) |
| 260 | +ENDIF() |
| 261 | + |
| 262 | + |
| 263 | +IF(BUILD_OPENBLAS) |
| 264 | +set(OPENBLAS_SRC_DIR ${CMAKE_SOURCE_DIR}/openblas-${openblas_VER}) |
| 265 | +set(OPENBLAS_BINARY_DIR ${CMAKE_BINARY_DIR}/openblas-${openblas_VER}) |
| 266 | +set(OPENBLAS_CONFIGURE ${OPENBLAS_SRC_DIR}/configure) |
| 267 | +file(MAKE_DIRECTORY ${OPENBLAS_BINARY_DIR}) |
| 268 | +add_custom_target(openblas COMMAND perl -i -ple "'s/^\\s*(EXTRALIB\\s*\\+=\\s*-lSystemStubs)\\s*$$/# $$1/g'" ${CMAKE_CURRENT_SOURCE_DIR}/openblas-${openblas_VER}/Makefile.system |
| 269 | +COMMAND $(MAKE) DYNAMIC_ARCH=1 USE_THREAD=0 NO_LAPACK=1 CC=$(CC) FC=$(FC) FFLAGS="$(FFLAGS)" TARGET=$(TARGET_OPENBLAS_ARCH) |
| 270 | +COMMAND $(MAKE) install PREFIX=${CMAKE_INSTALL_PREFIX} DYNAMIC_ARCH=1 USE_THREAD=0 NO_LAPACK=1 CC=$(CC) FC=$(FC) FFLAGS="$(FFLAGS)" TARGET=$(TARGET_OPENBLAS_ARCH) |
| 271 | +WORKING_DIRECTORY ${OPENBLAS_SRC_DIR}) |
| 272 | +ENDIF() |
| 273 | + |
| 274 | +IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 275 | +set(UNWIND_SRC_DIR ${CMAKE_SOURCE_DIR}/unwind-${unwind_VER}) |
| 276 | +set(UNWIND_BINARY_DIR ${CMAKE_BINARY_DIR}/unwind-${unwind_VER}) |
| 277 | +set(UNWIND_CONFIGURE ${UNWIND_SRC_DIR}/configure) |
| 278 | +add_custom_target(unwind ALL cd ${UNWIND_DIR} COMMAND ${UNWIND_CONFIGURE} CFLAGS="-U_FORTIFY_SOURCE -fPIC" --prefix=${CMAKE_INSTALL_PREFIX} |
| 279 | +COMMAND $(MAKE) -C ${UNWIND_BINARY_DIR} |
| 280 | +COMMAND touch ${UNWIND_CONFIGURE} |
| 281 | +COMMAND $(MAKE) -C ${UNWIND_BINARY_DIR} install |
| 282 | +WORKING_DIRECTORY ${UNWIND_BINARY_DIR}) |
| 283 | +ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 284 | + |
| 285 | +#add_custom_target(dependencies ALL DEPENDS ${fftw_BINARY_DIR}/BuildDone ${fftw-double_BINARY_DIR}/BuildDone) |
| 286 | + |
| 287 | +add_dependencies(lapack openblas) |
| 288 | +add_dependencies(arpack openblas lapack) |
0 commit comments