source: trunk/CMakeLists.txt @ 3107

Last change on this file since 3107 was 3107, checked in by Kana Sugimoto, 7 years ago

New Development: Yes

JIRA Issue: Yes (CAS-9275)

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs: build cmake

Put in Release Notes: No

Module(s): asap

Description: Darrell's changes to support thirdparty at /opt/casa/02.


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