source: trunk/CMakeLists.txt @ 1957

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

Adds wcslib, rpfits, cfitsio libraries.
Includes CASA's cmake modules for searching python, cfitsio, and rpfits.
Update dependency.

Test build and sd regression run.
All sd regressions are passed.

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