source: trunk/CMakeLists.txt@ 1971

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

Bug fix on standalone build.


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