netcdf-c/liblib/CMakeLists.txt

258 lines
6.2 KiB
CMake
Raw Normal View History

# Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
# 2015, 2016, 2017, 2018
# University Corporation for Atmospheric Research/Unidata.
# See netcdf-c/COPYRIGHT file for more info.
2012-07-26 06:09:19 +08:00
#####
# Add target objects/modules based on options.
#####
2024-01-27 03:29:38 +08:00
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:netcdf3>
$<TARGET_OBJECTS:dispatch>
)
2012-07-26 06:09:19 +08:00
if(USE_NETCDF4)
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:netcdf4>
)
endif()
if(USE_HDF5)
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:netcdfhdf5>
)
endif()
if(USE_PNETCDF)
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:netcdfp>
)
endif()
if(USE_HDF4)
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:netcdfhdf4>
)
endif()
if(ENABLE_DAP2)
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:oc2>
$<TARGET_OBJECTS:dap2>
)
endif()
if(ENABLE_DAP4)
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:dap4>
$<TARGET_OBJECTS:ncxml>
)
endif()
if(ENABLE_NCZARR)
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:nczarr>
)
endif()
if(ENABLE_S3_INTERNAL)
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:ncxml>
)
endif()
if(ENABLE_PLUGINS)
target_sources(netcdf
PRIVATE
$<TARGET_OBJECTS:ncpoco>
)
endif()
target_sources(netcdf
PRIVATE
2024-01-27 03:29:38 +08:00
${CMAKE_CURRENT_SOURCE_DIR}/nc_initialize.c
)
if(STATUS_PARALLEL)
# TODO: Make PUBLIC when other dependencies have PUBLIC/PRIVATE specified
target_link_libraries(netcdf MPI::MPI_C)
endif(STATUS_PARALLEL)
if(TARGET MPI::MPI_C)
target_link_libraries(netcdf MPI::MPI_C)
endif(TARGET MPI::MPI_C)
if(MOD_NETCDF_NAME)
set_target_properties(netcdf PROPERTIES LIBRARY_OUTPUT_NAME ${NETCDF_LIB_NAME})
set_target_properties(netcdf PROPERTIES ARCHIVE_OUTPUT_NAME ${NETCDF_LIB_NAME})
set_target_properties(netcdf PROPERTIES RUNTIME_OUTPUT_NAME ${NETCDF_LIB_NAME})
endif()
2012-07-21 05:16:27 +08:00
# Make sure that netcdf.dll path does not include the build configuration
if(MSVC)
set_target_properties(netcdf PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR})
endif()
2012-07-26 06:09:19 +08:00
#####
# Add dependencies required for linking.
#####
set(TLL_LIBS "")
set(TLL_LIBS ${TLL_LIBS} ${HAVE_LIBM} ${ZLIB_LIBRARY})
2014-09-30 02:04:35 +08:00
# Add extra dependencies specified via NC_EXTRA_DEPS
set(TLL_LIBS ${TLL_LIBS} ${EXTRA_DEPS})
if(ENABLE_NCZARR_ZIP)
set(TLL_LIBS ${TLL_LIBS} ${Zip_LIBRARIES})
endif()
if(Blosc_FOUND)
set(TLL_LIBS ${TLL_LIBS} ${Blosc_LIBRARIES})
endif()
if(Zstd_FOUND)
set(TLL_LIBS ${TLL_LIBS} ${Zstd_LIBRARIES})
endif()
if(Bz2_FOUND)
set(TLL_LIBS ${TLL_LIBS} ${Bz2_LIBRARIES})
endif()
if(SZIP_FOUND)
set(TLL_LIBS ${TLL_LIBS} ${Szip_LIBRARY})
endif()
if(HAVE_LIBDL)
set(TLL_LIBS ${LIBDL} ${TLL_LIBS})
endif()
if(ENABLE_NCZARR_ZIP)
set(TLL_LIBS ${TLL_LIBS} ${Zip_LIBRARIES})
endif()
if(USE_HDF5)
if(NOT MSVC)
2013-10-08 02:39:54 +08:00
# Some version of cmake define HDF5_hdf5_LIBRARY instead of
# HDF5_LIBRARY. Same with HDF5_HL_LIBRARIES
if(HDF5_hdf5_LIBRARY AND NOT HDF5_C_LIBRARIES)
set(HDF5_C_LIBRARIES ${HDF5_hdf5_LIBRARY})
endif()
if(HDF5_hdf5_hl_LIBRARY AND NOT HDF5_HL_LIBRARIES)
set(HDF5_HL_LIBRARIES ${HDF5_hdf5_hl_LIBRARY})
endif()
2014-08-21 18:03:41 +08:00
# The order of the libraries is important here for static
# builds:
# Make sure that HDF5_C_LIBRARY appears *after*
# HDF5_HL_LIBRARY.
set(TLL_LIBS ${HDF5_HL_LIBRARIES} ${HDF5_C_LIBRARIES} ${HDF5_LIBRARIES} ${TLL_LIBS} ${Szip_LIBRARY})
else() # Windows CMake defines HDF5_LIBRARIES.
set(TLL_LIBS ${HDF5_LIBRARIES} ${TLL_LIBS} ${Szip_LIBRARY})
endif()
endif()
if(FOUND_CURL)
set(TLL_LIBS ${TLL_LIBS} ${CURL_LIBRARIES})
endif()
2012-07-21 05:16:27 +08:00
if(USE_HDF4)
set(TLL_LIBS ${HDF4_MFHDF_LIB} ${HDF4_DF_LIB} ${TLL_LIBS})
endif()
if(ENABLE_PNETCDF AND PNETCDF)
set(TLL_LIBS ${TLL_LIBS} ${PNETCDF})
endif()
if(ENABLE_S3)
if(ENABLE_S3_AWS)
TARGET_LINK_DIRECTORIES(netcdf PUBLIC ${AWSSDK_LIB_DIR})
set(TLL_LIBS ${AWSSDK_LINK_LIBRARIES} ${TLL_LIBS})
elseif(ENABLE_S3_INTERNAL)
if(OPENSSL_FOUND)
set(TLL_LIBS ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES} ${TLL_LIBS})
endif(OPENSSL_FOUND)
endif(ENABLE_S3_AWS)
endif(ENABLE_S3)
if(HAVE_LIBXML2)
set(TLL_LIBS ${TLL_LIBS} ${LIBXML2_LIBRARIES})
endif()
if(NOT WIN32)
if(NOT APPLE)
if(CMAKE_DL_LIBS)
2024-01-27 03:29:38 +08:00
target_link_libraries(netcdf ${CMAKE_DL_LIBS})
endif()
endif()
endif()
Add filter support to NCZarr Filter support has three goals: 1. Use the existing HDF5 filter implementations, 2. Allow filter metadata to be stored in the NumCodecs metadata format used by Zarr, 3. Allow filters to be used even when HDF5 is disabled Detailed usage directions are define in docs/filters.md. For now, the existing filter API is left in place. So filters are defined using ''nc_def_var_filter'' using the HDF5 style where the id and parameters are unsigned integers. This is a big change since filters affect many parts of the code. In the following, the terms "compressor" and "filter" and "codec" are generally used synonomously. ### Filter-Related Changes: * In order to support dynamic loading of shared filter libraries, a new library was added in the libncpoco directory; it helps to isolate dynamic loading across multiple platforms. * Provide a json parsing library for use by plugins; this is created by merging libdispatch/ncjson.c with include/ncjson.h. * Add a new _Codecs attribute to allow clients to see what codecs are being used; let ncdump -s print it out. * Provide special headers to help support compilation of HDF5 filters when HDF5 is not enabled: netcdf_filter_hdf5_build.h and netcdf_filter_build.h. * Add a number of new test to test the new nczarr filters. * Let ncgen parse _Codecs attribute, although it is ignored. ### Plugin directory changes: * Add support for the Blosc compressor; this is essential because it is the most common compressor used in Zarr datasets. This also necessitated adding a CMake FindBlosc.cmake file * Add NCZarr support for the big-four filters provided by HDF5: shuffle, fletcher32, deflate (zlib), and szip * Add a Codec defaulter (see docs/filters.md) for the big four filters. * Make plugins work with windows by properly adding __declspec declaration. ### Misc. Non-Filter Changes * Replace most uses of USE_NETCDF4 (deprecated) with USE_HDF5. * Improve support for caching * More fixes for path conversion code * Fix misc. memory leaks * Add new utility -- ncdump/ncpathcvt -- that does more or less the same thing as cygpath. * Add a number of new test to test the non-filter fixes. * Update the parsers * Convert most instances of '#ifdef _MSC_VER' to '#ifdef _WIN32'
2021-09-03 07:04:26 +08:00
if(TLL_LIBS)
list(REMOVE_DUPLICATES TLL_LIBS)
endif()
target_link_libraries(netcdf ${TLL_LIBS})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${TLL_LIBS})
if(MSVC)
set_target_properties(netcdf PROPERTIES
LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)
endif()
2012-09-14 02:27:23 +08:00
if(NOT MSVC)
if(BUILD_SHARED_LIBS)
set_target_properties(netcdf PROPERTIES LINK_FLAGS -shared)
endif()
endif()
2012-10-03 06:56:12 +08:00
if(ENABLE_SHARED_LIBRARY_VERSION)
set_target_properties(netcdf PROPERTIES
VERSION ${netCDF_LIB_VERSION}
SOVERSION ${netCDF_SO_VERSION}
)
endif(ENABLE_SHARED_LIBRARY_VERSION)
2015-10-21 00:10:55 +08:00
###
# The INCLUDES directive was introduced in 2.8.12.
# However, 2.8.11 is still the default on some
# popular linux distributions. See
# https://github.com/Unidata/netcdf-c/issues/135
# for more information.
###
if(${CMAKE_VERSION} VERSION_LESS 2.8.12)
2024-01-27 03:29:38 +08:00
install(
2015-10-21 00:10:55 +08:00
TARGETS netcdf EXPORT netCDFTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
else()
2024-01-27 03:29:38 +08:00
install(
2015-10-21 00:10:55 +08:00
TARGETS netcdf EXPORT netCDFTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
set(ALL_TLL_LIBS ${TLL_LIBS} PARENT_SCOPE)
set(NC_LIBS ${NC_LIBS} PARENT_SCOPE)
2024-01-27 03:29:38 +08:00
file(GLOB CUR_EXTRA_DIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
set(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} CMakeLists.txt Makefile.am)
ADD_EXTRA_DIST("${CUR_EXTRA_DIST}")