source: trunk/CMakeLists.txt @ 1958

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

Update for Mac OS X.

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