[1954] | 1 | ### |
---|
| 2 | # CMakeLists.txt for ASAP module |
---|
| 3 | ### |
---|
| 4 | |
---|
| 5 | # minimum requirement for cmake version |
---|
| 6 | cmake_minimum_required( VERSION 2.8 ) |
---|
| 7 | |
---|
| 8 | # project name is ASAP |
---|
| 9 | project( ASAP ) |
---|
| 10 | |
---|
| 11 | # install directory |
---|
| 12 | # set casaroot |
---|
| 13 | # the regular expression means '../' |
---|
| 14 | # [^ ] Matches any character(s) not inside the brackets |
---|
| 15 | # + Matches preceding pattern one or more times |
---|
| 16 | # ? Matches preceding pattern zero or once only |
---|
| 17 | # $ Mathces at end of a line |
---|
| 18 | string( REGEX REPLACE /[^/]+/?$ "" casaroot ${CMAKE_SOURCE_DIR} ) |
---|
| 19 | message( STATUS "casaroot = " ${casaroot} ) |
---|
| 20 | |
---|
[1957] | 21 | # modules |
---|
| 22 | set( CMAKE_MODULE_PATH ${casaroot}/code/install ) |
---|
| 23 | include( config ) |
---|
| 24 | include( CASA ) |
---|
| 25 | |
---|
[1954] | 26 | # flags |
---|
| 27 | set( DEFAULT_CXX_FLAGS |
---|
[1957] | 28 | "-pipe -Wall -Wextra -Wno-non-template-friend -Wcast-align -Wno-comment -O3" ) |
---|
[1954] | 29 | find_package( OpenMP ) |
---|
| 30 | if( OPENMP_FOUND ) |
---|
| 31 | set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" ) |
---|
| 32 | endif() |
---|
| 33 | |
---|
| 34 | # environment dependent settings |
---|
| 35 | if( APPLE ) |
---|
| 36 | set( SO dylib ) |
---|
| 37 | if( NOT arch ) |
---|
| 38 | set( arch darwin ) |
---|
| 39 | endif() |
---|
| 40 | if( CMAKE_SYSTEM MATHCES ^Darwin-10 ) |
---|
| 41 | if( NOT archflag ) |
---|
| 42 | if( EXISTS /opt/casa/darwin10-64b ) |
---|
| 43 | set( archflag x86_64 ) |
---|
| 44 | elseif( EXISTS /opt/casa/core2-apple-darwin10 ) |
---|
| 45 | set( archflag i386 ) |
---|
| 46 | else() |
---|
| 47 | set( archflag x86_64 ) |
---|
| 48 | endif() |
---|
| 49 | endif() |
---|
| 50 | if( archflag STREQUAL x86_64 ) |
---|
| 51 | add_definitions( -DAIPS_64B ) |
---|
| 52 | set( casa_packages /opt/casa/darwin10-64b ) |
---|
| 53 | else() |
---|
| 54 | set( casa_packages /opt/casa/core2-apple-darwin10 ) |
---|
| 55 | endif() |
---|
| 56 | execute_process( COMMAND ${CMAKE_CXX_COMPILER} --version |
---|
| 57 | COMMAND head -1 |
---|
| 58 | COMMAND perl -pe "s|.*?(\\d+\\.\\d+)\\.\\d+$|$1|" |
---|
| 59 | OUTPUT_VARIABLE _cxx_version |
---|
| 60 | OUTPUT_STRIP_TRAILING_WHITESPACE ) |
---|
| 61 | if( NOT _cxx_version STREQUAL "4.4" ) |
---|
| 62 | set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -arch ${archflag}" ) |
---|
| 63 | endif() |
---|
| 64 | elseif( CMAKE_SYSTEM MATCHES ^Darwin-9 ) |
---|
| 65 | set( casa_packages /opt/casa/core2-apple-darwin8/3rd-party ) |
---|
| 66 | endif() |
---|
| 67 | elseif( CMAKE_SYSTEM_NAME STREQUAL Linux ) |
---|
| 68 | set( SO so ) |
---|
| 69 | add_definitions( -DAIPS_LINUX ) |
---|
| 70 | if( CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 ) |
---|
| 71 | set( casa_packages /usr/lib64/casapy ) |
---|
| 72 | if( NOT arch ) |
---|
| 73 | set( arch linux_64b ) |
---|
| 74 | endif() |
---|
| 75 | add_definitions( -DAIPS_64B ) |
---|
| 76 | set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -Wno-deprecated" ) |
---|
| 77 | else() |
---|
| 78 | set( casa_packages /usr/lib/casapy ) |
---|
| 79 | if( NOT arch ) |
---|
| 80 | set( arch linux_gnu ) |
---|
| 81 | endif() |
---|
| 82 | set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -Wno-deprecated -Woverloaded-virtual" ) |
---|
| 83 | endif() |
---|
| 84 | endif() |
---|
| 85 | message( STATUS "arch = " ${arch} ) |
---|
| 86 | |
---|
| 87 | # set root directory for installation |
---|
| 88 | set( CMAKE_INSTALL_PREFIX ${casaroot}/${arch} ) |
---|
| 89 | message( STATUS "CMAKE_INSTALL_PREFIX = " ${CMAKE_INSTALL_PREFIX} ) |
---|
| 90 | |
---|
| 91 | # set flags for cpp compiler |
---|
| 92 | set( CMAKE_CXX_FLAGS ${DEFAULT_CXX_FLAGS} ) |
---|
| 93 | |
---|
[1957] | 94 | |
---|
[1954] | 95 | # |
---|
| 96 | # casacore |
---|
| 97 | # |
---|
[1956] | 98 | if( NOT USE_LIBCASACORE ) |
---|
| 99 | # use casacore libraries |
---|
| 100 | set( _includename aipsdef.h ) |
---|
| 101 | find_path( CASACORE_INCPATH ${_includename} |
---|
| 102 | HINTS ${casaroot}/${arch}/include/ |
---|
| 103 | PATH_SUFFIXES casacore/casa ) |
---|
| 104 | if( CASACORE_INCPATH STREQUAL CASACORE_INCPATH-NOTFOUND ) |
---|
| 105 | message( FATAL_ERROR "${_includename} could not be found. Please check!" ) |
---|
| 106 | else() |
---|
| 107 | string( REGEX REPLACE /[^/]+/?$ "" CASACORE_INCLUDE_DIR ${CASACORE_INCPATH} ) |
---|
[1954] | 108 | endif() |
---|
[1956] | 109 | set( CASACORE_LIBS casa |
---|
| 110 | components |
---|
| 111 | coordinates |
---|
| 112 | fits |
---|
| 113 | images |
---|
| 114 | lattices |
---|
| 115 | measures |
---|
| 116 | mirlib |
---|
| 117 | ms |
---|
| 118 | msfits |
---|
| 119 | scimath |
---|
| 120 | scimath_f |
---|
| 121 | tables ) |
---|
| 122 | set( _casacore_libs "" ) |
---|
| 123 | foreach( _a ${CASACORE_LIBS} ) |
---|
| 124 | set( _libname libcasa_${_a}.${SO} ) |
---|
| 125 | unset( _casacore_lib CACHE ) |
---|
| 126 | find_library( _casacore_lib ${_libname} |
---|
| 127 | PATHS ${CMAKE_INSTALL_PREFIX} PATH_SUFFIXES lib ) |
---|
| 128 | if( NOT _casacore_lib-NOTFOUND ) |
---|
| 129 | list( APPEND _casacore_libs casa_${_a} ) |
---|
| 130 | endif() |
---|
| 131 | endforeach() |
---|
| 132 | set( CASACORE_LIBRARIES ${_casacore_libs} ) |
---|
| 133 | else() |
---|
| 134 | # use libcasacore |
---|
| 135 | set( _libname libcasacore.${SO} ) |
---|
| 136 | find_library( CASACORE_LIBRARIES ${_libname} ) |
---|
| 137 | if( CASACORE_LIBRARIES STREQUAL CASACORE_LIBRARIES-NOTFOUND ) |
---|
| 138 | message( FATAL_ERROR "${_libname} could not be found. Please check!" ) |
---|
| 139 | endif() |
---|
| 140 | set( _includename aipsdef.h ) |
---|
| 141 | find_path( CASACORE_INCPATH ${_includename} |
---|
| 142 | PATH_SUFFIXES casacore/casa ) |
---|
| 143 | if( CASACORE_INCPATH STREQUAL CASACORE_INCPATH-NOTFOUND ) |
---|
| 144 | message( FATAL_ERROR "${_includename} could not be found. Please check!" ) |
---|
| 145 | else() |
---|
| 146 | string( REGEX REPLACE /[^/]+/?$ "" CASACORE_INCLUDE_DIR ${CASACORE_INCPATH} ) |
---|
| 147 | endif() |
---|
| 148 | endif() |
---|
[1954] | 149 | message( STATUS "CASACORE_LIBRARIES = " ${CASACORE_LIBRARIES} ) |
---|
[1956] | 150 | message( STATUS "CASACORE_INCLUDE_DIR = " ${CASACORE_INCLUDE_DIR} ) |
---|
[1954] | 151 | |
---|
[1957] | 152 | |
---|
[1954] | 153 | # |
---|
| 154 | # Python |
---|
| 155 | # |
---|
[1957] | 156 | if( NOT PYTHON_FOUND ) |
---|
| 157 | |
---|
| 158 | if ( NOT PYTHON_LIBNAME ) |
---|
| 159 | set( _names 2.9 2.8 2.7 2.6 2.5.2 2.5 ) |
---|
| 160 | # (The library named libpython.2.5.2.dylib seems to exist only in the CASA world.) |
---|
| 161 | else() |
---|
| 162 | set( _names ${PYTHON_LIBNAME} ) |
---|
| 163 | endif() |
---|
| 164 | |
---|
| 165 | set( _found False ) |
---|
| 166 | foreach( _v ${_names} ) |
---|
| 167 | |
---|
| 168 | casa_find( |
---|
| 169 | PYTHON${_v} |
---|
| 170 | LIBS python${_v} |
---|
| 171 | NO_REQUIRE |
---|
| 172 | ) |
---|
| 173 | |
---|
| 174 | if( PYTHON${_v}_FOUND ) |
---|
| 175 | set( PYTHON_LIBNAME ${_v} ) |
---|
| 176 | set( _found True ) |
---|
| 177 | break() |
---|
| 178 | endif() |
---|
| 179 | |
---|
| 180 | endforeach() |
---|
| 181 | |
---|
| 182 | if( NOT _found ) |
---|
| 183 | message( FATAL_ERROR "Could not find any PYTHON library with version one of ${_names}. Please check!" ) |
---|
| 184 | endif() |
---|
| 185 | |
---|
[1954] | 186 | endif() |
---|
| 187 | |
---|
[1957] | 188 | if( NOT PYTHON_LIBNAME ) |
---|
| 189 | # Found Python, but PYTHON_LIBNAME is undefined, that is impossible. |
---|
| 190 | message( FATAL_ERROR "The variable PYTHON_LIBNAME is undefined. Most likely, CMake's cache is out of date and you need to redetect your PYTHON installation (\"cmake -U PYTHON*\")") |
---|
[1954] | 191 | endif() |
---|
| 192 | |
---|
[1957] | 193 | string( SUBSTRING ${PYTHON_LIBNAME} 0 3 PYTHONV ) |
---|
| 194 | string( REPLACE "." "" PV ${PYTHONV} ) |
---|
| 195 | set( python_library python${PYTHON_LIBNAME} ) |
---|
| 196 | |
---|
| 197 | # Form the Python install prefix by stripping away "lib/libpython2.5.2.dylib" (example) from |
---|
| 198 | # the full python library path |
---|
| 199 | string( REGEX MATCH "/lib(64)?/lib${python_library}" _match ${PYTHON${PYTHON_LIBNAME}_LIBRARIES} ) |
---|
| 200 | if( _match ) |
---|
| 201 | string( REGEX REPLACE "/lib(64)?/lib${python_library}.*" "" python_prefix ${PYTHON${PYTHON_LIBNAME}_LIBRARIES} ) |
---|
| 202 | else() |
---|
| 203 | # Python library was not in a lib(64) directory! |
---|
| 204 | message( WARNING "Python library path \"${PYTHON${PYTHON_LIBNAME}_LIBRARIES}\" does not contain \"/lib(64)/lib${python_library}\"" ) |
---|
| 205 | set( python_prefix ${casa_packages} ) |
---|
[1954] | 206 | endif() |
---|
[1957] | 207 | |
---|
| 208 | # The python version and prefix is known, do the actual search |
---|
| 209 | if( NOT PYTHON_FOUND ) |
---|
| 210 | message( STATUS "Looking for PYTHON version ${PYTHONV}.x in ${python_prefix}" ) |
---|
| 211 | endif() |
---|
| 212 | |
---|
| 213 | casa_find( PYTHON |
---|
| 214 | VERSION 2.5 # minimum required |
---|
| 215 | INCLUDES Python.h |
---|
| 216 | numpy/npy_interrupt.h # for numpy |
---|
| 217 | INCLUDES_SUFFIXES python${PYTHONV} |
---|
| 218 | PREFIX_HINTS |
---|
| 219 | ${python_prefix}/lib/python${PYTHONV}/site-packages/numpy/core |
---|
| 220 | ${python_prefix}/Library/Frameworks/Python.framework/Versions/${PYTHONV} |
---|
| 221 | ${python_prefix}/Library/Frameworks/Python.framework/Versions/${PYTHONV}/lib/python${PYTHONV}/site-packages/numpy/core |
---|
| 222 | LIBS ${python_library} |
---|
| 223 | CPP_VERSION PY_VERSION ) |
---|
| 224 | |
---|
| 225 | # Store PYTHON_LIBNAME in the cache |
---|
| 226 | set( PYTHON_LIBNAME ${PYTHON_LIBNAME} CACHE STRING "Python major and minor version to use" FORCE ) |
---|
| 227 | |
---|
| 228 | # Define pyroot to two directory levels above Python.h. |
---|
| 229 | string( REGEX REPLACE "/[^/]+/[^/]+/?$" "" pyroot ${PYTHON_Python.h} ) |
---|
| 230 | |
---|
[1954] | 231 | message( STATUS "PYTHON_INCLUDE_DIR = " ${PYTHON_INCLUDE_DIR} ) |
---|
[1957] | 232 | message( STATUS "PYTHON_LINRARIES = " ${PYTHON_LIBRARIES} ) |
---|
| 233 | message( STATUS "PYTHONV = " ${PYTHONV} ) |
---|
[1954] | 234 | |
---|
[1957] | 235 | set( PYTHON_DEFINITIONS ${PYTHON_DEFINITIONS} |
---|
| 236 | -DAIPSROOT=\"${CMAKE_SOURCE_DIR}\" |
---|
| 237 | -DAIPSARCH=\"${arch}\" |
---|
| 238 | -DAIPSSITE=\"garching\" |
---|
| 239 | -DPYTHONROOT=\"${pyroot}\" |
---|
| 240 | -DPYTHONVER=\"${PYTHONV}\" |
---|
| 241 | -DPYVERSION=${PV} ) |
---|
| 242 | |
---|
| 243 | |
---|
[1954] | 244 | # |
---|
| 245 | # Boost |
---|
| 246 | # |
---|
| 247 | if( NOT BOOST_ROOT ) |
---|
| 248 | set( BOOST_ROOT ${casa_packages} ) |
---|
| 249 | endif() |
---|
| 250 | |
---|
[1957] | 251 | set( boost_components python ) |
---|
[1954] | 252 | find_package( Boost REQUIRED ${boost_components} ) |
---|
| 253 | if( NOT Boost_FOUND ) |
---|
| 254 | message( FATAL_ERROR "Boost could not be found. Please check!" ) |
---|
| 255 | endif() |
---|
[1957] | 256 | message( STATUS "BOOST_INCLUDE_DIR = " ${Boost_INCLUDE_DIR} ) |
---|
| 257 | message( STATUS "BOOST_LIBRARIES = " ${Boost_LIBRARIES} ) |
---|
[1954] | 258 | |
---|
| 259 | |
---|
[1957] | 260 | # |
---|
| 261 | # cfitsio |
---|
| 262 | # |
---|
| 263 | casa_find( CFITSIO |
---|
| 264 | VERSION 3.006 |
---|
| 265 | INCLUDES fitsio.h fitsio2.h |
---|
| 266 | INCLUDES_SUFFIXES cfitsio |
---|
| 267 | LIBS cfitsio |
---|
| 268 | CPP_VERSION CFITSIO_VERSION |
---|
| 269 | RUN_VERSION "(ffvers(&v), v)" ) |
---|
| 270 | if( NOT CFITSIO_FOUND ) |
---|
| 271 | message( FATAL_ERROR "CFITSIO could not be found. Please check!" ) |
---|
| 272 | endif() |
---|
| 273 | message( STATUS "CFITSIO_INCLUDE_DIRS = " ${CFITSIO_INCLUDE_DIRS} ) |
---|
| 274 | message( STATUS "CFITSIO_LIBRARIES = " ${CFITSIO_LIBRARIES} ) |
---|
[1954] | 275 | |
---|
[1957] | 276 | |
---|
| 277 | # |
---|
| 278 | # wcslib |
---|
| 279 | # |
---|
| 280 | set( _wcslib libwcs.${SO} ) |
---|
| 281 | find_library( WCSLIB ${_wcslib} |
---|
| 282 | HINTS /usr/lib64 /usr/lib ${casaroot}/${arch}/lib ) |
---|
| 283 | if( WCSLIB STREQUAL WCSLIB-NOTFOUND ) |
---|
| 284 | message( FATAL_ERROR "${_wcslib} could not be found. Please check!" ) |
---|
| 285 | endif() |
---|
| 286 | message( STATUS "WCSLIB = " ${WCSLIB} ) |
---|
| 287 | |
---|
| 288 | |
---|
| 289 | # |
---|
| 290 | # RPFITS (Fortran) |
---|
| 291 | # |
---|
| 292 | if( NOT FORTRAN_LIBRARIES ) |
---|
| 293 | |
---|
| 294 | message( STATUS "Looking for Fortran runtime libraries" ) |
---|
| 295 | set( _try ${CMAKE_BINARY_DIR}/try_fortran.cc ) |
---|
| 296 | file( WRITE ${_try} |
---|
| 297 | "int main() { return 0; }\n" |
---|
| 298 | ) |
---|
| 299 | |
---|
| 300 | if( _gfortran_lib_path ) |
---|
| 301 | try_compile( _have_gfortran ${CMAKE_BINARY_DIR} ${_try} |
---|
| 302 | CMAKE_FLAGS -Wdev "-DCMAKE_EXE_LINKER_FLAGS=${_gfortran_lib_path}" |
---|
| 303 | ) |
---|
| 304 | else() |
---|
| 305 | try_compile( _have_gfortran ${CMAKE_BINARY_DIR} ${_try} |
---|
| 306 | CMAKE_FLAGS -Wdev "-DCMAKE_EXE_LINKER_FLAGS=-lgfortran" |
---|
| 307 | ) |
---|
[1954] | 308 | endif() |
---|
[1957] | 309 | try_compile( _have_g2c ${CMAKE_BINARY_DIR} ${_try} |
---|
| 310 | CMAKE_FLAGS -Wdev "-DCMAKE_EXE_LINKER_FLAGS=-lg2c" |
---|
| 311 | ) |
---|
| 312 | |
---|
| 313 | if( _have_gfortran ) |
---|
| 314 | if( _gfortran_lib_path ) |
---|
| 315 | set( FORTRAN_LIBRARIES ${_gfortran_lib_path} |
---|
| 316 | CACHE STRING "Fortran library linker option" FORCE ) |
---|
| 317 | else() |
---|
| 318 | set( FORTRAN_LIBRARIES -lgfortran |
---|
| 319 | CACHE STRING "Fortran library linker option" FORCE ) |
---|
| 320 | endif() |
---|
| 321 | message( STATUS "Looking for Fortran runtime libraries -- ${FORTRAN_LIBRARIES}" ) |
---|
| 322 | elseif( _have_g2c ) |
---|
| 323 | set( FORTRAN_LIBRARIES -lg2c |
---|
| 324 | CACHE STRING "Fortran library linker option" FORCE ) |
---|
| 325 | message( STATUS "Looking for Fortran runtime libraries -- ${FORTRAN_LIBRARIES}" ) |
---|
| 326 | else() |
---|
| 327 | set( FORTRAN_LIBRARIES "" |
---|
| 328 | CACHE STRING "Fortran library linker option" FORCE ) |
---|
| 329 | message( STATUS "Looking for Fortran runtime libraries -- <none>" ) |
---|
| 330 | # Not a fatal error because it might work, if all Fortran dependencies were |
---|
| 331 | # already linked statically to the Fortran runtime... |
---|
| 332 | endif() |
---|
| 333 | endif() |
---|
[1954] | 334 | |
---|
[1957] | 335 | casa_find( RPFITS |
---|
| 336 | VERSION 2.11 |
---|
| 337 | INCLUDES RPFITS.h |
---|
| 338 | LIBS rpfits |
---|
| 339 | RUN_VERSION names_.rpfitsversion |
---|
| 340 | DEPENDS FORTRAN |
---|
| 341 | ) |
---|
| 342 | if( NOT RPFITS_FOUND ) |
---|
| 343 | message( FATAL_ERROR "${_wcslib} could not be found. Please check!" ) |
---|
[1954] | 344 | endif() |
---|
[1957] | 345 | message( STATUS "RPFITS_INCLUDE_DIR = " ${RPFITS_INCLUDE_DIR} ) |
---|
| 346 | message( STATUS "RPFITS_LIBRARIES = " ${RPFITS_LIBRARIES} ) |
---|
[1954] | 347 | |
---|
| 348 | |
---|
[1957] | 349 | # |
---|
| 350 | # common include path |
---|
| 351 | # |
---|
[1954] | 352 | message( STATUS "Boost_INCLUDE_DIR = " ${Boost_INCLUDE_DIR} ) |
---|
| 353 | include_directories( ${CASACORE_INCLUDE_DIR} |
---|
| 354 | ${Boost_INCLUDE_DIR} |
---|
| 355 | ${PYTHON_INCLUDE_DIR} ) |
---|
| 356 | |
---|
[1957] | 357 | # |
---|
[1954] | 358 | # link path |
---|
[1957] | 359 | # |
---|
[1954] | 360 | set( CASACORE_LIBRARY_DIR ${casaroot}/${arch}/lib ) |
---|
| 361 | link_directories( ${CASACORE_LIBRARY_DIR} ) |
---|
| 362 | |
---|
| 363 | |
---|
[1957] | 364 | # |
---|
[1954] | 365 | # install directory |
---|
[1957] | 366 | # |
---|
[1954] | 367 | set( EXEC_INSTALL_DIR bin ) |
---|
| 368 | set( LIB_INSTALL_DIR lib ) |
---|
[1957] | 369 | set( PYTHON_INSTALL_DIR python/${PYTHONV}/asap ) |
---|
[1954] | 370 | set( SHARED_INSTALL_DIR share/asap ) |
---|
| 371 | |
---|
[1957] | 372 | |
---|
| 373 | # |
---|
| 374 | # libraries and executables |
---|
| 375 | # |
---|
| 376 | set( ASAPLIB _asap ) |
---|
| 377 | set( PYRAPLIB pyrap ) |
---|
| 378 | set( ATNFLIB atnf ) |
---|
| 379 | set( ASAP2TO3 asap2to3 ) |
---|
| 380 | |
---|
| 381 | |
---|
| 382 | # |
---|
[1954] | 383 | # subdirectories |
---|
[1957] | 384 | # ASAP2TO3 asap2to3 apps |
---|
| 385 | # PYRAPLIB libpyrap.so external/libpyrap |
---|
| 386 | # ATNFLIB libatnf.so external-alma/atnf |
---|
| 387 | # ASAPLIB _asap.so src |
---|
| 388 | # python modules python |
---|
| 389 | # shared files share |
---|
| 390 | # |
---|
[1954] | 391 | add_subdirectory( apps ) |
---|
| 392 | add_subdirectory( external/libpyrap ) |
---|
| 393 | add_subdirectory( external-alma/atnf ) |
---|
| 394 | add_subdirectory( src ) |
---|
| 395 | add_subdirectory( python ) |
---|
| 396 | add_subdirectory( share ) |
---|
| 397 | |
---|
| 398 | |
---|