2015-04-12 16:49:54 +08:00
# This is a CMake file, part of Unidata's netCDF-CXX4 package.
##################################
# Set Project Properties
##################################
#Minimum required CMake Version
cmake_minimum_required ( VERSION 2.8.12 )
#Project Name
2015-04-12 17:13:24 +08:00
PROJECT ( NCXX C CXX )
2015-04-18 02:35:13 +08:00
set ( PACKAGE "netcdf-cxx4" CACHE STRING "" )
2015-04-12 16:49:54 +08:00
#####
# Version Info:
#
# Release Version
# Library Version
# SO Version
#
# SO Version is computed from library version. See:
# http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning
#####
SET ( NCXX_VERSION_MAJOR 4 )
2016-05-14 06:50:49 +08:00
SET ( NCXX_VERSION_MINOR 3 )
2019-09-12 03:15:36 +08:00
SET ( NCXX_VERSION_PATCH 2 )
2016-01-26 06:08:48 +08:00
SET ( NCXX_VERSION_NOTE "-developer" )
2015-06-17 21:06:39 +08:00
SET ( NCXX_VERSION ${ NCXX_VERSION_MAJOR } . ${ NCXX_VERSION_MINOR } . ${ NCXX_VERSION_PATCH } ${ NCXX_VERSION_NOTE } )
2015-04-12 16:49:54 +08:00
SET ( VERSION ${ NCXX_VERSION } )
2019-09-12 03:12:42 +08:00
SET ( NCXX_LIB_VERSION 1.1.0 )
2015-04-13 23:08:39 +08:00
SET ( NCXX_SO_VERSION 1 )
2015-04-12 16:49:54 +08:00
SET ( PACKAGE_VERSION ${ VERSION } )
# Get system configuration, Use it to determine osname, os release, cpu. These
# will be used when committing to CDash.
find_program ( UNAME NAMES uname )
IF ( UNAME )
macro ( getuname name flag )
exec_program ( "${UNAME}" ARGS "${flag}" OUTPUT_VARIABLE "${name}" )
endmacro ( getuname )
getuname ( osname -s )
getuname ( osrel -r )
getuname ( cpu -m )
2015-04-28 00:26:38 +08:00
set ( TMP_BUILDNAME "${osname}-${osrel}-${cpu}" CACHE STRING "Build name variable for CDash" )
2015-04-12 16:49:54 +08:00
ENDIF ( )
2015-04-28 00:26:38 +08:00
###
# Allow for some customization of the buildname.
# This will make it easier to identify different builds,
# based on values passed from command line/shell scripts.
#
# For ctest scripts, we can use CTEST_BUILD_NAME.
###
SET ( BUILDNAME_PREFIX "" CACHE STRING "" )
SET ( BUILDNAME_SUFFIX "" CACHE STRING "" )
IF ( BUILDNAME_PREFIX )
SET ( TMP_BUILDNAME "${BUILDNAME_PREFIX}-${TMP_BUILDNAME}" )
ENDIF ( )
IF ( BUILDNAME_SUFFIX )
SET ( TMP_BUILDNAME "${TMP_BUILDNAME}-${BUILDNAME_SUFFIX}" )
ENDIF ( )
IF ( NOT BUILDNAME )
SET ( BUILDNAME "${TMP_BUILDNAME}" CACHE STRING "Build name variable for CDash" )
ENDIF ( )
###
# End BUILDNAME customization.
###
2015-06-17 20:52:55 +08:00
# For CMAKE_INSTALL_{LIBDIR,INCLUDEDIR,...}
2015-04-12 16:49:54 +08:00
INCLUDE ( GNUInstallDirs )
IF ( MSVC )
SET ( GLOBAL PROPERTY USE_FOLDERS ON )
ENDIF ( )
#Add custom CMake Module
2016-04-25 22:04:09 +08:00
SET ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/"
2015-04-12 16:49:54 +08:00
C A C H E I N T E R N A L " L o c a t i o n o f o u r c u s t o m C M a k e m o d u l e s . " )
# auto-configure style checks, other CMake modules.
INCLUDE ( ${ CMAKE_ROOT } /Modules/CheckLibraryExists.cmake )
INCLUDE ( ${ CMAKE_ROOT } /Modules/CheckIncludeFile.cmake )
INCLUDE ( ${ CMAKE_ROOT } /Modules/CheckTypeSize.cmake )
INCLUDE ( ${ CMAKE_ROOT } /Modules/CheckFunctionExists.cmake )
INCLUDE ( ${ CMAKE_ROOT } /Modules/CheckCXXSourceCompiles.cmake )
INCLUDE ( ${ CMAKE_ROOT } /Modules/CheckCSourceCompiles.cmake )
INCLUDE ( ${ CMAKE_ROOT } /Modules/TestBigEndian.cmake )
INCLUDE ( ${ CMAKE_ROOT } /Modules/CheckSymbolExists.cmake )
INCLUDE ( ${ CMAKE_ROOT } /Modules/GetPrerequisites.cmake )
INCLUDE ( CheckCCompilerFlag )
FIND_PACKAGE ( PkgConfig QUIET )
# A macro to check if a C linker supports a particular flag.
2015-04-15 15:33:19 +08:00
MACRO ( CHECK_CXX_LINKER_FLAG M_FLAG M_RESULT )
2015-04-12 16:49:54 +08:00
SET ( T_REQ_FLAG "${CMAKE_REQUIRED_FLAGS}" )
SET ( CMAKE_REQUIRED_FLAGS "${M_FLAG}" )
2015-04-15 15:33:19 +08:00
CHECK_CXX_SOURCE_COMPILES ( "int main() {return 0;}" ${ M_RESULT } )
2015-04-12 16:49:54 +08:00
SET ( CMAKE_REQUIRED_FLAGS "${T_REQ_FLAG}" )
ENDMACRO ( )
2015-04-12 17:13:24 +08:00
# Set the build type.
IF ( NOT CMAKE_BUILD_TYPE )
SET ( CMAKE_BUILD_TYPE DEBUG CACHE STRING "Choose the type of build, options are: None, Debug, Release."
F O R C E )
ENDIF ( )
# Set build type uppercase
STRING ( TOUPPER ${ CMAKE_BUILD_TYPE } CMAKE_BUILD_TYPE )
# Determine the configure date.
EXECUTE_PROCESS (
C O M M A N D d a t e
O U T P U T _ V A R I A B L E C O N F I G _ D A T E
)
IF ( CONFIG_DATE )
string ( STRIP ${ CONFIG_DATE } CONFIG_DATE )
ENDIF ( )
2019-07-09 00:38:52 +08:00
# Check to see if we have bash.
FIND_PROGRAM ( HAVE_BASH bash )
IF ( HAVE_BASH )
STRING ( COMPARE EQUAL "${HAVE_BASH}" "C:/Windows/System32/bash.exe" IS_BASH_EXE )
IF ( NOT IS_BASH_EXE )
MESSAGE ( STATUS "Found bash: ${HAVE_BASH}" )
ELSE ( )
MESSAGE ( STATUS "Ignoring ${HAVE_BASH}" )
SET ( HAVE_BASH "" )
ENDIF ( )
ELSE ( )
MESSAGE ( STATUS "Bash shell not found; disabling shell script tests." )
ENDIF ( )
2015-04-12 17:13:24 +08:00
##
# Allow for extra dependencies.
##
SET ( EXTRA_DEPS "" )
################################
# End Project Properties
################################
2015-04-12 22:37:52 +08:00
2015-04-13 22:43:53 +08:00
################################
# Utility Macros
################################
# A function used to create autotools-style 'yes/no' definitions.
# If a variable is set, it 'yes' is returned. Otherwise, 'no' is
# returned.
#
# Also creates a version of the ret_val prepended with 'NC',
# when feature is true, which is used to generate netcdf_meta.h.
FUNCTION ( is_disabled feature ret_val )
IF ( ${ feature } )
SET ( ${ ret_val } "no" PARENT_SCOPE )
ELSE ( )
SET ( ${ ret_val } "yes" PARENT_SCOPE )
SET ( "NC_${ret_val}" 1 PARENT_SCOPE )
ENDIF ( ${ feature } )
ENDFUNCTION ( )
FUNCTION ( is_enabled feature ret_val )
IF ( ${ feature } )
SET ( ${ ret_val } "yes" PARENT_SCOPE )
SET ( "NC_${ret_val}" 1 PARENT_SCOPE )
ELSE ( )
SET ( ${ ret_val } "no" PARENT_SCOPE )
SET ( "NC_${ret_val}" 0 PARENT_SCOPE )
ENDIF ( ${ feature } )
ENDFUNCTION ( )
2015-04-15 15:33:19 +08:00
###
# A macro to add a binary test.
###
MACRO ( add_bin_test prefix F )
SET ( CUR_TEST "${prefix}_${F}" )
ADD_EXECUTABLE ( ${ CUR_TEST } ${ F } .cpp )
TARGET_LINK_LIBRARIES ( ${ CUR_TEST }
n e t c d f - c x x 4
$ { E X T R A _ L I B S }
)
IF ( MSVC )
SET_TARGET_PROPERTIES ( ${ CUR_TEST }
P R O P E R T I E S L I N K _ F L A G S _ D E B U G " / N O D E F A U L T L I B : M S V C R T "
)
ENDIF ( )
ADD_TEST ( ${ CUR_TEST } ${ EXECUTABLE_OUTPUT_PATH } / ${ CUR_TEST } )
###
# If visual studio,
# do a little bit of housekeeping/reorganization.
###
IF ( MSVC )
SET_PROPERTY ( TEST ${ CUR_TEST } PROPERTY FOLDER "tests/" )
SET_TARGET_PROPERTIES ( ${ CUR_TEST } PROPERTIES RUNTIME_OUTPUT_DIRECTORY
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } )
SET_TARGET_PROPERTIES ( ${ CUR_TEST } PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } )
SET_TARGET_PROPERTIES ( ${ CUR_TEST } PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } )
ENDIF ( )
ENDMACRO ( )
2019-07-09 00:38:52 +08:00
###
# A macro to add a shell test.
###
MACRO ( add_sh_test prefix F )
IF ( HAVE_BASH )
ADD_TEST ( ${ prefix } _ ${ F } bash "-c" "export srcdir=${CMAKE_CURRENT_SOURCE_DIR};export TOPSRCDIR=${CMAKE_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR}/${F}.sh" )
ENDIF ( )
ENDMACRO ( )
# Build a binary used by a script, but don't make a test out of it.
MACRO ( build_bin_test F )
ADD_EXECUTABLE ( ${ F } ${ F } .cpp )
2020-05-15 22:18:21 +08:00
TARGET_LINK_LIBRARIES ( ${ F } netcdf-cxx4 )
2019-07-09 00:38:52 +08:00
IF ( MSVC )
SET_TARGET_PROPERTIES ( ${ F }
P R O P E R T I E S L I N K _ F L A G S _ D E B U G " / N O D E F A U L T L I B : M S V C R T "
)
SET_TARGET_PROPERTIES ( ${ F } PROPERTIES RUNTIME_OUTPUT_DIRECTORY
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } )
SET_TARGET_PROPERTIES ( ${ F } PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } )
SET_TARGET_PROPERTIES ( ${ F } PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } )
ENDIF ( )
ENDMACRO ( )
2015-04-13 22:43:53 +08:00
################################
# End Utility Macros
################################
2015-04-12 22:37:52 +08:00
################################
# Set CTest Properties
################################
ENABLE_TESTING ( )
INCLUDE ( CTest )
2015-04-15 15:33:19 +08:00
##
2015-04-12 22:37:52 +08:00
# Copy the CTest customization file into binary directory, as required.
2015-04-15 15:33:19 +08:00
##
2016-04-25 22:04:09 +08:00
FILE ( COPY ${ CMAKE_CURRENT_SOURCE_DIR } /CTestCustom.cmake DESTINATION ${ CMAKE_CURRENT_BINARY_DIR } )
2015-04-12 22:37:52 +08:00
2015-04-15 15:33:19 +08:00
##
2015-04-12 22:37:52 +08:00
# Set Memory test program for non-MSVC based builds.
# Assume valgrind for now.
2015-04-15 15:33:19 +08:00
##
2015-04-12 22:37:52 +08:00
IF ( NOT MSVC )
SET ( CTEST_MEMORYCHECK_COMMAND valgrind CACHE STRING "" )
ENDIF ( )
2015-04-15 15:33:19 +08:00
##
2015-04-12 22:37:52 +08:00
# Set variable to define the build type.
2015-04-15 15:33:19 +08:00
##
2015-04-12 22:37:52 +08:00
INCLUDE ( GenerateExportHeader )
2015-04-15 15:33:19 +08:00
ENABLE_TESTING ( )
INCLUDE ( CTest )
2015-04-12 22:37:52 +08:00
################################
# End CTest Properties
################################
################################
2015-04-15 15:33:19 +08:00
# User Options
2015-04-12 22:37:52 +08:00
################################
2015-04-15 15:33:19 +08:00
##
2015-04-12 22:37:52 +08:00
# Default building shared libraries.
# BUILD_SHARED_LIBS is provided by/used by
# CMake directly.
2015-04-15 15:33:19 +08:00
##
2015-04-12 22:37:52 +08:00
OPTION ( BUILD_SHARED_LIBS "Configure netcdf-cxx as a shared library." ON )
IF ( BUILD_SHARED_LIBS )
SET ( CMAKE_POSITION_INDEPENDENT_CODE ON )
ENDIF ( )
2016-01-26 05:49:16 +08:00
##
# Enable doxygen-generated documentation.
##
2016-02-12 02:28:20 +08:00
OPTION ( ENABLE_DOXYGEN "Enable generation of doxygen-based documentation." OFF )
IF ( ENABLE_DOXYGEN )
2016-01-26 05:49:16 +08:00
FIND_PACKAGE ( Doxygen REQUIRED )
FIND_PROGRAM ( NCXX_DOT NAMES dot )
IF ( NCXX_DOT )
SET ( HAVE_DOT YES CACHE STRING "" )
ELSE ( NCXX_DOT )
SET ( HAVE_DOT NO CACHE STRING "" )
ENDIF ( NCXX_DOT )
ENDIF ( )
2015-04-15 15:33:19 +08:00
OPTION ( NCXX_ENABLE_TESTS "Enable tests. Run with 'make test'." ON )
2015-04-15 17:29:27 +08:00
IF ( NCXX_ENABLE_TESTS )
# Options for CTest-based tests, dashboards.
SET ( NCXX_CTEST_PROJECT_NAME "netcdf-cxx4" CACHE STRING "Project Name for CTest-based testing purposes." )
2018-03-08 04:54:48 +08:00
SET ( NCXX_CTEST_DROP_SITE "cdash.unidata.ucar.edu" CACHE STRING "Dashboard location for CTest-based testing purposes." )
2015-04-15 17:29:27 +08:00
SET ( NCXX_CTEST_DROP_LOC_PREFIX "" CACHE STRING "Prefix for Dashboard location on remote server when using CTest-based testing." )
FIND_PROGRAM ( HOSTNAME_CMD NAMES hostname )
IF ( NOT MSVC )
SET ( HOSTNAME_ARG "-s" )
ENDIF ( )
IF ( HOSTNAME_CMD )
EXEC_PROGRAM ( ${ HOSTNAME_CMD } ARGS "${HOSTNAME_ARG}" OUTPUT_VARIABLE HOSTNAME )
SET ( NCXX_CTEST_SITE "${HOSTNAME}" CACHE STRING "Hostname of test machine." )
ENDIF ( )
IF ( NCXX_CTEST_SITE )
SET ( SITE "${NCXX_CTEST_SITE}" CACHE STRING "" )
ENDIF ( )
2015-04-15 15:33:19 +08:00
2015-04-15 17:29:27 +08:00
# Create a CTestConfig file from the template.
2016-04-25 22:04:09 +08:00
CONFIGURE_FILE ( "${CMAKE_CURRENT_SOURCE_DIR}/CTestConfig.cmake.in"
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / C T e s t C o n f i g . c m a k e "
2015-04-15 17:29:27 +08:00
@ O N L Y
)
ENDIF ( )
2015-04-15 15:33:19 +08:00
##
# Mark some options as advanced.
##
MARK_AS_ADVANCED ( NCXX_CTEST_PROJECT_NAME
N C X X _ C T E S T _ D R O P _ S I T E
N C X X _ C T E S T _ D R O P _ L O C _ P R E F I X
)
2015-04-12 22:37:52 +08:00
################################
2015-04-15 15:33:19 +08:00
# End User Options
2015-04-12 22:37:52 +08:00
################################
2015-04-14 20:14:22 +08:00
################################
# Seek out dependent libraries.
################################
2019-07-09 05:10:43 +08:00
###
# Find NetCDF
###
2015-04-14 20:14:22 +08:00
IF ( NOT netCDF_LIBRARIES AND NOT netCDF_INCLUDE_DIR )
FIND_PACKAGE ( netCDF QUIET )
ELSE ( )
SET ( netCDF_FOUND TRUE )
ENDIF ( )
IF ( netCDF_FOUND )
SET ( NETCDF_C_LIBRARY ${ netCDF_LIBRARIES } )
SET ( NETCDF_C_INCLUDE_DIR ${ netCDF_INCLUDE_DIR } )
2020-05-15 22:18:44 +08:00
message ( STATUS "Found netCDF CMake package: ${NETCDF_C_LIBRARY}" )
2015-04-14 20:14:22 +08:00
ELSE ( )
# netCDF not properly packaged. Try to find it manually.
FIND_LIBRARY ( NETCDF_C_LIBRARY NAMES netcdf libnetcdf )
IF ( NOT NETCDF_C_LIBRARY )
MESSAGE ( FATAL_ERROR "libnetcdf not found. Please reinstall and try again." )
ELSE ( )
2020-05-15 22:18:44 +08:00
FIND_PATH ( NETCDF_C_INCLUDE_DIR "netcdf.h" )
2015-04-14 20:14:22 +08:00
MESSAGE ( STATUS "Found netcdf: ${NETCDF_C_LIBRARY}" )
2020-05-15 22:18:44 +08:00
IF ( NOT NETCDF_C_INCLUDE_DIR )
2015-04-14 20:14:22 +08:00
MESSAGE ( FATAL_ERROR "Directory containing netcdf.h cannot be found. Please reinstall and try again." )
ELSE ( )
2016-04-01 02:29:30 +08:00
GET_FILENAME_COMPONENT ( netCDF_LIB_DIR "${NETCDF_C_LIBRARY}" REALPATH )
2015-04-14 20:14:22 +08:00
INCLUDE_DIRECTORIES ( SYSTEM ${ NC_H_INCLUDE_DIR } )
ENDIF ( )
ENDIF ( )
ENDIF ( )
2020-05-15 22:18:44 +08:00
2020-05-16 20:49:25 +08:00
if ( NOT TARGET netCDF::netcdf )
add_library ( netCDF::netcdf UNKNOWN IMPORTED )
set_target_properties ( netCDF::netcdf PROPERTIES
2020-05-15 22:18:44 +08:00
I M P O R T E D _ L O C A T I O N " $ { N E T C D F _ C _ L I B R A R Y } "
I N T E R F A C E _ I N C L U D E _ D I R E C T O R I E S " $ { N E T C D F _ C _ I N C L U D E _ D I R } "
)
endif ( )
2015-04-28 00:53:33 +08:00
###
# Check to see if netcdf-c was built with parallel.
###
2015-04-28 00:59:34 +08:00
CHECK_LIBRARY_EXISTS ( ${ NETCDF_C_LIBRARY } nc_use_parallel_enabled "" NC_IS_PARALLEL )
2015-04-28 00:53:33 +08:00
IF ( NC_IS_PARALLEL )
SET ( BUILD_PARALLEL ${ NC_IS_PARALLEL } CACHE STRING "" )
ENDIF ( )
2019-06-22 05:29:44 +08:00
###
# Check to see if netcdf-c was built with plugin support.
###
CHECK_LIBRARY_EXISTS ( ${ NETCDF_C_LIBRARY } nc_def_var_filter "" NC_HAS_DEF_VAR_FILTER )
IF ( NC_HAS_DEF_VAR_FILTER )
SET ( HAS_DEF_VAR_FILTER ${ NC_HAS_DEF_VAR_FILTER } CACHE STRING "" )
ENDIF ( NC_HAS_DEF_VAR_FILTER )
2019-07-09 05:10:43 +08:00
###
# Find HDF5
###
IF ( MSVC )
SET ( SEARCH_PACKAGE_NAME ${ HDF5_PACKAGE_NAME } )
FIND_PACKAGE ( HDF5 NAMES ${ SEARCH_PACKAGE_NAME } COMPONENTS C HL NO_MODULES REQUIRED ${ NC_HDF5_LINK_TYPE } )
ELSE ( MSVC )
FIND_PACKAGE ( HDF5 COMPONENTS C HL REQUIRED )
ENDIF ( MSVC )
2020-05-22 16:31:46 +08:00
CHECK_LIBRARY_EXISTS ( ${ HDF5_C_LIBRARIES } H5free_memory "" HAVE_H5FREE_MEMORY )
2019-07-09 05:10:43 +08:00
IF ( NOT HAVE_H5FREE_MEMORY )
MESSAGE ( STATUS "Plugin support requires libhdf5 with H5Free support. Your libhdf5 install does not provide H5Free. Please install a newer version of libhdf5 if you require plugin compression support." )
SET ( NC_HAS_DEF_VAR_FILTER "" )
ENDIF ( )
2015-04-14 20:14:22 +08:00
################################
# End 'seek out dependent libraries'
################################
2015-04-12 22:37:52 +08:00
################################
# Compiler Configuration
################################
2015-04-15 15:33:19 +08:00
##
2015-04-12 22:37:52 +08:00
# Supress unused variable and parameter warnings, for the time being,
# on GCC.
#
# Also, set some other default compiler flags.
2015-04-15 15:33:19 +08:00
##
2024-01-18 09:14:46 +08:00
SET ( CMAKE_CXX_STANDARD 11 )
SET ( CMAKE_CXX_STANDARD_REQUIRED TRUE )
2015-04-15 15:33:19 +08:00
2015-04-12 22:37:52 +08:00
IF ( CMAKE_COMPILER_IS_GNUCC OR APPLE )
2019-09-26 03:33:42 +08:00
SET ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-variable -Wno-unused-parameter" )
SET ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-variable -Wno-unused-parameter" )
2015-04-15 15:33:19 +08:00
OPTION ( ENABLE_COVERAGE_TESTS "Enable compiler flags needed to perform coverage tests." OFF )
OPTION ( ENABLE_CONVERSION_WARNINGS "Enable warnings for implicit conversion from 64 to 32-bit datatypes." ON )
OPTION ( ENABLE_LARGE_FILE_TESTS "Enable large file tests." OFF )
# Check to see if -Wl,--no-undefined is supported.
CHECK_CXX_LINKER_FLAG ( "-Wl,--no-undefined" LIBTOOL_HAS_NO_UNDEFINED )
IF ( LIBTOOL_HAS_NO_UNDEFINED )
SET ( CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -Wl,--no-undefined" )
ENDIF ( )
SET ( CMAKE_REQUIRED_FLAGS "${TMP_CMAKE_REQUIRED_FLAGS}" )
# Coverage tests need to have optimization turned off.
IF ( ENABLE_COVERAGE_TESTS )
SET ( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage" )
SET ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage" )
MESSAGE ( STATUS "Coverage Tests: On." )
ENDIF ( )
# Warnings for 64-to-32 bit conversions.
IF ( ENABLE_CONVERSION_WARNINGS )
CHECK_CXX_COMPILER_FLAG ( -Wconversion CXX_HAS_WCONVERSION )
CHECK_CXX_COMPILER_FLAG ( -Wshorten-64-to-32 CXX_HAS_SHORTEN_64_32 )
IF ( CXX_HAS_SHORTEN_64_32 )
SET ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wshorten-64-to-32" )
ENDIF ( )
IF ( CXX_HAS_WCONVERSION )
SET ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wconversion" )
ENDIF ( )
ENDIF ( ENABLE_CONVERSION_WARNINGS )
ENDIF ( CMAKE_COMPILER_IS_GNUCC OR APPLE )
# End default linux gcc & apple compiler options.
2015-04-12 22:37:52 +08:00
ADD_DEFINITIONS ( )
# Supress CRT Warnings.
# Only necessary for Windows
IF ( MSVC )
ADD_DEFINITIONS ( -D_CRT_SECURE_NO_WARNINGS )
ENDIF ( )
################################
# End Compiler Configuration
################################
2015-04-18 02:35:13 +08:00
################################
# Configuration for post-install RPath
# Adapted from http://www.cmake.org/Wiki/CMake_RPATH_handling
################################
IF ( NOT MSVC )
# use, i.e. don't skip the full RPATH for the build tree
SET ( CMAKE_SKIP_BUILD_RPATH FALSE )
# when building, don't use the install RPATH already
# (but later on when installing)
SET ( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
if ( APPLE )
set ( CMAKE_MACOSX_RPATH ON )
endif ( APPLE )
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
# the RPATH to be used when installing,
# but only if it's not a system directory
2015-06-17 20:52:55 +08:00
LIST ( FIND
C M A K E _ P L A T F O R M _ I M P L I C I T _ L I N K _ D I R E C T O R I E S
" $ { C M A K E _ I N S T A L L _ F U L L _ L I B D I R } "
i s S y s t e m D i r
)
2015-04-18 02:35:13 +08:00
IF ( "${isSystemDir}" STREQUAL "-1" )
2015-06-17 20:52:55 +08:00
SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}" )
ENDIF ( )
2015-04-18 02:35:13 +08:00
ENDIF ( )
################################
# End configuration for post-install RPath
################################
2015-04-13 22:43:53 +08:00
################################
# Configure, print libnetcdf-cxx.settings
# file.
################################
# Set variables to mirror those used by autoconf.
# This way we don't need to maintain two separate template
# files.
SET ( host_cpu "${cpu}" )
SET ( host_vendor "${osname}" )
SET ( host_os "${osrel}" )
2016-04-25 22:04:09 +08:00
SET ( abs_top_builddir "${CMAKE_CURRENT_BINARY_DIR}" )
2015-04-13 22:43:53 +08:00
SET ( CC_VERSION "${CMAKE_C_COMPILER}" )
2015-04-15 15:33:19 +08:00
SET ( CXX_VERSION "${CMAKE_CXX_COMPILER}" )
2015-04-13 22:43:53 +08:00
# Build *FLAGS for libnetcdf.settings.
SET ( CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}" )
2015-04-15 15:33:19 +08:00
SET ( CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}" )
2015-04-13 22:43:53 +08:00
SET ( LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE}}" )
is_disabled ( BUILD_SHARED_LIBS enable_static )
is_enabled ( BUILD_SHARED_LIBS enable_shared )
# Remove libnetcdf from NC_LIBS.
2015-04-15 15:33:19 +08:00
STRING ( REPLACE "-lnetcdf-cxx4 " "" TMP_NCXX_LIBS "${NCXX_LIBS}" )
2015-04-13 22:43:53 +08:00
SET ( LIBS "${TMP_NCXX_LIBS}" )
CONFIGURE_FILE (
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / l i b n e t c d f - c x x . s e t t i n g s . i n "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / l i b n e t c d f - c x x . s e t t i n g s "
2015-06-17 20:52:55 +08:00
@ O N L Y
)
2015-04-13 22:43:53 +08:00
# Read in settings file, print out.
# Avoid using system-specific calls so that this
# might also work on Windows.
2015-06-17 20:52:55 +08:00
FILE (
R E A D " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / l i b n e t c d f - c x x . s e t t i n g s "
L I B N E T C D F C X X _ S E T T I N G S
)
2015-04-13 22:43:53 +08:00
MESSAGE ( ${ LIBNETCDFCXX_SETTINGS } )
# Install libnetcdf-cxx.settings file into same location
# as the libraries.
2015-06-17 20:52:55 +08:00
INSTALL (
F I L E S " $ { N C X X _ B I N A R Y _ D I R } / l i b n e t c d f - c x x . s e t t i n g s "
2015-04-13 22:43:53 +08:00
D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ L I B D I R } "
2015-06-17 20:52:55 +08:00
C O M P O N E N T l i b r a r i e s
)
2015-04-13 22:43:53 +08:00
#####
# End libnetcdf-cxx.settings section.
#####
2019-06-07 18:23:16 +08:00
#####
# Traverse into subdirectories.
#####
##
# Set up include directories.
##
# INCLUDE_DIRECTORIES(cxx4 examples)
ADD_SUBDIRECTORY ( cxx4 )
ADD_SUBDIRECTORY ( examples )
IF ( ENABLE_DOXYGEN )
ADD_SUBDIRECTORY ( docs )
ENDIF ( )
2016-06-07 18:38:19 +08:00
#####
# Begin ncxx4-config section
#####
2016-06-07 19:09:47 +08:00
FILE ( MAKE_DIRECTORY ${ NCXX_BINARY_DIR } /tmp )
CONFIGURE_FILE ( "${CMAKE_CURRENT_SOURCE_DIR}/ncxx4-config.cmake.in"
" $ { N C X X _ B I N A R Y _ D I R } / t m p / n c x x 4 - c o n f i g " @ O N L Y )
FILE ( COPY "${NCXX_BINARY_DIR}/tmp/ncxx4-config"
D E S T I N A T I O N $ { N C X X _ B I N A R Y _ D I R } /
2016-06-07 18:38:19 +08:00
F I L E _ P E R M I S S I O N S O W N E R _ R E A D O W N E R _ W R I T E O W N E R _ E X E C U T E G R O U P _ R E A D G R O U P _ E X E C U T E W O R L D _ R E A D W O R L D _ E X E C U T E )
2016-06-07 19:09:47 +08:00
INSTALL ( PROGRAMS ${ NCXX_BINARY_DIR } /ncxx4-config
2016-06-07 18:38:19 +08:00
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ B I N D I R }
C O M P O N E N T u t i l i t i e s )
#####
# End ncxx4-config section
#####
2019-06-22 05:29:44 +08:00
#####
2019-07-09 00:38:52 +08:00
# Build test_common.sh
2019-06-22 05:29:44 +08:00
#####
2020-11-05 19:59:36 +08:00
SET ( EXTRA_DIST ${ EXTRA_DIST } ${ CMAKE_CURRENT_SOURCE_DIR } /test_common.in )
SET ( TOPSRCDIR "${CMAKE_CURRENT_SOURCE_DIR}" )
SET ( TOPBUILDDIR "${CMAKE_CURRENT_BINARY_DIR}" )
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /test_common.in ${ CMAKE_CURRENT_BINARY_DIR } /test_common.sh @ONLY NEWLINE_STYLE LF )
2016-06-07 18:38:19 +08:00
2016-01-26 05:49:16 +08:00
#####
# Options
#####
2015-06-17 21:06:39 +08:00
include ( CMakePackageConfigHelpers )
2019-06-07 18:23:16 +08:00
set ( ConfigPackageLocation "${CMAKE_INSTALL_LIBDIR}/cmake/netCDF" )
2015-06-17 21:06:39 +08:00
# Create export configuration
write_basic_package_version_file (
2019-06-07 18:23:16 +08:00
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / n e t C D F C x x C o n f i g V e r s i o n . c m a k e "
2015-06-17 21:06:39 +08:00
V E R S I O N $ { N C X X _ V E R S I O N }
C O M P A T I B I L I T Y S a m e M a j o r V e r s i o n
)
install (
2019-06-07 18:23:16 +08:00
E X P O R T n e t c d f - c x x 4 T a r g e t s
F I L E n e t c d f - c x x 4 T a r g e t s . c m a k e
N A M E S P A C E n e t C D F : :
D E S T I N A T I O N $ { C o n f i g P a c k a g e L o c a t i o n }
2015-06-17 21:06:39 +08:00
)
2020-11-05 20:02:39 +08:00
export (
E X P O R T n e t c d f - c x x 4 T a r g e t s
F I L E n e t c d f - c x x 4 T a r g e t s . c m a k e
N A M E S P A C E n e t C D F : :
)
2019-06-07 18:23:16 +08:00
configure_package_config_file (
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / n e t C D F C x x C o n f i g . c m a k e . i n "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / n e t C D F C x x C o n f i g . c m a k e "
I N S T A L L _ D E S T I N A T I O N " $ { C o n f i g P a c k a g e L o c a t i o n } "
)
2015-06-17 21:06:39 +08:00
2020-05-15 06:50:09 +08:00
2019-06-07 18:23:16 +08:00
install (
F I L E S
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / n e t C D F C x x C o n f i g . c m a k e "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / n e t C D F C x x C o n f i g V e r s i o n . c m a k e "
D E S T I N A T I O N " $ { C o n f i g P a c k a g e L o c a t i o n } "
C O M P O N E N T h e a d e r s
)
2016-01-26 05:49:16 +08:00
2019-06-22 05:29:44 +08:00
IF ( NC_HAS_DEF_VAR_FILTER )
2019-06-25 06:08:22 +08:00
#####
# Build cxx4/findplugin.sh
#####
SET ( ISCMAKE "1" )
2020-11-05 19:59:36 +08:00
CONFIGURE_FILE ( ${ CMAKE_CURRENT_SOURCE_DIR } /cxx4/findplugin.in ${ CMAKE_CURRENT_BINARY_DIR } /cxx4/findplugin.sh @ONLY NEWLINE_STYLE LF )
CONFIGURE_FILE ( ${ CMAKE_CURRENT_SOURCE_DIR } /examples/findplugin.in ${ CMAKE_CURRENT_BINARY_DIR } /examples/findplugin.sh @ONLY NEWLINE_STYLE LF )
2019-06-25 06:08:22 +08:00
2019-06-22 05:29:44 +08:00
ADD_SUBDIRECTORY ( plugins )
ENDIF ( NC_HAS_DEF_VAR_FILTER )
2016-02-12 02:28:20 +08:00
IF ( ENABLE_DOXYGEN )
2016-01-26 05:49:16 +08:00
ADD_SUBDIRECTORY ( docs )
ENDIF ( )
##
# CPack, CMakeInstallation.cmake file.
##
INCLUDE ( CMakeInstallation.cmake )