source: trunk/CMakeLists.txt @ 3035

Last change on this file since 3035 was 3035, checked in by Kana Sugimoto, 9 years ago

New Development: Yes

JIRA Issue: Yes (CAS-7383))

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): asap

Description: use libcasa_python instead of pyrap in cmake.


File size: 22.7 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 )
15option( PKSMS
16        "set ON to diable to build PKSMS2reader/writer"
17        OFF )
18message( STATUS "USE_LIBCASACORE = " ${USE_LIBCASACORE} )
19message( STATUS "STANDALONE = " ${STANDALONE} )
20message( STATUS "PKSMS = " ${PKSMS} )
21
22# Use casapy's fork of casacore
23if ( NOT STANDALONE )
24  add_definitions( -DUSE_CASAPY )
25endif ()
26
27# Define compiler paths on OSX 10.5. This must be done before invoking project()
28if( APPLE )
29    if( EXISTS            /opt/casa/core2-apple-darwin8/3rd-party/bin/gfortran )
30        set( CMAKE_Fortran_COMPILER /opt/casa/core2-apple-darwin8/3rd-party/bin/gfortran )
31        set( CMAKE_CXX_COMPILER     /opt/casa/core2-apple-darwin8/3rd-party/bin/g++ )
32    elseif( EXISTS        /opt/local/bin/gfortran )
33        set( CMAKE_Fortran_COMPILER /opt/local/bin/gfortran )
34    elseif( EXISTS        /opt/local/bin/gfortran-mp-4.4 )
35        set( CMAKE_Fortran_COMPILER /opt/local/bin/gfortran-mp-4.4 )
36        if( EXISTS /opt/local/bin/g++-mp-4.4 )
37            set( CMAKE_CXX_COMPILER /opt/local/bin/g++-mp-4.4 )
38        endif()
39    endif()
40endif()
41
42
43# project name is ASAP
44project( ASAP )
45
46
47#
48# build type and their flags
49#
50# CMAKE_BUILD_TYPE (Release, Debug, RelWithDebInfo, MinSizeRel, Profile)
51# default is RelWithDebInfo
52#
53if ( NOT CMAKE_BUILD_TYPE )
54   set( CMAKE_BUILD_TYPE RelWithDebInfo )
55endif()
56message( STATUS "CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE} )
57
58# flags for Debug build
59if ( CMAKE_BUILD_TYPE STREQUAL Debug )
60   add_definitions( -DAIPS_DEBUG )
61endif()
62set( CMAKE_CXX_FLAGS_DEBUG "-ggdb3 -O0 -fno-omit-frame-pointer" )
63
64# flags for Profile build
65set( CMAKE_CXX_FLAGS_PROFILE "-g -O2 -pg -fprofile-arcs -fno-omit-frame-pointer" )
66
67
68# flags for Release and MinSizeRel build
69if ( APPLE )
70    # OS X
71    # On 10.8 (Darwin-12) with llvm clang, -s option for linker
72    # causes link error. This may be because that -s option is
73    # obsolete and is different behavior from Linux.
74    if ( CMAKE_SYSTEM MATCHES ^Darwin-11 AND NOT LLVMCOMPILER )
75        set( CMAKE_SHARED_LINKER_FLAGS_RELEASE "-Wl,-s" )
76        set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-s" )
77        set( CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "-Wl,-s" )
78        set( CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-Wl,-s" )
79    endif()
80else()
81    # Linux
82    set( CMAKE_SHARED_LINKER_FLAGS_RELEASE "-Wl,-s" )
83    set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-s" )
84    set( CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "-Wl,-s" )
85    set( CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-Wl,-s" )
86endif()
87
88if ( DEFINED CXX_FLAGS_TAIL_END )
89   set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CXX_FLAGS_TAIL_END}" )
90   set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CXX_FLAGS_TAIL_END}" )
91   set( CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${CXX_FLAGS_TAIL_END}" )
92   set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CXX_FLAGS_TAIL_END}" )
93   set( CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} ${CXX_FLAGS_TAIL_END}" )
94endif()
95
96# default flags
97set( DEFAULT_CXX_FLAGS
98     "-pipe -Wall -Wextra -Wno-non-template-friend -Wcast-align -Wno-comment" )
99
100# additional flag for fortran complex div/mul rules.
101include( CheckCXXCompilerFlag )
102include( CheckCCompilerFlag )
103check_cxx_compiler_flag( -fcx-fortran-rules HAS_GXX_FORTRAN_RULES )
104check_c_compiler_flag( -fcx-fortran-rules HAS_GCC_FORTRAN_RULES )
105if( HAS_GXX_FORTRAN_RULES )
106     set( DEFAULT_CXX_FLAGS "-fcx-fortran-rules ${DEFAULT_CXX_FLAGS}")
107endif()
108if( HAS_GCC_FORTRAN_RULES )
109     set( CMAKE_C_FLAGS "-fcx-fortran-rules ${CMAKE_C_FLAGS}" )
110endif()
111
112find_package( OpenMP )
113if( OPENMP_FOUND )
114   set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
115endif()
116
117# environment dependent settings
118message( STATUS "CMAKE_SYSTEM = " ${CMAKE_SYSTEM} )
119message( STATUS "CMAKE_SYSTEM_PROCESSOR = " ${CMAKE_SYSTEM_PROCESSOR} )
120if( APPLE )
121   set( SO dylib )
122   if( CMAKE_SYSTEM MATCHES ^Darwin-10 OR
123                CMAKE_SYSTEM MATCHES ^Darwin-11 )
124      if( NOT archflag )
125         if( EXISTS /opt/casa/01 )
126            set( archflag x86_64 )
127         elseif( EXISTS /opt/casa/darwin11 )
128            set( archflag x86_64 )
129         elseif( EXISTS /opt/casa/darwin10-64b )
130            set( archflag x86_64 )
131         elseif( EXISTS /opt/casa/core2-apple-darwin10 )
132            set( archflag i386 )
133         else()
134            set( archflag x86_64 )
135         endif()
136      endif()
137      if( archflag STREQUAL x86_64 )
138         add_definitions( -DAIPS_64B )
139      endif()
140      execute_process( COMMAND ${CMAKE_CXX_COMPILER} --version
141                       COMMAND head -1
142                       COMMAND perl -pe "s|.*?(\\d+\\.\\d+)\\.\\d+$|$1|"
143                       OUTPUT_VARIABLE _cxx_version
144                       OUTPUT_STRIP_TRAILING_WHITESPACE )
145      if( NOT _cxx_version STREQUAL "4.4" )
146         set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -arch ${archflag}" )
147      endif()
148   endif()
149elseif( CMAKE_SYSTEM_NAME STREQUAL Linux )
150   set( SO so )
151   add_definitions( -DAIPS_LINUX )
152   if( CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 )
153      add_definitions( -DAIPS_64B )
154      set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -Wno-deprecated" )
155   else()
156      set( DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -Wno-deprecated -Woverloaded-virtual" )
157   endif()
158endif()
159
160# set flags for cpp compiler
161set( CMAKE_CXX_FLAGS ${DEFAULT_CXX_FLAGS} )
162
163
164#
165# casacore definitions
166#
167set( CASACORE_DEFINITIONS ${CASACORE_DEFINITIONS}
168  -DCASA_USECASAPATH
169  -DCASACORE_NEEDS_RETHROW
170  -DAIPS_STDLIB
171  -DAIPS_AUTO_STL
172  -D_GNU_SOURCE )
173
174if( CMAKE_SYSTEM_NAME STREQUAL Linux )
175  set( CASACORE_DEFINITIONS ${CASACORE_DEFINITIONS}
176    -D_FILE_OFFSET_BITS=64
177    -D_LARGEFILE_SOURCE
178    )
179endif()
180
181add_definitions( ${CASACORE_DEFINITIONS} )
182
183#
184# mode specific settings
185#
186# STANDALONE=ON   standalone build
187# STANDALONE=OFF  build with casa
188#
189set( CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake" )
190message( STATUS "CMAKE_MODULE_PATH = " ${CMAKE_MODULE_PATH} )
191if( STANDALONE )
192   include( standalone )
193else()
194   include( withcasa )
195endif()
196
197message( STATUS "CMAKE_INSTALL_PREFIX = " ${CMAKE_INSTALL_PREFIX} )
198
199
200#
201# casacore
202#
203unset( CASACORE_INCLUDE_DIR CACHE )
204unset( CASACORE_LIBRARIES CACHE )
205if( NOT USE_LIBCASACORE )
206   # use casacore libraries
207   set( _includename casa/aipsdef.h )
208   find_path( CASACORE_INCLUDE_DIR ${_includename}
209              PATHS ${CASACORE_PATHS}
210              PATH_SUFFIXES include include/casacore
211              NO_DEFAULT_PATH )
212   find_path( CASACORE_INCLUDE_DIR ${_includename} )
213   if( CASACORE_INCLUDE_DIR MATCHES "NOTFOUND$" )
214     message( FATAL_ERROR "${_includename} could not be found. Please check!" )
215   endif()
216   set( CASACORE_LIBS casa
217                      coordinates
218                      fits
219                      images
220                      lattices
221                      measures
222                      mirlib
223                      ms
224                      msfits
225                      scimath
226                      scimath_f
227                      tables
228                      python )
229   set( _casacore_libs "" )
230   foreach( _a ${CASACORE_LIBS} )
231      set( _libname libcasa_${_a}.${SO} )
232      unset( _casacore_lib CACHE )
233      find_library( _casacore_lib ${_libname}
234                    PATHS ${CASACORE_PATHS}
235                    PATH_SUFFIXES lib64 lib )
236      if( _casacore_lib MATCHES "NOTFOUND$" )
237         message( FATAL_ERROR "${_libname} could not be found. Please check!" )
238      else()
239         #list( APPEND _casacore_libs casa_${_a} )
240         list( APPEND _casacore_libs ${_casacore_lib} )
241      endif()
242   endforeach()
243   set ( _libname libcomponents.${SO} )
244   unset( _casacore_lib CACHE )
245   find_library( _casacore_lib ${_libname}
246             PATHS ${CASACORE_PATHS}
247              PATH_SUFFIXES lib64 lib )
248   if( _casacore_lib MATCHES "NOTFOUND$" )
249       message( FATAL_ERROR "${_libname} could not be found. Please check!" )
250   else()
251       list( APPEND _casacore_libs ${_casacore_lib} )
252   endif()
253   set( CASACORE_LIBRARIES ${_casacore_libs} )
254else()
255   # use libcasacore
256   set( _libname libcasacore.${SO} )
257   find_library( CASACORE_LIBRARIES ${_libname}
258                 PATHS ${CASACORE_PATHS}
259                 PATH_SUFFIXES lib64 lib )
260   if( CASACORE_LIBRARIES MATCHES "NOTFOUND$" )
261      message( FATAL_ERROR "${_libname} could not be found. Please check!" )
262   endif()
263   set( _includename casa/aipsdef.h )
264   string( REGEX REPLACE /[^/]+/[^/]+/?$ "" _coreroot ${CASACORE_LIBRARIES} )
265   find_path( CASACORE_INCLUDE_DIR ${_includename}
266              PATHS ${_coreroot}
267              PATH_SUFFIXES include include/casacore
268              NO_DEFAULT_PATH )
269   find_path( CASACORE_INCLUDE_DIR ${_includename}
270              PATHS ${CASACORE_PATHS}
271              PATH_SUFFIXES include include/casacore
272              NO_DEFAULT_PATH )
273   find_path( CASACORE_INCLUDE_DIR ${_includename} )
274   if( CASACORE_INCLUDE_DIR MATCHES "NOTFOUND$" )
275     message( FATAL_ERROR "${_includename} could not be found. Please check!" )
276   endif()
277endif()
278message( STATUS "CASACORE_LIBRARIES = " ${CASACORE_LIBRARIES} )
279message( STATUS "CASACORE_INCLUDE_DIR = " ${CASACORE_INCLUDE_DIR} )
280unset( USE_LIBCASACORE CACHE )
281
282#
283# Python
284#
285if( STANDALONE )
286   include( FindPythonLibs )
287   if( NOT PYTHONLIBS_FOUND )
288      message( FATAL_ERROR "Python could not be found. Please check!" )
289   endif()
290
291   # Define pyroot
292   string( REGEX REPLACE "/[^/]+/[^/]+/?$" "" pyroot ${PYTHON_INCLUDE_DIRS} )
293
294   # find numpy
295   string( REGEX MATCH [0-9].[0-9] PYTHONV ${PYTHON_INCLUDE_DIRS} )
296   string( REPLACE "." "" PV ${PYTHONV} )
297   find_path( NUMPY_INCLUDE_DIR numpy/npy_interrupt.h
298              PATHS
299                 ${pyroot}/lib/python${PYTHONV}/site-packages/numpy/core
300                 ${pyroot}/Library/Frameworks/Python.framework/Versions/${PYTHONV}
301                 ${pyroot}/Library/Frameworks/Python.framework/Versions/${PYTHONV}/lib/python${PYTHONV}/site-packages/numpy/core
302              PATH_SUFFIXES include )
303   if( NUMPY_INCLUDE_DIR MATCHES "NOTFOUND$" )
304      message( FATAL_ERROR "numpy/npy_interrupt.h could not be found. Please check!" )
305   endif()
306   list( APPEND PYTHON_INCLUDE_DIRS ${NUMPY_INCLUDE_DIR} )
307
308   set( PYTHON_DEFINITIONS ${PYTHON_DEFINITIONS}
309      -DPYTHONROOT=\"${pyroot}\"
310      -DPYTHONVER=\"${PYTHONV}\"
311      -DPYVERSION=${PV} )
312else()
313   # with CASA
314   if( NOT PYTHON_FOUND )
315      if ( NOT PYTHON_LIBNAME )
316         #set( _names 2.9 2.8 2.7 2.6 2.5.2 2.5 )
317         set( _names 2.7 2.6 2.5.2 2.5 )
318         # OSX 10.7 has Python2.7 by default. CASA has't yet supported python > 2.6 anyway.
319         # (The library named libpython.2.5.2.dylib seems to exist only in the CASA world.)
320      else()
321         set( _names ${PYTHON_LIBNAME} )
322      endif()
323
324      set( _found False )
325      foreach( _v ${_names} )
326
327         casa_find(
328            PYTHON${_v}
329            #PREFIX_HINTS ${PYTHON_ROOT_DIR}
330            LIBS python${_v}
331            NO_REQUIRE
332         )
333
334         if( PYTHON${_v}_FOUND )
335            set( PYTHON_LIBNAME ${_v} )
336            set( _found True )
337            break()
338         endif()
339
340      endforeach()
341 
342      if( NOT _found )
343         message( FATAL_ERROR "Could not find any PYTHON library with version one of ${_names}. Please check!" )
344      endif()
345
346   endif()
347
348   if( NOT PYTHON_LIBNAME )
349      # Found Python, but PYTHON_LIBNAME is undefined, that is impossible.
350      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*\")")
351   endif()
352
353   string( SUBSTRING ${PYTHON_LIBNAME} 0 3 PYTHONV )
354   string( REPLACE "." "" PV ${PYTHONV} )
355   set( python_library python${PYTHON_LIBNAME} )
356
357   # Form the Python install prefix by stripping away "lib/libpython2.5.2.dylib" (example) from
358   # the full python library path
359   string( REGEX MATCH "/lib(64)?/lib${python_library}" _match ${PYTHON${PYTHON_LIBNAME}_LIBRARIES} )
360   if( _match )
361      string( REGEX REPLACE "/lib(64)?/lib${python_library}.*" "" python_prefix ${PYTHON${PYTHON_LIBNAME}_LIBRARIES} )
362   else()
363      # Python library was not in a lib(64) directory!
364      message( WARNING "Python library path \"${PYTHON${PYTHON_LIBNAME}_LIBRARIES}\" does not contain \"/lib(64)/lib${python_library}\"" )
365      set( python_prefix ${casa_packages} )
366   endif()
367
368   #
369   # For some unknown reason cmake sets the /usr for Lion
370   #
371   if( APPLE )
372      set( python_prefix ${casa_packages} )
373   endif()
374
375   # The python version and prefix is known, do the actual search
376   if( NOT PYTHON_FOUND )
377      message( STATUS "Looking for PYTHON version ${PYTHONV}.x in ${python_prefix}" )
378   endif()
379
380   casa_find( PYTHON
381      VERSION 2.5    # minimum required
382      INCLUDES Python.h
383         numpy/npy_interrupt.h   # for numpy
384      INCLUDES_SUFFIXES python${PYTHONV}
385      PREFIX_HINTS
386         ${python_prefix}/lib/python${PYTHONV}/site-packages/numpy/core
387         ${python_prefix}/Library/Frameworks/Python.framework/Versions/${PYTHONV}
388         ${python_prefix}/Library/Frameworks/Python.framework/Versions/${PYTHONV}/lib/python${PYTHONV}/site-packages/numpy/core
389      LIBS ${python_library}
390      CPP_VERSION PY_VERSION )
391
392   # Store PYTHON_LIBNAME in the cache
393   set( PYTHON_LIBNAME ${PYTHON_LIBNAME} CACHE STRING "Python major and minor version to use" FORCE )
394
395   # Define pyroot to two directory levels above Python.h.
396   string( REGEX REPLACE "/[^/]+/[^/]+/?$" "" pyroot ${PYTHON_Python.h} )
397
398   set( PYTHON_DEFINITIONS ${PYTHON_DEFINITIONS}
399      -DAIPSROOT=\"${CMAKE_SOURCE_DIR}\"
400      -DAIPSARCH=\"${arch}\"
401      -DAIPSSITE=\"garching\"
402      -DPYTHONROOT=\"${pyroot}\"
403      -DPYTHONVER=\"${PYTHONV}\"
404      -DPYVERSION=${PV} )
405endif()
406message( STATUS "PYTHON_INCLUDE_DIRS = " ${PYTHON_INCLUDE_DIRS} )
407message( STATUS "PYTHON_LINRARIES = " ${PYTHON_LIBRARIES} )
408message( STATUS "PYTHONV = " ${PYTHONV} )
409
410
411#
412# DL
413#
414set( DL_LIBRARIES ${CMAKE_DL_LIBS} CACHE STRING "dl libraries" FORCE )
415if( DL_LIBRARIES STREQUAL "dl" )
416  set( DL_LIBRARIES "-ldl" CACHE STRING "dl libraries" FORCE )
417endif()
418message( STATUS "DL_LIBRARIES = " ${DL_LIBRARIES} )
419
420
421#
422# BLAS
423#
424find_library( BLAS_LIBRARIES libblas.${SO} )
425if ( BLAS_LIBRARIES MATCHES "NOTFOUND$" )
426   message( FATAL_ERROR "blas could not be found. Please check!" )
427endif()
428message( STATUS "BLAS_LIBRARIES = " ${BLAS_LIBRARIES} )
429
430
431#
432# LAPACK
433#
434find_library( LAPACK_LIBRARIES liblapack.${SO} )
435if ( LAPACK_LIBRARIES MATCHES "NOTFOUND$" )
436   message( FATAL_ERROR "lapack could not be found. Please check!" )
437endif()
438message( STATUS "LAPACK_LIBRARIES = " ${LAPACK_LIBRARIES} )
439
440
441#
442# Boost
443#
444set( boost_components python )
445if( NOT STANDALONE )
446  set( boost_components ${boost_components} system )
447endif()
448find_package( Boost REQUIRED ${boost_components} )
449if( NOT Boost_FOUND )
450  message( FATAL_ERROR "Boost could not be found. Please check!" )
451endif()
452message( STATUS "BOOST_INCLUDE_DIR = " ${Boost_INCLUDE_DIR} )
453message( STATUS "BOOST_LIBRARIES = " ${Boost_LIBRARIES} )
454
455
456#
457# cfitsio
458#
459if( STANDALONE )
460   find_path( CFITSIO_INCLUDE_DIRS fitsio.h
461              PATH_SUFFIXES cfitsio )
462   if( CFITSIO_INCLUDE_DIRS MATCHES "NOTFOUND$" )
463      message( FATAL_ERROR "fitsio.h could not be found. Please check!" )
464   endif()
465   string( REGEX REPLACE "/[^/]+/?$" "" CFITSIO_ROOT ${CFITSIO_INCLUDE_DIRS} )
466   message( STATUS "CFITSIO_ROOT=" ${CFITSIO_ROOT} )
467   find_library( CFITSIO_LIBRARIES libcfitsio.${SO}
468                 PATHS ${CFITSIO_ROOT}
469                 PATH_SUFFIXES lib64 lib
470                 NO_DEFAULT_PATH )
471   if( CFITSIO_LIBRARIES MATCHES "NOTFOUND$" )
472      find_library( CFITSIO_LIBRARIES libcfitsio.a
473                    PATHS ${CFITSIO_ROOT}
474                    PATH_SUFFIXES lib64 lib
475                    NO_DEFAULT_PATH )
476   endif()
477   find_library( CFITSIO_LIBRARIES libcfitsio.${SO}
478                 PATHS /usr/local /usr
479                 PATH_SUFFIXES lib64 lib )
480   if( CFITSIO_LIBRARIES MATCHES "NOTFOUND$" )
481      message( FATAL_ERROR "libcfitsio.so could not be found. Please check!" )
482   endif()
483else()
484   casa_find( CFITSIO
485              VERSION 3.006
486              INCLUDES fitsio.h fitsio2.h
487              INCLUDES_SUFFIXES cfitsio
488              LIBS cfitsio
489              CPP_VERSION CFITSIO_VERSION
490              RUN_VERSION "(ffvers(&v), v)" )
491endif()
492message( STATUS "CFITSIO_INCLUDE_DIRS = " ${CFITSIO_INCLUDE_DIRS} )
493message( STATUS "CFITSIO_LIBRARIES = " ${CFITSIO_LIBRARIES} )
494
495
496#
497# Fortran
498#
499if( NOT FORTRAN_LIBRARIES )
500
501  message( STATUS "Looking for Fortran runtime libraries" )
502  set( _try  ${CMAKE_BINARY_DIR}/try_fortran.cc )
503  file( WRITE ${_try}
504    "int main() { return 0; }\n"
505    )
506
507  execute_process( COMMAND ${CMAKE_Fortran_COMPILER} -print-search-dirs
508                   COMMAND perl -e "$found = 0; while(<>) {  s|\n||g; if( m|^libraries:\\s*=(.*?$)| ) { foreach $d (split(':',$1) ) { if ( -e \"$d/libgfortran${CMAKE_SHARED_LIBRARY_SUFFIX}\" ) { print \"$d/libgfortran${CMAKE_SHARED_LIBRARY_SUFFIX}\"; $found = 1; break; }} break if $found; } break if $found;}"
509                   OUTPUT_VARIABLE _gfortran_lib_path
510                   OUTPUT_STRIP_TRAILING_WHITESPACE )
511
512  if( _gfortran_lib_path )
513    try_compile( _have_gfortran ${CMAKE_BINARY_DIR} ${_try}
514      CMAKE_FLAGS -Wdev "-DCMAKE_EXE_LINKER_FLAGS=${_gfortran_lib_path}"
515      )
516  else()
517    try_compile( _have_gfortran ${CMAKE_BINARY_DIR} ${_try}
518      CMAKE_FLAGS -Wdev "-DCMAKE_EXE_LINKER_FLAGS=-lgfortran"
519      )
520  endif()
521  try_compile( _have_g2c ${CMAKE_BINARY_DIR} ${_try}
522    CMAKE_FLAGS -Wdev "-DCMAKE_EXE_LINKER_FLAGS=-lg2c"
523    )
524 
525  if( _have_gfortran )
526    if( _gfortran_lib_path )
527      set( FORTRAN_LIBRARIES ${_gfortran_lib_path}
528        CACHE STRING "Fortran library linker option" FORCE )
529    else()
530      set( FORTRAN_LIBRARIES -lgfortran
531        CACHE STRING "Fortran library linker option" FORCE )
532    endif()
533    message( STATUS "Looking for Fortran runtime libraries -- ${FORTRAN_LIBRARIES}" )
534  elseif( _have_g2c )
535    set( FORTRAN_LIBRARIES -lg2c
536      CACHE STRING "Fortran library linker option" FORCE )
537    message( STATUS "Looking for Fortran runtime libraries -- ${FORTRAN_LIBRARIES}" )
538  else()
539    set( FORTRAN_LIBRARIES ""
540      CACHE STRING "Fortran library linker option" FORCE )
541    message( STATUS "Looking for Fortran runtime libraries -- <none>" )
542    # Not a fatal error because it might work, if all Fortran dependencies were
543    # already linked statically to the Fortran runtime...
544  endif()
545endif()
546
547# X11.
548if( NOT APPLE )
549  find_package( X11 REQUIRED )
550  # Rename
551  set( X11_INCLUDE_DIRS ${X11_INCLUDE_DIR} )
552endif()
553
554# PGPLOT (FORTRAN plotting package).
555# depends on X11
556# not require in standalone mode
557if( NOT STANDALONE )
558  if( APPLE )
559    set( _deps FORTRAN )
560  else()
561    set( _deps X11 FORTRAN )
562  endif()
563  if (CMAKE_SYSTEM MATCHES ^Darwin-11 AND NOT LLVMCOMPILER )
564     set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-undefined -Wl,error -framework AppKit -lgfortran" )
565  else()
566     if (APPLE)
567        set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-undefined -Wl,error -framework AppKit" )
568     else()
569        set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-undefined -Wl,error" )
570     endif()
571  endif()
572  casa_find( PGPLOT
573    VERSION 5.3.1
574    PREFIX_HINTS ${PGPLOT_ROOT_DIR}
575    INCLUDES cpgplot.h
576    LIBS pgplot${pgplot_ext} cpgplot${pgplot_ext}
577    DEPENDS ${_deps} )
578
579  add_definitions( -DENABLE_PLOTTER2 )
580endif()
581
582#
583# RPFITS
584#
585if ( STANDALONE )
586   find_path( RPFITS_INCLUDE_DIRS RPFITS.h
587              PATHS /usr/local /usr
588              PATH_SUFFIXES include )
589   if( RPFITS_INCLUDE_DIRS MATCHES "NOTFOUND$" )
590      message( FATAL_ERROR "RPFITS.h could not be found. Please check!" )
591   endif()
592   find_library( RPFITS_LIBRARIES librpfits.so
593                 PATHS /usr/local /usr
594                 PATH_SUFFIXES lib64 lib )
595   if( RPFITS_LIBRARIES MATCHES "NOTFOUND$" )
596      message( FATAL_ERROR "librpfits.so could not be found. Please check!" )
597   endif()
598   list( APPEND RPFITS_LIBRARIES ${FORTRAN_LIBRARIES} )
599else()
600   casa_find( RPFITS
601              VERSION 2.11
602              INCLUDES RPFITS.h
603              LIBS rpfits
604              RUN_VERSION names_.rpfitsversion
605              DEPENDS FORTRAN )
606endif()
607message( STATUS "RPFITS_INCLUDE_DIRS = " ${RPFITS_INCLUDE_DIRS} )
608message( STATUS "RPFITS_LIBRARIES = " ${RPFITS_LIBRARIES} )
609
610
611#
612# wcslib
613#
614set( _wcslib libwcs.${SO} )
615set( _wcs_version 4.3 )
616find_library( WCSLIB ${_wcslib}
617              PATHS ${WCSLIB_PATHS}
618              PATH_SUFFIXES lib64 lib )
619if( WCSLIB MATCHES "NOTFOUND$" )
620   message( STATUS "${_wcslib} could not be found." )
621   unset( _wcslib CACHE )
622   unset( WCSLIB CACHE )
623   set( _wcslib libwcs.${_wcs_version}.${SO} )
624   message( STATUS "Try to find ${_wcslib}..." )
625   find_library( WCSLIB ${_wcslib}
626                 PATHS ${WCSLIB_PATHS}
627                 PATH_SUFFIXES lib64 lib )
628   if( WCSLIB MATCHES "NOTFOUND$" )
629      message( FATAL_ERROR "${_wcslib} could not be found. Please check!" )
630   endif()
631endif()
632message( STATUS "WCSLIB = " ${WCSLIB} )
633find_path( WCSLIB_INCLUDE_DIR wcslib/wcs.h
634           PATHS ${WCSLIB_PATHS}
635           PATH_SUFFIXES include )
636if( WCSLIB_INCLUDE_DIR MATCHES "NOTFOUND$" )
637   message( FATAL_ERROR "wcs.h could not be found. Please check!" )
638endif()
639message( STATUS "WCSLIB_INCLUDE_DIR = " ${WCSLIB_INCLUDE_DIR} )
640
641
642#
643# common include path
644#
645include_directories( ${CASACORE_INCLUDE_DIR}/..
646                     ${CASACORE_INCLUDE_DIR}
647                     ${Boost_INCLUDE_DIR}
648                     ${X11_INCLUDE_DIRS}
649                     ${PGPLOT_INCLUDE_DIRS}
650                     ${PYTHON_INCLUDE_DIRS}
651                     ${WCSLIB_INCLUDE_DIR}
652                     ${CFITSIO_INCLUDE_DIRS}
653                     ${RPFITS_INCLUDE_DIRS} )
654
655
656#
657# install directory
658#
659set( EXEC_INSTALL_DIR bin )
660set( LIB_INSTALL_DIR lib )
661set( PYTHON_INSTALL_DIR python/${PYTHONV}/asap )
662set( SHARED_INSTALL_DIR share/asap )
663
664#
665# execute getsvnrev.sh to create/update svninfo.txt
666# run chmod to make sure the script has executable
667#
668exec_program( chmod ARGS a+x ${ASAP_SOURCE_DIR}/getsvnrev.sh )
669exec_program( chmod ARGS a+x ${ASAP_SOURCE_DIR}/cmake/exec_getsvnrev.sh )
670exec_program( ${ASAP_SOURCE_DIR}/cmake/exec_getsvnrev.sh ARGS ${ASAP_SOURCE_DIR})
671
672# Add the modules to be built.
673#
674# Choose to have correct RPATHs both in the build tree and
675# in the install tree (at the cost of having to change the
676# rpath when installing)
677#
678set( CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib )
679set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
680set( CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib )
681
682#
683# PKSMS
684#
685if ( NOT PKSMS )
686   add_definitions( -DNOPKSMS )
687endif()
688
689#
690# libraries and executables
691#
692set( ASAPPYLIB _asap )
693set( ASAPLIB asap )
694#set( PYRAPLIB pyrap )
695set( ATNFLIB atnf )
696set( ASAP2TO3 asap2to3 )
697if ( NOT STANDALONE )
698#   set( ASDM2ASAP_OLD oldasdm2ASAP )
699   set( ASDM2ASAP asdm2ASAP )
700endif()
701
702#
703# always install by default
704#
705add_custom_target( inst ALL ${CMAKE_BUILD_TOOL} install/fast )
706
707#
708# subdirectories
709#
710asap_add_subdirectory()
Note: See TracBrowser for help on using the repository browser.