source: trunk/CMakeLists.txt @ 3048

Last change on this file since 3048 was 3036, 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 build

Description: Darrell's addition to CXX11 flag.


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