source: trunk/CMakeLists.txt@ 3054

Last change on this file since 3054 was 3054, checked in by Kana Sugimoto, 9 years ago

New Development: Yes

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs: build asap using CMake

Put in Release Notes: No

Module(s): build of asap by CMake

Description: Committing the changes sent by Ville to support git migration


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