source: trunk/CMakeLists.txt @ 1963

Last change on this file since 1963 was 1963, checked in by Takeshi Nakazato, 13 years ago

New Development: No

JIRA Issue: Yes CAS-2668

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Updated along with Jonas's recommendation.
Added result check for lapack, blas.


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