source: trunk/CMakeLists.txt @ 1970

Last change on this file since 1970 was 1970, 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...

Refactoring.


File size: 16.3 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# options
9option( USE_LIBCASACORE
10        "set ON to use libcasacore.so instead of libcasa_*.so"
11        OFF )
12option( STANDALONE
13        "set ON to build standalone mode"
14        OFF )
15message( STATUS "USE_LIBCASACORE = " ${USE_LIBCASACORE} )
16message( STATUS "STANDALONE = " ${STANDALONE} )
17
18# Define compiler paths on OSX 10.5. This must be done before invoking project()
19if( APPLE )
20    if( EXISTS            /opt/casa/core2-apple-darwin8/3rd-party/bin/gfortran )
21        set( CMAKE_Fortran_COMPILER /opt/casa/core2-apple-darwin8/3rd-party/bin/gfortran )
22        set( CMAKE_CXX_COMPILER     /opt/casa/core2-apple-darwin8/3rd-party/bin/g++ )
23    elseif( EXISTS        /opt/local/bin/gfortran )
24        set( CMAKE_Fortran_COMPILER /opt/local/bin/gfortran )
25    elseif( EXISTS        /opt/local/bin/gfortran-mp-4.4 )
26        set( CMAKE_Fortran_COMPILER /opt/local/bin/gfortran-mp-4.4 )
27        if( EXISTS /opt/local/bin/g++-mp-4.4 )
28            set( CMAKE_CXX_COMPILER /opt/local/bin/g++-mp-4.4 )
29        endif()
30    endif()
31endif()
32
33# project name is ASAP
34project( ASAP )
35
36# flags
37set( DEFAULT_CXX_FLAGS
38     "-pipe -Wall -Wextra -Wno-non-template-friend -Wcast-align -Wno-comment -O3" )
39find_package( OpenMP )
40if( OPENMP_FOUND )
41   set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
42endif()
43
44set( CASACORE_DEFINITIONS ${CASACORE_DEFINITIONS}
45  -DCASA_USECASAPATH
46  -DCASACORE_NEEDS_RETHROW
47  -DAIPS_STDLIB
48  -DAIPS_AUTO_STL
49  -D_GNU_SOURCE )
50
51if( CMAKE_SYSTEM_NAME STREQUAL Linux )
52  set( CASACORE_DEFINITIONS ${CASACORE_DEFINITIONS}
53    -D_FILE_OFFSET_BITS=64
54    -D_LARGEFILE_SOURCE
55    )
56endif()
57
58add_definitions( ${CASACORE_DEFINITIONS} )
59
60# set flags for cpp compiler
61set( CMAKE_CXX_FLAGS ${DEFAULT_CXX_FLAGS} )
62
63# environment dependent settings
64message( STATUS "CMAKE_SYSTEM = " ${CMAKE_SYSTEM} )
65message( STATUS "CMAKE_SYSTEM_PROCESSOR = " ${CMAKE_SYSTEM_PROCESSOR} )
66if( APPLE )
67   set( SO dylib )
68   if( CMAKE_SYSTEM MATCHES ^Darwin-10 )
69      if( NOT archflag )
70         if( EXISTS /opt/casa/darwin10-64b )
71            set( archflag x86_64 )
72         elseif( EXISTS /opt/casa/core2-apple-darwin10 )
73            set( archflag i386 )
74         else()
75            set( archflag x86_64 )
76         endif()
77      endif()
78      if( archflag STREQUAL x86_64 )
79         add_definitions( -DAIPS_64B )
80      endif()
81      execute_process( COMMAND ${CMAKE_CXX_COMPILER} --version
82                       COMMAND head -1
83                       COMMAND perl -pe "s|.*?(\\d+\\.\\d+)\\.\\d+$|$1|"
84                       OUTPUT_VARIABLE _cxx_version
85                       OUTPUT_STRIP_TRAILING_WHITESPACE )
86      if( NOT _cxx_version STREQUAL "4.4" )
87         set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -arch ${archflag}" )
88      endif()
89   endif()         
90elseif( CMAKE_SYSTEM_NAME STREQUAL Linux )
91   set( SO so )
92   add_definitions( -DAIPS_LINUX )
93   if( CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 )
94      add_definitions( -DAIPS_64B )
95      set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -Wno-deprecated" )
96   else()
97      set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -Wno-deprecated -Woverloaded-virtual" )
98   endif()
99endif()
100
101
102#
103# mode specific settings
104#
105# STANDALONE=ON   standalone build
106# STANDALONE=OFF  build with casa
107#
108set( CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake" )
109message( STATUS "CMAKE_MODULE_PATH = " ${CMAKE_MODULE_PATH} )
110if( STANDALONE )
111   include( standalone )
112else()
113   include( withcasa )
114endif()
115
116message( STATUS "CMAKE_INSTALL_PREFIX = " ${CMAKE_INSTALL_PREFIX} )
117
118
119#
120# casacore
121#
122unset( CASACORE_INCLUDE_DIR CACHE )
123unset( CASACORE_LIBRARIES CACHE )
124if( NOT USE_LIBCASACORE )
125   # use casacore libraries
126   set( _includename casa/aipsdef.h )
127   find_path( CASACORE_INCLUDE_DIR ${_includename}
128              PATHS ${CASACORE_PATHS}
129              PATH_SUFFIXES include include/casacore
130              NO_DEFAULT_PATH )
131   find_path( CASACORE_INCLUDE_DIR ${_includename} )
132   if( CASACORE_INCLUDE_DIR MATCHES "NOTFOUND$" )
133     message( FATAL_ERROR "${_includename} could not be found. Please check!" )
134   endif()
135   set( CASACORE_LIBS casa
136                      components
137                      coordinates
138                      fits
139                      images
140                      lattices
141                      measures
142                      mirlib
143                      ms
144                      msfits
145                      scimath
146                      scimath_f
147                      tables )
148   set( _casacore_libs "" )
149   foreach( _a ${CASACORE_LIBS} )
150      set( _libname libcasa_${_a}.${SO} )
151      unset( _casacore_lib CACHE )
152      find_library( _casacore_lib ${_libname}
153                    PATHS ${CASACORE_PATHS}
154                    PATH_SUFFIXES lib64 lib )
155      if( _casacore_lib MATCHES "NOTFOUND$" )
156         message( FATAL_ERROR "${_libname} could not be found. Please check!" )
157      else()
158         #list( APPEND _casacore_libs casa_${_a} )
159         list( APPEND _casacore_libs ${_casacore_lib} )
160      endif()
161   endforeach()
162   set( CASACORE_LIBRARIES ${_casacore_libs} )
163else()
164   # use libcasacore
165   set( _libname libcasacore.${SO} )
166   find_library( CASACORE_LIBRARIES ${_libname}
167                 PATHS ${CASACORE_PATHS}
168                 PATH_SUFFIXES lib64 lib )
169   if( CASACORE_LIBRARIES MATCHES "NOTFOUND$" )
170      message( FATAL_ERROR "${_libname} could not be found. Please check!" )
171   endif()
172   set( _includename casa/aipsdef.h )
173   find_path( CASACORE_INCLUDE_DIR ${_includename}
174              PATHS ${CASACORE_PATHS}
175              PATH_SUFFIXES include include/casacore
176              NO_DEFAULT_PATH )
177   find_path( CASACORE_INCLUDE_DIR ${_includename} )
178   if( CASACORE_INCLUDE_DIR MATCHES "NOTFOUND$" )
179     message( FATAL_ERROR "${_includename} could not be found. Please check!" )
180   endif()
181endif()
182message( STATUS "CASACORE_LIBRARIES = " ${CASACORE_LIBRARIES} )
183message( STATUS "CASACORE_INCLUDE_DIR = " ${CASACORE_INCLUDE_DIR} )
184unset( USE_LIBCASACORE CACHE )
185
186
187#
188# Python
189#
190if( STANDALONE )
191   include( FindPythonLibs )
192   if( NOT PYTHONLIBS_FOUND )
193      message( FATAL_ERROR "Python could not be found. Please check!" )
194   endif()
195
196   # Define pyroot
197   string( REGEX REPLACE "/[^/]+/[^/]+/?$" "" pyroot ${PYTHON_INCLUDE_DIRS} )
198
199   # find numpy
200   string( REGEX MATCH [0-9].[0-9] PYTHONV ${PYTHON_INCLUDE_DIRS} )
201   string( REPLACE "." "" PV ${PYTHONV} )
202   set( PYTHON_PREFIX ${PYTHON_INCLUDE_DIRS}/../.. )
203   find_path( NUMPY_INCLUDE_DIR numpy/npy_interrupt.h
204              PATHS
205                 ${PYTHON_PREFIX}/lib/python${PYTHONV}/site-packages/numpy/core
206                 ${PYTHON_PREFIX}/Library/Frameworks/Python.framework/Versions/${PYTHONV}
207                 ${PYTHON_PREFIX}/Library/Frameworks/Python.framework/Versions/${PYTHONV}/lib/python${PYTHONV}/site-packages/numpy/core
208              PATH_SUFFIXES include )
209   if( NUMPY_INCLUDE_DIR MATCHES "NOTFOUND$" )
210      message( FATAL_ERROR "numpy/npy_interrupt.h could not be found. Please check!" )
211   endif()
212   list( APPEND PYTHON_INCLUDE_DIRS ${NUMPY_INCLUDE_DIR} )
213
214   set( PYTHON_DEFINITIONS ${PYTHON_DEFINITIONS}
215      -DPYTHONROOT=\"${pyroot}\"
216      -DPYTHONVER=\"${PYTHONV}\"
217      -DPYVERSION=${PV} )
218else()
219   if( NOT PYTHON_FOUND )
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
248   endif()
249
250   if( 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*\")")
253   endif()
254
255   string( SUBSTRING ${PYTHON_LIBNAME} 0 3 PYTHONV )
256   string( REPLACE "." "" PV ${PYTHONV} )
257   set( 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
261   string( REGEX MATCH "/lib(64)?/lib${python_library}" _match ${PYTHON${PYTHON_LIBNAME}_LIBRARIES} )
262   if( _match )
263      string( REGEX REPLACE "/lib(64)?/lib${python_library}.*" "" python_prefix ${PYTHON${PYTHON_LIBNAME}_LIBRARIES} )
264   else()
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} )
268   endif()
269
270   # The python version and prefix is known, do the actual search
271   if( NOT PYTHON_FOUND )
272      message( STATUS "Looking for PYTHON version ${PYTHONV}.x in ${python_prefix}" )
273   endif()
274
275   casa_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
288   set( 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.
291   string( REGEX REPLACE "/[^/]+/[^/]+/?$" "" pyroot ${PYTHON_Python.h} )
292
293   set( PYTHON_DEFINITIONS ${PYTHON_DEFINITIONS}
294      -DAIPSROOT=\"${CMAKE_SOURCE_DIR}\"
295      -DAIPSARCH=\"${arch}\"
296      -DAIPSSITE=\"garching\"
297      -DPYTHONROOT=\"${pyroot}\"
298      -DPYTHONVER=\"${PYTHONV}\"
299      -DPYVERSION=${PV} )
300endif()
301message( STATUS "PYTHON_INCLUDE_DIRS = " ${PYTHON_INCLUDE_DIRS} )
302message( STATUS "PYTHON_LINRARIES = " ${PYTHON_LIBRARIES} )
303message( STATUS "PYTHONV = " ${PYTHONV} )
304
305
306#
307# DL
308#
309set( DL_LIBRARIES ${CMAKE_DL_LIBS} CACHE STRING "dl libraries" FORCE )
310if( DL_LIBRARIES STREQUAL "dl" )
311  set( DL_LIBRARIES "-ldl" CACHE STRING "dl libraries" FORCE )
312endif()
313message( STATUS "DL_LIBRARIES = " ${DL_LIBRARIES} )
314
315
316#
317# BLAS
318#
319find_library( BLAS_LIBRARIES libblas.${SO} )
320if ( BLAS_LIBRARIES MATCHES "NOTFOUND$" )
321   message( FATAL_ERROR "blas could not be found. Please check!" )
322endif()
323message( STATUS "BLAS_LIBRARIES = " ${BLAS_LIBRARIES} )
324
325
326#
327# LAPACK
328#
329find_library( LAPACK_LIBRARIES liblapack.${SO} )
330if ( LAPACK_LIBRARIES MATCHES "NOTFOUND$" )
331   message( FATAL_ERROR "lapack could not be found. Please check!" )
332endif()
333message( STATUS "LAPACK_LIBRARIES = " ${LAPACK_LIBRARIES} )
334
335
336#
337# Boost
338#
339set( boost_components python )
340find_package( Boost REQUIRED ${boost_components} )
341if( NOT Boost_FOUND )
342  message( FATAL_ERROR "Boost could not be found. Please check!" )
343endif()
344message( STATUS "BOOST_INCLUDE_DIR = " ${Boost_INCLUDE_DIR} )
345message( STATUS "BOOST_LIBRARIES = " ${Boost_LIBRARIES} )
346
347
348#
349# cfitsio
350#
351if( STANDALONE )
352   find_path( CFITSIO_INCLUDE_DIRS fitsio.h
353              PATH_SUFFIXES cfitsio )
354   if( CFITSIO_INCLUDE_DIRS MATCHES "NOTFOUND$" )
355      message( FATAL_ERROR "fitsio.h could not be found. Please check!" )
356   endif()
357   find_library( CFITSIO_LIBRARIES libcfitsio.${SO}
358                 PATHS /usr/local /usr
359                 PATH_SUFFIXES lib64 lib )
360   if( CFITSIO_LIBRARIES MATCHES "NOTFOUND$" )
361      message( FATAL_ERROR "libcfitsio.so could not be found. Please check!" )
362   endif()
363else()
364   casa_find( CFITSIO
365              VERSION 3.006
366              INCLUDES fitsio.h fitsio2.h
367              INCLUDES_SUFFIXES cfitsio
368              LIBS cfitsio
369              CPP_VERSION CFITSIO_VERSION
370              RUN_VERSION "(ffvers(&v), v)" )
371endif()
372message( STATUS "CFITSIO_INCLUDE_DIRS = " ${CFITSIO_INCLUDE_DIRS} )
373message( STATUS "CFITSIO_LIBRARIES = " ${CFITSIO_LIBRARIES} )
374
375
376#
377# Fortran
378#
379if( NOT FORTRAN_LIBRARIES )
380
381  message( STATUS "Looking for Fortran runtime libraries" )
382  set( _try  ${CMAKE_BINARY_DIR}/try_fortran.cc )
383  file( WRITE ${_try}
384    "int main() { return 0; }\n"
385    )
386 
387  if( _gfortran_lib_path )
388    try_compile( _have_gfortran ${CMAKE_BINARY_DIR} ${_try}
389      CMAKE_FLAGS -Wdev "-DCMAKE_EXE_LINKER_FLAGS=${_gfortran_lib_path}"
390      )
391  else()
392    try_compile( _have_gfortran ${CMAKE_BINARY_DIR} ${_try}
393      CMAKE_FLAGS -Wdev "-DCMAKE_EXE_LINKER_FLAGS=-lgfortran"
394      )
395  endif()
396  try_compile( _have_g2c ${CMAKE_BINARY_DIR} ${_try}
397    CMAKE_FLAGS -Wdev "-DCMAKE_EXE_LINKER_FLAGS=-lg2c"
398    )
399 
400  if( _have_gfortran )
401    if( _gfortran_lib_path )
402      set( FORTRAN_LIBRARIES ${_gfortran_lib_path}
403        CACHE STRING "Fortran library linker option" FORCE )
404    else()
405      set( FORTRAN_LIBRARIES -lgfortran
406        CACHE STRING "Fortran library linker option" FORCE )
407    endif()
408    message( STATUS "Looking for Fortran runtime libraries -- ${FORTRAN_LIBRARIES}" )
409  elseif( _have_g2c )
410    set( FORTRAN_LIBRARIES -lg2c
411      CACHE STRING "Fortran library linker option" FORCE )
412    message( STATUS "Looking for Fortran runtime libraries -- ${FORTRAN_LIBRARIES}" )
413  else()
414    set( FORTRAN_LIBRARIES ""
415      CACHE STRING "Fortran library linker option" FORCE )
416    message( STATUS "Looking for Fortran runtime libraries -- <none>" )
417    # Not a fatal error because it might work, if all Fortran dependencies were
418    # already linked statically to the Fortran runtime...
419  endif()
420endif()
421
422
423#
424# RPFITS
425#
426if ( STANDALONE )
427   find_path( RPFITS_INCLUDE_DIRS RPFITS.h
428              PATHS /usr/local /usr
429              PATH_SUFFIXES include )
430   if( RPFITS_INCLUDE_DIRS MATCHES "NOTFOUND$" )
431      message( FATAL_ERROR "RPFITS.h could not be found. Please check!" )
432   endif()
433   find_library( RPFITS_LIBRARIES librpfits.so
434                 PATHS /usr/local /usr
435                 PATH_SUFFIXES lib64 lib )
436   if( RPFITS_LIBRARIES MATCHES "NOTFOUND$" )
437      message( FATAL_ERROR "librpfits.so could not be found. Please check!" )
438   endif()
439   list( APPEND RPFITS_LIBRARIES ${FORTRAN_LIBRARIES} )
440else()
441   casa_find( RPFITS
442              VERSION 2.11
443              INCLUDES RPFITS.h
444              LIBS rpfits
445              RUN_VERSION names_.rpfitsversion
446              DEPENDS FORTRAN )
447endif()
448message( STATUS "RPFITS_INCLUDE_DIRS = " ${RPFITS_INCLUDE_DIRS} )
449message( STATUS "RPFITS_LIBRARIES = " ${RPFITS_LIBRARIES} )
450
451
452#
453# wcslib
454#
455set( _wcslib libwcs.${SO} )
456set( _wcs_version 4.3 )
457find_library( WCSLIB ${_wcslib}
458              PATHS ${WCSLIB_PATHS}
459              PATH_SUFFIXES lib64 lib )
460if( WCSLIB MATCHES "NOTFOUND$" )
461   message( STATUS "${_wcslib} could not be found." )
462   unset( _wcslib CACHE )
463   unset( WCSLIB CACHE )
464   set( _wcslib libwcs.${_wcs_version}.${SO} )
465   message( STATUS "Try to find ${_wcslib}..." )
466   find_library( WCSLIB ${_wcslib}
467                 PATHS ${WCSLIB_PATHS}
468                 PATH_SUFFIXES lib64 lib )
469   if( WCSLIB MATCHES "NOTFOUND$" )
470      message( FATAL_ERROR "${_wcslib} could not be found. Please check!" )
471   endif()
472endif()
473message( STATUS "WCSLIB = " ${WCSLIB} )
474find_path( WCSLIB_INCLUDE_DIR wcslib/wcs.h
475           PATHS ${WCSLIB_PATHS}
476           PATH_SUFFIXES include )
477if( WCSLIB_INCLUDE_DIR MATCHES "NOTFOUND$" )
478   message( FATAL_ERROR "wcs.h could not be found. Please check!" )
479endif()
480message( STATUS "WCSLIB_INCLUDE_DIR = " ${WCSLIB_INCLUDE_DIR} )
481
482
483#
484# common include path
485#
486include_directories( ${CASACORE_INCLUDE_DIR}
487                     ${Boost_INCLUDE_DIR}
488                     ${PYTHON_INCLUDE_DIRS}
489                     ${WCSLIB_INCLUDE_DIR}
490                     ${CFITSIO_INCLUDE_DIRS}
491                     ${RPFITS_INCLUDE_DIRS} )
492
493
494#
495# install directory
496#
497set( EXEC_INSTALL_DIR bin )
498set( LIB_INSTALL_DIR lib )
499set( PYTHON_INSTALL_DIR python/${PYTHONV}/asap )
500set( SHARED_INSTALL_DIR share/asap )
501
502
503#
504# libraries and executables
505#
506set( ASAPLIB asap )
507set( PYRAPLIB pyrap )
508set( ATNFLIB atnf )
509set( ASAP2TO3 asap2to3 )
510
511#
512# always install by default
513#
514add_custom_target( inst ALL ${CMAKE_BUILD_TOOL} install/fast )
515
516#
517# subdirectories
518#
519asap_add_subdirectory()
Note: See TracBrowser for help on using the repository browser.