mirror of
https://github.com/HDFGroup/hdf5.git
synced 2026-09-25 04:09:44 +03:00
The previous `lib/cmake/hdf5-config.cmake` isn't in CMake's find_package search path since CMake expects that to be a common path with each package having it's own subdirectory. This changes it to `lib/cmake/hdf5/hdf5-config.cmake` so the config is now found when the install prefix is in `CMAKE_PREFIX_PATH`. This also sets `HDF5_USE_GNU_DIRS=ON` by default for non-Windows builds. Fixes #6137 Co-authored-by: Larry Knox <lrknox@hdfgroup.org>
206 lines
7.6 KiB
CMake
206 lines
7.6 KiB
CMake
#
|
|
# Copyright by The HDF Group.
|
|
# All rights reserved.
|
|
#
|
|
# This file is part of HDF5. The full HDF5 copyright notice, including
|
|
# terms governing use, modification, and redistribution, is contained in
|
|
# the LICENSE file, which can be found at the root of the source code
|
|
# distribution tree, or in https://www.hdfgroup.org/licenses.
|
|
# If you do not have access to either file, you may request a copy from
|
|
# help@hdfgroup.org.
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
# Setup output Directories
|
|
#-----------------------------------------------------------------------------
|
|
macro (SET_HDF_OUTPUT_DIRS package_prefix)
|
|
if (NOT ${package_prefix}_EXTERNALLY_CONFIGURED)
|
|
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY
|
|
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all Executables."
|
|
)
|
|
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY
|
|
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all Libraries"
|
|
)
|
|
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY
|
|
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all static libraries."
|
|
)
|
|
set (CMAKE_Fortran_MODULE_DIRECTORY
|
|
${PROJECT_BINARY_DIR}/mod CACHE PATH "Single Directory for all fortran modules."
|
|
)
|
|
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
|
if(_isMultiConfig)
|
|
set (CMAKE_TEST_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${HDF_CFG_NAME})
|
|
set (CMAKE_PDB_OUTPUT_DIRECTORY
|
|
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all pdb files."
|
|
)
|
|
else ()
|
|
set (CMAKE_TEST_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
|
endif ()
|
|
else ()
|
|
# if we are externally configured, but the project uses old cmake scripts
|
|
# this may not be set and utilities like H5detect will fail
|
|
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
|
|
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
|
|
endif ()
|
|
endif ()
|
|
endmacro ()
|
|
|
|
#-------------------------------------------------------------------------------
|
|
macro (SET_HDF_BUILD_TYPE)
|
|
get_property (_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
|
if (_isMultiConfig)
|
|
# HDF_CFG_BUILD_TYPE is used in the Fortran install commands for the build location of the .mod files
|
|
set (HDF_CFG_BUILD_TYPE \${CMAKE_INSTALL_CONFIG_NAME})
|
|
if (CMAKE_BUILD_TYPE)
|
|
# set the default to the specified command line define
|
|
set (HDF_CFG_NAME ${CMAKE_BUILD_TYPE})
|
|
else ()
|
|
# set the default to the MultiConfig variable
|
|
set (HDF_CFG_NAME "$<CONFIG>")
|
|
endif ()
|
|
else ()
|
|
set (HDF_CFG_BUILD_TYPE ".")
|
|
if (CMAKE_BUILD_TYPE)
|
|
set (HDF_CFG_NAME ${CMAKE_BUILD_TYPE})
|
|
else ()
|
|
set (HDF_CFG_NAME "Release")
|
|
endif ()
|
|
endif ()
|
|
endmacro ()
|
|
|
|
#-------------------------------------------------------------------------------
|
|
macro (TARGET_C_PROPERTIES wintarget libtype)
|
|
target_compile_options(${wintarget} PRIVATE
|
|
"$<$<C_COMPILER_ID:MSVC>:${WIN_COMPILE_FLAGS}>"
|
|
"$<$<CXX_COMPILER_ID:MSVC>:${WIN_COMPILE_FLAGS}>"
|
|
)
|
|
if(MSVC)
|
|
set_property(TARGET ${wintarget} APPEND PROPERTY LINK_FLAGS "${WIN_LINK_FLAGS}")
|
|
endif()
|
|
endmacro ()
|
|
|
|
macro (HDFTEST_COPY_FILE src dest target)
|
|
add_custom_command(
|
|
OUTPUT "${dest}"
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
ARGS -E copy_if_different "${src}" "${dest}"
|
|
DEPENDS "${src}"
|
|
)
|
|
list (APPEND ${target}_list "${dest}")
|
|
endmacro ()
|
|
|
|
macro (HDF_DIR_PATHS package_prefix)
|
|
set(_H5EXAMPLE_USE_GNU_DIRS_DEFAULT ON)
|
|
if (CMAKE_SYSTEM_NAME MATCHES "^Windows")
|
|
set(_H5EXAMPLE_USE_GNU_DIRS_DEFAULT OFF)
|
|
endif()
|
|
option (H5EXAMPLE_USE_GNU_DIRS "ON to use GNU Coding Standard install directory variables, OFF to use historical settings" ${_H5EXAMPLE_USE_GNU_DIRS_DEFAULT})
|
|
mark_as_advanced (H5EXAMPLE_USE_GNU_DIRS)
|
|
unset (_H5EXAMPLE_USE_GNU_DIRS_DEFAULT)
|
|
|
|
if (H5EXAMPLE_USE_GNU_DIRS)
|
|
include(GNUInstallDirs)
|
|
if (NOT ${package_prefix}_INSTALL_BIN_DIR)
|
|
set (${package_prefix}_INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR})
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_LIB_DIR)
|
|
set (${package_prefix}_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_JAR_DIR)
|
|
set (${package_prefix}_INSTALL_JAR_DIR ${CMAKE_INSTALL_LIBDIR})
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_INCLUDE_DIR)
|
|
set (${package_prefix}_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_MODULE_DIR)
|
|
set (${package_prefix}_INSTALL_MODULE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/mod)
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_DATA_DIR)
|
|
set (${package_prefix}_INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR})
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_CMAKE_DIR)
|
|
string(TOLOWER "${package_prefix}" package_prefix_lower)
|
|
set (${package_prefix}_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${package_prefix_lower})
|
|
unset(package_prefix_lower)
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_DOC_DIR)
|
|
set (${package_prefix}_INSTALL_DOC_DIR ${CMAKE_INSTALL_DOCDIR})
|
|
endif ()
|
|
message(STATUS "GNU: ${${package_prefix}_INSTALL_DOC_DIR}")
|
|
endif ()
|
|
|
|
if (APPLE)
|
|
option (${package_prefix}_BUILD_FRAMEWORKS "ON to build as frameworks libraries, OFF to build according to BUILD_SHARED_LIBS" OFF)
|
|
endif ()
|
|
|
|
if (NOT ${package_prefix}_INSTALL_BIN_DIR)
|
|
set (${package_prefix}_INSTALL_BIN_DIR bin)
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_LIB_DIR)
|
|
if (APPLE)
|
|
if (${package_prefix}_BUILD_FRAMEWORKS)
|
|
set (${package_prefix}_INSTALL_JAR_DIR ../Java)
|
|
else ()
|
|
set (${package_prefix}_INSTALL_JAR_DIR lib)
|
|
endif ()
|
|
set (${package_prefix}_INSTALL_FMWK_DIR ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
|
|
else ()
|
|
set (${package_prefix}_INSTALL_JAR_DIR lib)
|
|
endif ()
|
|
set (${package_prefix}_INSTALL_LIB_DIR lib)
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_INCLUDE_DIR)
|
|
set (${package_prefix}_INSTALL_INCLUDE_DIR include)
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_MODULE_DIR)
|
|
set (${package_prefix}_INSTALL_MODULE_DIR mod)
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_DATA_DIR)
|
|
if (NOT MSVC)
|
|
if (APPLE)
|
|
if (${package_prefix}_BUILD_FRAMEWORKS)
|
|
set (${package_prefix}_INSTALL_EXTRA_DIR ../SharedSupport)
|
|
else ()
|
|
set (${package_prefix}_INSTALL_EXTRA_DIR share)
|
|
endif ()
|
|
set (${package_prefix}_INSTALL_FWRK_DIR ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
|
|
endif ()
|
|
set (${package_prefix}_INSTALL_DATA_DIR share)
|
|
else ()
|
|
set (${package_prefix}_INSTALL_DATA_DIR ".")
|
|
endif ()
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_CMAKE_DIR)
|
|
set (${package_prefix}_INSTALL_CMAKE_DIR cmake)
|
|
endif ()
|
|
if (NOT ${package_prefix}_INSTALL_DOC_DIR)
|
|
set (${package_prefix}_INSTALL_DOC_DIR ${${package_prefix}_INSTALL_DATA_DIR})
|
|
endif ()
|
|
message(STATUS "Final: ${${package_prefix}_INSTALL_DOC_DIR}")
|
|
|
|
if (DEFINED ADDITIONAL_CMAKE_PREFIX_PATH AND EXISTS "${ADDITIONAL_CMAKE_PREFIX_PATH}")
|
|
set (CMAKE_PREFIX_PATH ${ADDITIONAL_CMAKE_PREFIX_PATH} ${CMAKE_PREFIX_PATH})
|
|
endif ()
|
|
|
|
SET_HDF_BUILD_TYPE()
|
|
|
|
SET_HDF_OUTPUT_DIRS(${package_prefix})
|
|
|
|
include (FetchContent)
|
|
endmacro ()
|
|
|
|
macro (ADD_H5_FLAGS h5_flag_var infile)
|
|
file (STRINGS ${infile} TEST_FLAG_STREAM)
|
|
list (LENGTH TEST_FLAG_STREAM len_flag)
|
|
if (len_flag GREATER 0)
|
|
math (EXPR _FP_LEN "${len_flag} - 1")
|
|
foreach (line RANGE 0 ${_FP_LEN})
|
|
list (GET TEST_FLAG_STREAM ${line} str_flag)
|
|
string (REGEX REPLACE "^#.*" "" str_flag "${str_flag}")
|
|
if (str_flag)
|
|
list (APPEND ${h5_flag_var} "${str_flag}")
|
|
endif ()
|
|
endforeach ()
|
|
endif ()
|
|
endmacro ()
|