Skip to content

Commit 6bb837f

Browse files
authored
Merge pull request #291 from casacore/update-find-casacore-script
Update the FindCasacore script to include version info
2 parents 24cf83f + d8485ed commit 6bb837f

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

cmake/FindCasacore.cmake

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# For this, you need to have a complete casacore installation, built with shared
1414
# libraries, at your disposal.
1515
#
16-
# The dependencies in this macro were generated against casacore release 1.7.0.
16+
# The dependencies in this macro were generated against casacore release 2.0.
1717
#
1818
# Variables used by this module:
1919
# CASACORE_ROOT_DIR - Casacore root directory.
@@ -24,6 +24,7 @@
2424
# CASACORE_FOUND - System has Casacore, which means that the
2525
# include dir was found, as well as all
2626
# libraries specified (not cached)
27+
# CASACORE_VERSION - Found version, e.g. "3.6.1" (not cached)
2728
# CASACORE_INCLUDE_DIR - Casacore include directory (cached)
2829
# CASACORE_INCLUDE_DIRS - Casacore include directories (not cached)
2930
# identical to CASACORE_INCLUDE_DIR
@@ -112,13 +113,11 @@ endmacro(casacore_find_library _name)
112113
# Usage: casacore_find_package(name [REQUIRED])
113114
#
114115
macro(casacore_find_package _name)
115-
if("${ARGN}" MATCHES "^REQUIRED$" AND
116-
Casacore_FIND_REQUIRED AND
117-
NOT CASACORE_MAKE_REQUIRED_EXTERNALS_OPTIONAL)
118-
find_package(${_name} REQUIRED)
119-
else()
120-
find_package(${_name})
116+
set(_arg_list ${ARGN})
117+
if(NOT Casacore_FIND_REQUIRED OR CASACORE_MAKE_REQUIRED_EXTERNALS_OPTIONAL)
118+
list(REMOVE_ITEM _arg_list "REQUIRED")
121119
endif()
120+
find_package(${_name} ${_arg_list})
122121
if(${_name}_FOUND)
123122
list(APPEND CASACORE_INCLUDE_DIRS ${${_name}_INCLUDE_DIRS})
124123
list(APPEND CASACORE_LIBRARIES ${${_name}_LIBRARIES})
@@ -150,12 +149,12 @@ set(Casacore_coordinates_DEPENDENCIES fits measures casa)
150149
set(Casacore_derivedmscal_DEPENDENCIES ms measures tables casa)
151150
set(Casacore_fits_DEPENDENCIES measures tables casa)
152151
set(Casacore_images_DEPENDENCIES coordinates mirlib lattices fits measures scimath tables casa)
153-
set(Casacore_lattices_DEPENDENCIES scimath tables casa)
152+
set(Casacore_lattices_DEPENDENCIES tables scimath casa)
154153
set(Casacore_meas_DEPENDENCIES measures tables casa)
155154
set(Casacore_measures_DEPENDENCIES tables casa)
156155
set(Casacore_mirlib_DEPENDENCIES)
157156
set(Casacore_ms_DEPENDENCIES measures scimath tables casa)
158-
set(Casacore_msfits_DEPENDENCIES ms fits measures scimath tables casa)
157+
set(Casacore_msfits_DEPENDENCIES ms fits measures tables casa)
159158
set(Casacore_python3_DEPENDENCIES casa)
160159
set(Casacore_scimath_DEPENDENCIES scimath_f casa)
161160
set(Casacore_scimath_f_DEPENDENCIES)
@@ -166,6 +165,7 @@ set(CASACORE_FOUND FALSE)
166165
set(CASACORE_DEFINITIONS)
167166
set(CASACORE_LIBRARIES)
168167
set(CASACORE_MISSING_COMPONENTS)
168+
set(CASACORE_VERSION)
169169

170170
# Search for the header file first.
171171
if(NOT CASACORE_INCLUDE_DIR)
@@ -209,7 +209,7 @@ else(NOT CASACORE_INCLUDE_DIR)
209209
foreach(_comp ${_find_components})
210210
casacore_find_library(casa_${_comp})
211211
if(${_comp} STREQUAL casa)
212-
casacore_find_package(HDF5)
212+
casacore_find_package(HDF5 COMPONENTS CXX)
213213
casacore_find_library(m)
214214
list(APPEND CASACORE_LIBRARIES ${CMAKE_DL_LIBS})
215215
elseif(${_comp} STREQUAL coordinates)
@@ -242,6 +242,25 @@ if(CASACORE_FOUND)
242242
set(HAVE_AIPSPP TRUE CACHE INTERNAL "Define if AIPS++/Casacore is installed")
243243
endif(CASACORE_FOUND)
244244

245+
# Check version requirements
246+
file(WRITE ${CMAKE_BINARY_DIR}/casacore_version.cpp "#include <iostream>\n#include <casacore/casa/version.h>\nint main(int argc,char *argv[]) { std::cout << CASACORE_VERSION; return 0; }\n")
247+
try_run(CASACORE_VERSION_RUN_RESULT CASACORE_VERSION_COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/casacore_version.cpp
248+
RUN_OUTPUT_VARIABLE CASACORE_VERSION
249+
COMPILE_DEFINITIONS "-I${CASACORE_INCLUDE_DIR}" )
250+
if (CASACORE_FOUND AND CASACORE_VERSION)
251+
if (Casacore_FIND_VERSION)
252+
if (Casacore_FIND_VERSION_EXACT)
253+
if (NOT CASACORE_VERSION VERSION_EQUAL Casacore_FIND_VERSION)
254+
message(FATAL_ERROR "Found Casacore version ${CASACORE_VERSION}, but EXACT version ${Casacore_FIND_VERSION} is required.")
255+
endif()
256+
else()
257+
if (CASACORE_VERSION VERSION_LESS Casacore_FIND_VERSION)
258+
message(FATAL_ERROR "Found Casacore version ${CASACORE_VERSION}, but at least version ${Casacore_FIND_VERSION} is required.")
259+
endif()
260+
endif()
261+
endif()
262+
endif()
263+
245264
# Compose diagnostic message if not all necessary components were found.
246265
if(CASACORE_MISSING_COMPONENTS)
247266
set(CASACORE_ERROR_MESSAGE "Casacore: the following components could not be found:\n ${CASACORE_MISSING_COMPONENTS}")
@@ -250,7 +269,7 @@ endif(CASACORE_MISSING_COMPONENTS)
250269
# Print diagnostics.
251270
if(CASACORE_FOUND)
252271
if(NOT Casacore_FIND_QUIETLY)
253-
message(STATUS "Found the following Casacore components: ")
272+
message(STATUS "Found Casacore (version ${CASACORE_VERSION}) with the following components:")
254273
foreach(_comp ${_find_components})
255274
string(TOUPPER casa_${_comp} _COMP)
256275
message(STATUS " ${_comp}: ${${_COMP}_LIBRARY}")

0 commit comments

Comments
 (0)