netcdf-c/liblib/CMakeLists.txt

108 lines
2.7 KiB
CMake

SET(CMAKE_INCLUDE_CURRENT_DIR ON)
INCLUDE_DIRECTORIES(".")
SET(liblib_LIBS dispatch netcdf3)
#####
# Add target objects/modules based on options.
#####
IF(USE_HDF5 OR USE_NETCDF4)
SET(liblib_LIBS ${liblib_LIBS} netcdf4)
ENDIF()
IF(USE_PNETCDF)
SET(liblib_LIBS ${liblib_LIBS} netcdf5)
ENDIF()
IF(USE_DAP)
SET(liblib_LIBS ${liblib_LIBS} oc2 dap2)
ENDIF()
IF(BUILD_CDMREMOTE)
SET(liblib_LIBS ${liblib_LIBS} cdmr)
ENDIF()
FOREACH(LIBS ${liblib_LIBS})
SET(LARGS ${LARGS} $<TARGET_OBJECTS:${LIBS}>)
ENDFOREACH()
ADD_LIBRARY(netcdf ${LIB_TYPE} stub.c ${LARGS} )
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()
#####
# Add dependencies required for linking.
#####
SET(TLL_LIBS "")
SET(TLL_LIBS ${TLL_LIBS} ${HAVE_LIBM} ${ZLIB_LIBRARY})
IF(HAVE_LIBDL)
SET(TLL_LIBS ${LIBDL} ${TLL_LIBS})
ENDIF()
IF(USE_HDF5 OR USE_NETCDF4)
IF(NOT MSVC)
# Some version of cmake define HDF5_hdf5_LIBRARY instead of
# HDF5_LIBRARY. Same with HDF5_HL_LIBRARY
IF(HDF5_hdf5_LIBRARY AND NOT HDF5_C_LIBRARY)
SET(HDF5_C_LIBRARY ${HDF5_hdf5_LIBRARY})
ENDIF()
IF(HDF5_hdf5_hl_LIBRARY AND NOT HDF5_HL_LIBRARY)
SET(HDF5_HL_LIBRARY ${HDF5_hdf5_hl_LIBRARY})
ENDIF()
SET(TLL_LIBS ${HDF5_C_LIBRARY} ${HDF5_HL_LIBRARY} ${TLL_LIBS} ${SZIP_LIBRARY})
ELSE() # Windows CMake defines HDF5_LIBRARIES.
SET(TLL_LIBS ${HDF5_LIBRARIES} ${TLL_LIBS} ${SZIP_LIBRARY})
ENDIF()
ENDIF()
IF(USE_DAP)
SET(TLL_LIBS ${TLL_LIBS} ${CURL_LIBRARY})
ENDIF()
IF(USE_HDF4)
SET(TLL_LIBS ${TLL_LIBS} ${HDF4_LIBRARIES})
ENDIF()
IF(ENABLE_PNETCDF AND PNETCDF)
SET(TLL_LIBS ${TLL_LIBS} ${PNETCDF})
ENDIF()
TARGET_LINK_LIBRARIES(netcdf ${TLL_LIBS})
IF(MSVC)
SET_TARGET_PROPERTIES(netcdf PROPERTIES
LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)
ENDIF()
IF(NOT MSVC)
IF(BUILD_SHARED_LIBS)
SET_TARGET_PROPERTIES(netcdf PROPERTIES LINK_FLAGS -shared)
ENDIF()
ENDIF()
SET_TARGET_PROPERTIES(netcdf PROPERTIES
VERSION ${netCDF_VERSION}
SOVERSION ${netCDF_SO_VERSION})
INSTALL(TARGETS netcdf EXPORT netcdf-targets RUNTIME DESTINATION bin COMPONENT libraries
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
)
SET(ALL_TLL_LIBS ${TLL_LIBS} PARENT_SCOPE)
SET(NC_LIBS ${NC_LIBS} PARENT_SCOPE)
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}")