Files
hdf5/tools/lib/CMakeLists.txt
Scot Breitenfeld a7ec64a857 Split static targets into separate optional target [UPDATED] (#6216)
Build-tree exports can't diverge from install-tree exports — the export(EXPORT ...) reads directly from the install export sets. No manual list to keep in sync.

Removed 3 global variables (HDF5_STATIC_LIBRARIES_TO_EXPORT, HDF5_JAVA_LIBRARIES_TO_EXPORT, HDF5_UTILS_TO_EXPORT) and their ~21 set_global_variable calls across tool/utility files.

Fixed the static-only build bug in the PR where the base export set was guarded by BUILD_SHARED_LIBS, breaking tools export.

Removed redundant utils in export files — the PR was dumping tools into all three build-tree export files (java, static, shared). Now they correctly appear only in the base export.
2026-02-24 17:04:25 -06:00

148 lines
6.9 KiB
CMake

#-----------------------------------------------------------------------------
# CMake configuration for HDF5 tools library
# This file sets up the build, formatting, and installation rules for the HDF5 tools library (static and shared).
# It handles source/header definitions, compiler options, linking, and export for the HDF5 tools suite.
#-----------------------------------------------------------------------------
cmake_minimum_required (VERSION 3.26)
project (HDF5_TOOLS_LIB C)
#-----------------------------------------------------------------------------
# Define Sources and Headers for the HDF5 tools library
#-----------------------------------------------------------------------------
set (H5_TOOLS_LIB_SOURCES
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5diff.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5diff_array.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5diff_attr.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5diff_dset.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5diff_util.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_dump.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_filters.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_ref.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_str.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_type.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_utils.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5trav.c
${HDF5_TOOLS_LIB_SOURCE_DIR}/io_timer.c
)
set (H5_TOOLS_LIB_HDRS
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5trav.h
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools.h
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_dump.h
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_error.h
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_utils.h
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_str.h
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_ref.h
${HDF5_TOOLS_LIB_SOURCE_DIR}/h5diff.h
${HDF5_TOOLS_LIB_SOURCE_DIR}/io_timer.h
)
if (BUILD_STATIC_LIBS)
#--------------------------------------------------------------------------
# Build the static HDF5 tools library
#--------------------------------------------------------------------------
add_library (${HDF5_TOOLS_LIB_TARGET} STATIC ${H5_TOOLS_LIB_SOURCES} ${H5_TOOLS_LIB_HDRS})
target_include_directories (${HDF5_TOOLS_LIB_TARGET}
PRIVATE "${HDF5_TOOLS_LIB_SOURCE_DIR};${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>"
INTERFACE "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${HDF5_INSTALL_INCLUDE_DIR}>"
)
target_compile_options(${HDF5_TOOLS_LIB_TARGET} PRIVATE "${HDF5_CMAKE_C_FLAGS}")
#target_compile_definitions(${HDF5_TOOLS_LIB_TARGET} PRIVATE H5_TOOLS_DEBUG)
#target_compile_definitions(${HDF5_TOOLS_LIB_TARGET} PRIVATE H5DIFF_DEBUG)
TARGET_C_PROPERTIES (${HDF5_TOOLS_LIB_TARGET} STATIC)
target_link_libraries (${HDF5_TOOLS_LIB_TARGET}
PUBLIC ${HDF5_LIB_TARGET}
PRIVATE "$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:MPI::MPI_C>"
)
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_TOOLS_LIB_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_TOOLS_LIB_TARGET} ${HDF5_TOOLS_LIB_NAME} STATIC 0)
set_target_properties (${HDF5_TOOLS_LIB_TARGET} PROPERTIES FOLDER libraries/tools)
set (install_targets_static ${HDF5_TOOLS_LIB_TARGET})
endif ()
if (BUILD_SHARED_LIBS)
#--------------------------------------------------------------------------
# Build the shared HDF5 tools library
#--------------------------------------------------------------------------
add_library (${HDF5_TOOLS_LIBSH_TARGET} SHARED ${H5_TOOLS_LIB_SOURCES} ${H5_TOOLS_LIB_HDRS})
target_include_directories (${HDF5_TOOLS_LIBSH_TARGET}
PRIVATE "${HDF5_TOOLS_LIB_SOURCE_DIR};${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>"
INTERFACE "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${HDF5_INSTALL_INCLUDE_DIR}>"
)
target_compile_options(${HDF5_TOOLS_LIBSH_TARGET} PRIVATE "${HDF5_CMAKE_C_FLAGS}")
target_compile_definitions(${HDF5_TOOLS_LIBSH_TARGET}
PUBLIC "H5_BUILT_AS_DYNAMIC_LIB"
#PRIVATE H5_TOOLS_DEBUG
#PRIVATE H5DIFF_DEBUG
)
TARGET_C_PROPERTIES (${HDF5_TOOLS_LIBSH_TARGET} SHARED)
target_link_libraries (${HDF5_TOOLS_LIBSH_TARGET}
PUBLIC ${HDF5_LIBSH_TARGET}
PRIVATE "$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:MPI::MPI_C>"
)
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_TOOLS_LIBSH_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_TOOLS_LIBSH_TARGET} ${HDF5_TOOLS_LIB_NAME} SHARED "TOOLS")
set_target_properties (${HDF5_TOOLS_LIBSH_TARGET} PROPERTIES FOLDER libraries/tools)
set (install_targets_shared ${HDF5_TOOLS_LIBSH_TARGET})
endif ()
#-----------------------------------------------------------------------------
# Add Target to clang-format if enabled
#-----------------------------------------------------------------------------
if (HDF5_ENABLE_FORMATTERS)
if (BUILD_STATIC_LIBS)
clang_format (HDF5_TOOLS_SRC_FORMAT ${HDF5_TOOLS_LIB_TARGET})
else ()
clang_format (HDF5_TOOLS_SRC_FORMAT ${HDF5_TOOLS_LIBSH_TARGET})
endif ()
endif ()
##############################################################################
##############################################################################
### I N S T A L L A T I O N ###
##############################################################################
##############################################################################
#-----------------------------------------------------------------------------
# Add Target(s) to CMake Install for import into other projects
#-----------------------------------------------------------------------------
if (HDF5_EXPORTED_TARGETS)
if (BUILD_SHARED_LIBS)
INSTALL_TARGET_PDB (${HDF5_TOOLS_LIBSH_TARGET} ${HDF5_INSTALL_BIN_DIR} toolslibraries)
install (
TARGETS
${install_targets_shared}
EXPORT
${HDF5_EXPORTED_TARGETS}
LIBRARY DESTINATION ${HDF5_INSTALL_LIB_DIR} COMPONENT toolslibraries
ARCHIVE DESTINATION ${HDF5_INSTALL_LIB_DIR} COMPONENT toolslibraries
RUNTIME DESTINATION ${HDF5_INSTALL_BIN_DIR} COMPONENT toolslibraries
FRAMEWORK DESTINATION ${HDF5_INSTALL_FWRK_DIR} COMPONENT toolslibraries
INCLUDES DESTINATION include
)
endif ()
if (BUILD_STATIC_LIBS)
INSTALL_TARGET_PDB (${HDF5_TOOLS_LIB_TARGET} ${HDF5_INSTALL_LIB_DIR} toolslibraries)
if (BUILD_SHARED_LIBS)
set (_static_export ${HDF5_EXPORTED_TARGETS}_static)
else ()
set (_static_export ${HDF5_EXPORTED_TARGETS})
endif ()
install (
TARGETS
${install_targets_static}
EXPORT
${_static_export}
LIBRARY DESTINATION ${HDF5_INSTALL_LIB_DIR} COMPONENT toolslibraries
ARCHIVE DESTINATION ${HDF5_INSTALL_LIB_DIR} COMPONENT toolslibraries
RUNTIME DESTINATION ${HDF5_INSTALL_BIN_DIR} COMPONENT toolslibraries
FRAMEWORK DESTINATION ${HDF5_INSTALL_FWRK_DIR} COMPONENT toolslibraries
INCLUDES DESTINATION include
)
endif ()
endif ()