source: trunk/cmake/withcasa.cmake@ 1968

Last change on this file since 1968 was 1968, checked in by Takeshi Nakazato, 15 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...

Defined standalone build mode.


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