diff --git a/HDF5Examples/C/HL/test-pc.sh b/HDF5Examples/C/HL/test-pc.sh index d9ef9620b72..9efbdf86383 100755 --- a/HDF5Examples/C/HL/test-pc.sh +++ b/HDF5Examples/C/HL/test-pc.sh @@ -151,6 +151,7 @@ if test $status -ne 0 then echo " FAILED!" else + echo " Passed" $ECHO_N "Testing C/HL/h5ex_lite2...$ECHO_C" exout ./h5ex_lite2 >tmp.test cmp -s $TESTDIR/tmp.test $top_srcdir/$currentpath/tfiles/h5ex_lite2.tst diff --git a/HDF5Examples/C/test-pc.sh b/HDF5Examples/C/test-pc.sh index c4ea8229ba0..eea98c930c4 100755 --- a/HDF5Examples/C/test-pc.sh +++ b/HDF5Examples/C/test-pc.sh @@ -33,7 +33,7 @@ for dir in */; do then echo "Entering directory: $dir" ( - mkdir "$top_builddir/$currentpath/$dir" + mkdir -p "$top_builddir/$currentpath/$dir" cd "$dir" ./test-pc.sh $top_srcdir $top_builddir $currentpath/$dir # Execute script in the subdirectory status=$? diff --git a/HDF5Examples/CXX/test-pc.sh b/HDF5Examples/CXX/test-pc.sh index 5f0b45d99e6..ab263fdaac4 100755 --- a/HDF5Examples/CXX/test-pc.sh +++ b/HDF5Examples/CXX/test-pc.sh @@ -33,7 +33,7 @@ for dir in */; do then echo "Entering directory: $dir" ( - mkdir "$top_builddir/$currentpath/$dir" + mkdir -p "$top_builddir/$currentpath/$dir" cd "$dir" ./test-pc.sh $top_srcdir $top_builddir $currentpath/$dir # Execute script in the subdirectory status=$? diff --git a/HDF5Examples/FORTRAN/test-pc.sh b/HDF5Examples/FORTRAN/test-pc.sh index 5f0b45d99e6..ab263fdaac4 100755 --- a/HDF5Examples/FORTRAN/test-pc.sh +++ b/HDF5Examples/FORTRAN/test-pc.sh @@ -33,7 +33,7 @@ for dir in */; do then echo "Entering directory: $dir" ( - mkdir "$top_builddir/$currentpath/$dir" + mkdir -p "$top_builddir/$currentpath/$dir" cd "$dir" ./test-pc.sh $top_srcdir $top_builddir $currentpath/$dir # Execute script in the subdirectory status=$? diff --git a/HDF5Examples/JAVA/test-pc.sh b/HDF5Examples/JAVA/test-pc.sh index 5f0b45d99e6..ab263fdaac4 100755 --- a/HDF5Examples/JAVA/test-pc.sh +++ b/HDF5Examples/JAVA/test-pc.sh @@ -33,7 +33,7 @@ for dir in */; do then echo "Entering directory: $dir" ( - mkdir "$top_builddir/$currentpath/$dir" + mkdir -p "$top_builddir/$currentpath/$dir" cd "$dir" ./test-pc.sh $top_srcdir $top_builddir $currentpath/$dir # Execute script in the subdirectory status=$? diff --git a/HDF5Examples/test-pc.sh b/HDF5Examples/test-pc.sh index 61f624aa93d..7232d4f9ee8 100755 --- a/HDF5Examples/test-pc.sh +++ b/HDF5Examples/test-pc.sh @@ -24,7 +24,7 @@ nerrors=0 return_val=0 -mkdir "$top_builddir" +mkdir -p "$top_builddir" cd "$top_srcdir" # Loop through all subdirectories for dir in */; do @@ -34,7 +34,7 @@ for dir in */; do then echo "Entering directory: $dir" ( - mkdir "$top_builddir/$dir" + mkdir -p "$top_builddir/$dir" cd "$dir" ./test-pc.sh $top_srcdir/ $top_builddir/ $dir # Execute script in the subdirectory status=$? diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt index 08b90e0981c..db49a4836bc 100644 --- a/c++/src/CMakeLists.txt +++ b/c++/src/CMakeLists.txt @@ -176,22 +176,17 @@ set (_PKG_CONFIG_EXEC_PREFIX \${prefix}) set (_PKG_CONFIG_LIBDIR \${exec_prefix}/${HDF5_INSTALL_LIB_DIR}) set (_PKG_CONFIG_INCLUDEDIR \${prefix}/${HDF5_INSTALL_INCLUDE_DIR}) set (_PKG_CONFIG_LIBNAME "${HDF5_CPP_LIB_NAME}") +set (_PKG_CONFIG_HL_LIBNAME "${HDF5_HL_CPP_LIB_NAME}") set (_PKG_CONFIG_VERSION "${HDF5_PACKAGE_VERSION}") set (PKG_CONFIG_LIBNAME "${HDF5_CPP_LIB_NAME}") if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") set (PKG_CONFIG_LIBNAME "${PKG_CONFIG_LIBNAME}${CMAKE_DEBUG_POSTFIX}") endif () -set (_PKG_CONFIG_LIBS_PRIVATE) - -if (BUILD_STATIC_LIBS) - set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () -if (BUILD_SHARED_LIBS) - set (_PKG_CONFIG_SH_LIBS "${_PKG_CONFIG_SH_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () - +set (_PKG_CONFIG_EXTRA_CFLAGS) +set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") set (_PKG_CONFIG_REQUIRES "${HDF5_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") +set (_PKG_CONFIG_LIBS_PRIVATE) set (_PKG_CONFIG_REQUIRES_PRIVATE "${HDF5_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") configure_file ( @@ -205,7 +200,7 @@ install ( COMPONENT cpplibraries ) -if (H5_HAVE_PKGCONFIG AND NOT HDF5_BUILD_HL_LIB) +if (H5_HAVE_PKGCONFIG) set (_PKG_CONFIG_COMPILER ${HDF5_H5CC_CXX_COMPILER}) configure_file ( ${HDF_CONFIG_DIR}/libh5cc.in diff --git a/config/libh5cc.in b/config/libh5cc.in index 939698c3640..b16de1d8729 100644 --- a/config/libh5cc.in +++ b/config/libh5cc.in @@ -11,6 +11,31 @@ # help@hdfgroup.org. ## +# Constants definitions +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +# Variables to control final behavior of script +do_show="no" +do_compile="yes" +do_link="yes" + +# Add the HDF5 library directory to the rpath of the +# built executable/library by default +add_rpath="yes" + +# Variables for arguments passed to pkg-config and compiler +pc_args="${HDF5_PKG_CONFIG_ARGS}" +compile_args="" +prefix="" +libdir="" + +# Variables for flags passed to pkg-config and compiler +pc_flags="" + +status=$EXIT_SUCCESS + +# Determine name and location of script prg=$0 if [ ! -e "$prg" ]; then case $prg in @@ -21,12 +46,15 @@ fi dir=$( cd -P -- "$(dirname -- "$prg")/.." && pwd -P ) || exit -prg=$dir/bin/$(basename -- "$prg") || exit -#printf '%s\n' "$prg" -#printf 'dir is %s\n' "$dir" +prog_name=$(basename -- "$prg") || exit +prg=$dir/bin/$prog_name -pc_args="" +prefix=$dir + +libdir=$dir/@HDF5_INSTALL_LIB_DIR@ + +export PKG_CONFIG_PATH=$libdir/pkgconfig # Show the configuration summary of the library recorded in the # libhdf5.settings file residing in the lib directory. @@ -38,50 +66,214 @@ showconfigure() usage() { # "How-to use" message. - echo "usage: $prg [OPTIONS] " + echo "usage: $prog_name [OPTIONS] " echo " OPTIONS:" - echo " -help This help message." - echo " -show Show the commands without executing them" - echo " -showconfig Show the HDF5 library configuration summary" + echo " -help | --help | -h This help message." + echo " -echo Show all the shell commands executed" + echo " -show Show the commands without executing them" + echo " -showconfig Show the HDF5 library configuration summary" + echo " -shlib Compile with shared HDF5 libraries [default for" + echo " hdf5 built with shared libraries]" + echo " -noshlib Compile with static HDF5 libraries [default for" + echo " hdf5 built without shared libraries]" + echo " -nohl By default, $prog_name builds and links against the" + echo " high-level HDF5 library, if it is available." + echo " Specifying the -nohl option disables this behavior." + echo " -norpath By default, $prog_name adds the library directory" + echo " of the HDF5 installation to the rpath of the resulting" + echo " executable/library when linking against shared HDF5" + echo " libraries. If this behavior is not desired or is" + echo " problematic for a particular compiler/linker, specifying" + echo " the -norpath option disables this behavior." + echo " -c Compile and assemble without linking. When combined" + echo " with -show, displays only the compile flags without" + echo " displaying the linking flags. Otherwise, passes the" + echo " '-c' flag to the compiler, where it's assumed that" + echo " the flag will have the behavior of 'compile and" + echo " assemble without linking'. Note that this may not" + echo " be the case for some compilers." echo " " - echo " - the pkg-config compile line options for the compiler" - echo " that was used to compile HDF5." - echo " Use pkg-config --help for more information" - echo " on which options are available. $prg passes pkg-config options" - echo " through as those options use double-underscores." + echo " - the normal compile line options for your compiler." + echo " $prog_name uses the same compiler you used to compile" + echo " HDF5, unless an alternate compiler is specified at" + echo " configuration time. Check with your compiler's man" + echo " pages for more information on which options are needed." echo " " - echo " NOTE: pkg-config is required to be installed on your system and" - echo " using --static requires a static version of the C runtime library" - echo " to be have been installed on your system." + echo " All options specific to $prog_name should appear BEFORE" + echo " any options specified for ." + echo " " + echo " You can override whether or not to use shared or static HDF5 libraries" + echo " by setting the following environment variable:" + echo " " + echo " HDF5_USE_SHLIB=[yes|no] - use shared or static version of the HDF5 library." + echo " precedence is given to the -shlib/-noshlib options." + echo " [default: yes except when built with only" + echo " static libraries]" + echo " " + echo " $prog_name uses pkg-config to determine additional flags to pass to the" + echo " compiler. You can specify any options to pass to pkg-config by setting the" + echo " following environment variable:" + echo " " + echo " HDF5_PKG_CONFIG_ARGS" echo " " - exit $EXIT_FAILURE } -export PKG_CONFIG_PATH=$dir/@HDF5_INSTALL_LIB_DIR@/pkgconfig +if test $# -eq 0; then + # No parameters specified, issue usage statement and exit. + usage + exit $EXIT_FAILURE +fi + +# If a shared library is available, the default will be to use it. If the only +# available library is static, it will be used by default. The user can +# override either default, although choosing an unavailable library will result +# in errors from h5cc. +SHARED_AVAILABLE="@BUILD_SHARED_LIBS@" +STATIC_AVAILABLE="@BUILD_STATIC_LIBS@" +if test "${SHARED_AVAILABLE}" = "ON"; then + USE_SHARED_LIB="${HDF5_USE_SHLIB:-yes}" +else + USE_SHARED_LIB="${HDF5_USE_SHLIB:-no}" +fi + +# If the high-level library is available, the default will be to build and +# link against it. +USE_HL_LIB="yes" +HL_AVAILABLE="@HDF5_BUILD_HL_LIB@" +if test "${HL_AVAILABLE}" = "ON"; then + HL_LIB_NAME="@_PKG_CONFIG_HL_LIBNAME@" +else + USE_HL_LIB="no" +fi for arg in $@ ; do case "$arg" in + -help|--help|-h) + usage + exit $EXIT_SUCCESS + ;; + -echo) + shift + set -x + ;; + -show) + shift + # Delay showing command-line until arguments have been processed + do_show="yes" + ;; -showconfig) showconfigure exit $status ;; - -show) + -shlib) shift - echo @_PKG_CONFIG_COMPILER@ "$@" `pkg-config $pc_args --define-variable=prefix=$dir --cflags --libs @_PKG_CONFIG_LIBNAME@` - exit $status + USE_SHARED_LIB="yes" ;; - -help) - usage - exit $status + -noshlib) + shift + USE_SHARED_LIB="no" ;; - --*) - # gather pkg-config specific options - pc_args="$pc_args $arg" + -nohl) + shift + USE_HL_LIB="no" + ;; + -norpath) + shift + add_rpath="no" + ;; + -c) + compile_args="${compile_args:+${compile_args} }$arg" + shift + + do_link="no" ;; *) - @_PKG_CONFIG_COMPILER@ "$@" `pkg-config $pc_args --define-variable=prefix=$dir --cflags --libs @_PKG_CONFIG_LIBNAME@` - status=$? - exit $status + # For now, any unrecognized arguments are passed directly on to the + # compiler to simplify handling of them. It's assumed that any + # h5cc-specific options come before these arguments. If this proves + # to be insufficient, arguments should be stored somewhere and + # shifted off the command-line. ;; esac done + +# Check availability of default or requested HDF5 library type +if test "${USE_SHARED_LIB}" = "yes" -a "${SHARED_AVAILABLE}" != "ON"; then + echo "error: linking against shared HDF5 libraries was requested, but shared HDF5 libraries aren't available" >&2 + exit $EXIT_FAILURE +elif test "${USE_SHARED_LIB}" = "no" -a "${STATIC_AVAILABLE}" != "ON"; then + echo "error: linking against static HDF5 libraries was requested, but static HDF5 libraries aren't available" >&2 + exit $EXIT_FAILURE +fi + +# Add in relevant flags to pkg-config command +pc_args="${pc_args:+${pc_args} }--define-variable=prefix=$prefix" + +if test "$do_compile" = "yes"; then + pc_args="${pc_args:+${pc_args} }--cflags" +fi + +if test "$do_link" = "yes"; then + pc_args="${pc_args:+${pc_args} }--libs" +fi + +if test "$USE_SHARED_LIB" = "no"; then + pc_args="${pc_args:+${pc_args} }--static" +fi + +pc_args="${pc_args:+${pc_args} }@_PKG_CONFIG_LIBNAME@" + +# Build and link against high-level library, +# unless requested not to. +if test "${USE_HL_LIB}" = "yes"; then + pc_args="${pc_args:+${pc_args} }${HL_LIB_NAME}" +fi + +# Evaluate pkg-config command for later use +pc_flags="`pkg-config $pc_args`" +if test $? -ne 0; then + echo "pkg-config failed with arguments: $pc_args" >&2 + exit $EXIT_FAILURE +fi + +# If linking against static HDF5 libraries, fixup the +# flags generated by pkg-config to point to the static +# libraries +if test "$do_link" = "yes" -a "$USE_SHARED_LIB" = "no"; then + # Escape '/' in libdir path to not conflict with sed delimiter + escaped_libdir=$(echo "$libdir" | sed 's/\//\\\//g') + + # Replace flags of form '-lhdf5*' with path to matching static library + edited_pc_flags=$(echo "$pc_flags" | sed -E 's/-l(hdf5[a-z0-9_]*)/'"${escaped_libdir}\/"'lib\1.a/g') + if test $? -ne 0; then + echo "couldn't edit flags to compile against static HDF5 libraries" >&2 + exit $EXIT_FAILURE + fi + + pc_flags=$edited_pc_flags +fi + +# If linking against shared HDF5 libraries, add the +# HDF5 library directory to the rpath of the executable +# if not requested not to. +if test "$do_link" = "yes" -a "$USE_SHARED_LIB" = "yes" -a "$add_rpath" = "yes"; then + # Simply assume that the -Wl,-rpath, form is acceptable + # for the compiler and -rpath is a linker option. Add + # compiler/linker-specific logic as needed. + compile_args="${compile_args:+${compile_args} }-Wl,-rpath,$libdir" +fi + +# If -show was passed, only output the command-line, don't execute it +if test "$do_show" = "yes"; then + echo @_PKG_CONFIG_COMPILER@ ${compile_args:+"${compile_args} "}"$@" "$pc_flags" + exit $EXIT_SUCCESS +fi + +@_PKG_CONFIG_COMPILER@ $compile_args "$@" $pc_flags +status=$? + +if test $status -ne 0; then + echo "compile failed with command: @_PKG_CONFIG_COMPILER@ $compile_args $@ $pc_flags" >&2 +fi + +exit $status diff --git a/config/libhdf5.fpc.in b/config/libhdf5.fpc.in index 8a4d532a8db..36a91548906 100644 --- a/config/libhdf5.fpc.in +++ b/config/libhdf5.fpc.in @@ -10,7 +10,7 @@ Version: @_PKG_CONFIG_VERSION@ Cflags: -I${includedir} -I${moddir} Fflags: -I${moddir} -Libs: -L${libdir} @_PKG_CONFIG_SH_LIBS@ +Libs: -L${libdir} @_PKG_CONFIG_LIBS@ Requires: @_PKG_CONFIG_REQUIRES@ -Libs.private: @_PKG_CONFIG_LIBS@ @_PKG_CONFIG_LIBS_PRIVATE@ +Libs.private: @_PKG_CONFIG_LIBS_PRIVATE@ Requires.private: @_PKG_CONFIG_REQUIRES_PRIVATE@ diff --git a/config/libhdf5.pc.in b/config/libhdf5.pc.in index 3cb42d280e9..8d43f1ec367 100644 --- a/config/libhdf5.pc.in +++ b/config/libhdf5.pc.in @@ -7,8 +7,8 @@ Name: @_PKG_CONFIG_LIBNAME@ Description: HDF5 (Hierarchical Data Format 5) Software Library Version: @_PKG_CONFIG_VERSION@ -Cflags: -I${includedir} -Libs: -L${libdir} @_PKG_CONFIG_SH_LIBS@ +Cflags: -I${includedir} @_PKG_CONFIG_EXTRA_CFLAGS@ +Libs: -L${libdir} @_PKG_CONFIG_LIBS@ Requires: @_PKG_CONFIG_REQUIRES@ -Libs.private: @_PKG_CONFIG_LIBS@ @_PKG_CONFIG_LIBS_PRIVATE@ +Libs.private: @_PKG_CONFIG_LIBS_PRIVATE@ Requires.private: @_PKG_CONFIG_REQUIRES_PRIVATE@ diff --git a/fortran/src/CMakeLists.txt b/fortran/src/CMakeLists.txt index c1b106ede4d..613b90b7730 100644 --- a/fortran/src/CMakeLists.txt +++ b/fortran/src/CMakeLists.txt @@ -588,22 +588,17 @@ if (NOT HDF5_INSTALL_MOD_FORTRAN MATCHES "NO") set (_PKG_CONFIG_MODULEDIR \${prefix}/${HDF5_INSTALL_INCLUDE_DIR}) endif () set (_PKG_CONFIG_LIBNAME "${HDF5_F90_LIB_NAME}") +set (_PKG_CONFIG_HL_LIBNAME "${HDF5_HL_F90_LIB_NAME}") set (_PKG_CONFIG_VERSION "${HDF5_PACKAGE_VERSION}") set (PKG_CONFIG_LIBNAME "${HDF5_F90_LIB_NAME}") if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") set (PKG_CONFIG_LIBNAME "${PKG_CONFIG_LIBNAME}${CMAKE_DEBUG_POSTFIX}") endif () -set (_PKG_CONFIG_LIBS_PRIVATE) - -if (BUILD_STATIC_LIBS) - set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () -if (BUILD_SHARED_LIBS) - set (_PKG_CONFIG_SH_LIBS "${_PKG_CONFIG_SH_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () - +set (_PKG_CONFIG_EXTRA_CFLAGS) +set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") set (_PKG_CONFIG_REQUIRES "${HDF5_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") +set (_PKG_CONFIG_LIBS_PRIVATE "-l${HDF5_F90_C_LIB_NAME}") set (_PKG_CONFIG_REQUIRES_PRIVATE "${HDF5_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") configure_file ( @@ -617,7 +612,7 @@ install ( COMPONENT fortlibraries ) -if (H5_HAVE_PKGCONFIG AND NOT HDF5_BUILD_HL_LIB) +if (H5_HAVE_PKGCONFIG) set (_PKG_CONFIG_COMPILER ${HDF5_H5CC_Fortran_COMPILER}) configure_file ( ${HDF_CONFIG_DIR}/libh5cc.in diff --git a/hl/c++/src/CMakeLists.txt b/hl/c++/src/CMakeLists.txt index 38c3a1cee53..890946a9c96 100644 --- a/hl/c++/src/CMakeLists.txt +++ b/hl/c++/src/CMakeLists.txt @@ -100,17 +100,11 @@ if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") set (PKG_CONFIG_LIBNAME "${PKG_CONFIG_LIBNAME}${CMAKE_DEBUG_POSTFIX}") endif () +set (_PKG_CONFIG_EXTRA_CFLAGS) +set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") +set (_PKG_CONFIG_REQUIRES "${HDF5_CPP_LIB_NAME} = ${HDF5_PACKAGE_VERSION}, ${HDF5_HL_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") set (_PKG_CONFIG_LIBS_PRIVATE) - -if (BUILD_STATIC_LIBS) - set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () -if (BUILD_SHARED_LIBS) - set (_PKG_CONFIG_SH_LIBS "${_PKG_CONFIG_SH_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () - -set (_PKG_CONFIG_REQUIRES "${HDF5_HL_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") -set (_PKG_CONFIG_REQUIRES_PRIVATE "${HDF5_HL_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") +set (_PKG_CONFIG_REQUIRES_PRIVATE "${HDF5_CPP_LIB_NAME} = ${HDF5_PACKAGE_VERSION}, ${HDF5_HL_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") configure_file ( ${HDF_CONFIG_DIR}/libhdf5.pc.in @@ -122,18 +116,3 @@ install ( DESTINATION ${HDF5_INSTALL_LIB_DIR}/pkgconfig COMPONENT hlcpplibraries ) - -if (H5_HAVE_PKGCONFIG) - set (_PKG_CONFIG_COMPILER ${HDF5_H5CC_CXX_COMPILER}) - configure_file ( - ${HDF_CONFIG_DIR}/libh5cc.in - ${HDF5_BINARY_DIR}/CMakeFiles/h5c++ - @ONLY - ) - install ( - FILES ${HDF5_BINARY_DIR}/CMakeFiles/h5c++ - DESTINATION ${HDF5_INSTALL_BIN_DIR} - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - COMPONENT cpplibraries - ) -endif () diff --git a/hl/fortran/src/CMakeLists.txt b/hl/fortran/src/CMakeLists.txt index 6e96e9f0193..1a089811590 100644 --- a/hl/fortran/src/CMakeLists.txt +++ b/hl/fortran/src/CMakeLists.txt @@ -343,16 +343,10 @@ if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") set (PKG_CONFIG_LIBNAME "${PKG_CONFIG_LIBNAME}${CMAKE_DEBUG_POSTFIX}") endif () -set (_PKG_CONFIG_LIBS_PRIVATE) - -if (BUILD_STATIC_LIBS) - set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () -if (BUILD_SHARED_LIBS) - set (_PKG_CONFIG_SH_LIBS "${_PKG_CONFIG_SH_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () - +set (_PKG_CONFIG_EXTRA_CFLAGS) +set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") set (_PKG_CONFIG_REQUIRES "${HDF5_F90_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") +set (_PKG_CONFIG_LIBS_PRIVATE "-l${HDF5_HL_F90_C_LIB_NAME}") set (_PKG_CONFIG_REQUIRES_PRIVATE "${HDF5_F90_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") configure_file ( @@ -365,31 +359,3 @@ install ( DESTINATION ${HDF5_INSTALL_LIB_DIR}/pkgconfig COMPONENT hlfortlibraries ) - -if (H5_HAVE_PKGCONFIG) - set (_PKG_CONFIG_COMPILER ${HDF5_H5CC_Fortran_COMPILER}) - configure_file ( - ${HDF_CONFIG_DIR}/libh5cc.in - ${HDF5_BINARY_DIR}/CMakeFiles/h5fc - @ONLY - ) - install ( - FILES ${HDF5_BINARY_DIR}/CMakeFiles/h5fc - DESTINATION ${HDF5_INSTALL_BIN_DIR} - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - COMPONENT fortlibraries - ) - if (HDF5_ENABLE_PARALLEL AND MPI_Fortran_FOUND) - configure_file ( - ${HDF_CONFIG_DIR}/libh5cc.in - ${HDF5_BINARY_DIR}/CMakeFiles/h5pfc - @ONLY - ) - install ( - FILES ${HDF5_BINARY_DIR}/CMakeFiles/h5pfc - DESTINATION ${HDF5_INSTALL_BIN_DIR} - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - COMPONENT fortlibraries - ) - endif () -endif () diff --git a/hl/src/CMakeLists.txt b/hl/src/CMakeLists.txt index 3d6f8c850f5..2e61bf483ad 100644 --- a/hl/src/CMakeLists.txt +++ b/hl/src/CMakeLists.txt @@ -132,16 +132,10 @@ if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") set (PKG_CONFIG_LIBNAME "${PKG_CONFIG_LIBNAME}${CMAKE_DEBUG_POSTFIX}") endif () -set (_PKG_CONFIG_LIBS_PRIVATE) - -if (BUILD_STATIC_LIBS) - set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () -if (BUILD_SHARED_LIBS) - set (_PKG_CONFIG_SH_LIBS "${_PKG_CONFIG_SH_LIBS} -l${PKG_CONFIG_LIBNAME}") -endif () - +set (_PKG_CONFIG_EXTRA_CFLAGS) +set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") set (_PKG_CONFIG_REQUIRES "${HDF5_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") +set (_PKG_CONFIG_LIBS_PRIVATE) set (_PKG_CONFIG_REQUIRES_PRIVATE "${HDF5_LIB_NAME} = ${HDF5_PACKAGE_VERSION}") configure_file ( @@ -155,35 +149,6 @@ install ( COMPONENT hllibraries ) -if (H5_HAVE_PKGCONFIG) - set (_PKG_CONFIG_COMPILER ${HDF5_H5CC_C_COMPILER}) - configure_file ( - ${HDF_CONFIG_DIR}/libh5cc.in - ${HDF5_BINARY_DIR}/CMakeFiles/h5cc - @ONLY - ) - install ( - FILES ${HDF5_BINARY_DIR}/CMakeFiles/h5cc - DESTINATION ${HDF5_INSTALL_BIN_DIR} - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - COMPONENT libraries - ) - if (HDF5_ENABLE_PARALLEL AND MPI_C_FOUND) - #legacy requires a different name - configure_file ( - ${HDF_CONFIG_DIR}/libh5cc.in - ${HDF5_BINARY_DIR}/CMakeFiles/h5pcc - @ONLY - ) - install ( - FILES ${HDF5_BINARY_DIR}/CMakeFiles/h5pcc - DESTINATION ${HDF5_INSTALL_BIN_DIR} - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - COMPONENT libraries - ) - endif () -endif () - #----------------------------------------------------------------------------- # Option to build documentation #----------------------------------------------------------------------------- diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 571013fb91b..e97a9363dd2 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -199,6 +199,39 @@ New Features Library: -------- + - Aligned the CMake compiler wrappers with the old Autotools versions + + The versions of h5cc, h5fc, h5c++, etc. generated by CMake were missing + several options and features from the Autotools counterparts. Some of + these options and features have now been implemented in the CMake versions, + while some of them have not: + + * The missing --help/-h, -c, -echo and -shlib/-noshlib options have + been implemented. + + * The -prefix option was not implemented, as it didn't appear to + function in the Autotools wrappers and is generally covered by + pkg-config in the CMake wrappers. + + * A new -nohl option has been added to avoid building and linking + against the high-level HDF5 libraries if desired. + + * Similar to the Autotools wrappers, the CMake wrappers now add the + HDF5 installation library directory to the rpath of the resulting + executable/library by default when linking against shared HDF5 + libraries. This behavior can be avoided by specifying the new + -norpath option. + + * Parsing of the HDF5_USE_SHLIB environment variable has been added + to determine whether to link against shared or static HDF5 libraries. + Precedence is still given to the -shlib/-noshlib options. + + * Parsing of the HDF5_PKG_CONFIG_ARGS environment variable has been + added to separate pkg-config-specific options from compiler-specific + options and prevent conflicts between them. + + Several issues were also fixed in the pkg-config files that are generated + by CMake. - The file format has been updated to 4.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 672a2bdb663..f7e246ffbbe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1338,33 +1338,93 @@ set (_PKG_CONFIG_EXEC_PREFIX \${prefix}) set (_PKG_CONFIG_LIBDIR \${exec_prefix}/${HDF5_INSTALL_LIB_DIR}) set (_PKG_CONFIG_INCLUDEDIR \${prefix}/${HDF5_INSTALL_INCLUDE_DIR}) set (_PKG_CONFIG_LIBNAME "${HDF5_LIB_NAME}") +set (_PKG_CONFIG_HL_LIBNAME "${HDF5_HL_LIB_NAME}") set (_PKG_CONFIG_VERSION "${HDF5_PACKAGE_VERSION}") -set (PKGCONFIG_LIBNAME "${HDF5_LIB_NAME}") +set (PKG_CONFIG_LIBNAME "${HDF5_LIB_NAME}") if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer") - set (PKGCONFIG_LIBNAME "${PKGCONFIG_LIBNAME}${CMAKE_DEBUG_POSTFIX}") + set (PKG_CONFIG_LIBNAME "${PKG_CONFIG_LIBNAME}${CMAKE_DEBUG_POSTFIX}") endif () -#foreach (libs ${LINK_LIBS}) -# set (_PKG_CONFIG_LIBS_PRIVATE "${_PKG_CONFIG_LIBS_PRIVATE} -l${libs}") -#endforeach () +set (_PKG_CONFIG_EXTRA_CFLAGS) +set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKG_CONFIG_LIBNAME}") +set (_PKG_CONFIG_REQUIRES) +set (_PKG_CONFIG_LIBS_PRIVATE) +set (_PKG_CONFIG_REQUIRES_PRIVATE) + +# Process LINK_LIBS and LINK_COMP_LIBS for private dependencies +# to add to pkg-config files. Note that, for simplicity, the below +# assumes dependency libraries don't have pkg-config support. +foreach (lib ${LINK_LIBS}) + # If this is a regular library, add it to the list of + # libraries for the Libs.private field. Otherwise, do + # special processing for library targets. + if (NOT TARGET ${lib}) + # Avoid generator expressions related to flags for now. + # A more complete solution will be needed in order to + # correctly evaluate these. + string (GENEX_STRIP "${lib}" lib_genex_stripped) + if ("${lib}" STREQUAL "${lib_genex_stripped}") + set (_PKG_CONFIG_LIBS_PRIVATE "${_PKG_CONFIG_LIBS_PRIVATE} -l${lib}") + endif () + + continue () + endif () + + # If the target isn't an imported target, it's probably + # one that we created ourselves and set the OUTPUT_NAME + # property for. This is a fragile assumption, but should + # work for now. If the library is an imported target, we + # have to do more special processing. + get_target_property (lib_is_imported ${lib} IMPORTED) + if (NOT lib_is_imported) + get_target_property (libname ${lib} OUTPUT_NAME) + if (NOT "${libname}" MATCHES "libname-NOTFOUND") + set (_PKG_CONFIG_LIBS_PRIVATE "${_PKG_CONFIG_LIBS_PRIVATE} -l${libname}") + else () + message (WARNING "library name not retrieved for library ${lib}") + endif () + + continue () + endif () + + # Attempt to retrieve anything needed from the imported target + get_target_property (lib_interface_compile_opts ${lib} INTERFACE_COMPILE_OPTIONS) + if (lib_interface_compile_opts) + foreach (compile_opt ${lib_interface_compile_opts}) + set (_PKG_CONFIG_EXTRA_CFLAGS "${_PKG_CONFIG_EXTRA_CFLAGS} ${compile_opt}") + endforeach () + endif () + + # For now, naively assume that any libraries listed are in the form + # -llibname and can be directly added to the pkg-config files. This + # is not always the case and more sophisticated processing of libraries + # will be needed eventually. + get_target_property (lib_interface_link_libs ${lib} INTERFACE_LINK_LIBRARIES) + if (lib_interface_link_libs) + foreach (interface_link_lib ${lib_interface_link_libs}) + set (lib_namespace_substr -1) + + # Simple heuristic to filter out library dependencies of a target + # that are targets themselves. More complex processing is needed + # here to get the full list of libraries to be linked. + string (FIND "${interface_link_lib}" "::" lib_namespace_substr) + if (NOT lib_namespace_substr EQUAL -1) + message (WARNING "filtered out library dependency ${interface_link_lib} of library ${lib} when generating pkg-config file") + continue () + endif () + + set (_PKG_CONFIG_LIBS_PRIVATE "${_PKG_CONFIG_LIBS_PRIVATE} ${interface_link_lib}") + endforeach() + endif () +endforeach () # The settings for the compression libs depends on if they have pkconfig support # Assuming they don't foreach (libs ${LINK_COMP_LIBS}) -# set (_PKG_CONFIG_REQUIRES_PRIVATE "${_PKG_CONFIG_REQUIRES_PRIVATE} -l${libs}") get_target_property (libname ${libs} OUTPUT_NAME) set (_PKG_CONFIG_LIBS_PRIVATE "${_PKG_CONFIG_LIBS_PRIVATE} -l${libname}") endforeach () -#if (BUILD_STATIC_LIBS) -# set (_PKG_CONFIG_LIBS "${_PKG_CONFIG_LIBS} -l${PKGCONFIG_LIBNAME}") -#endif () -if (BUILD_SHARED_LIBS) - set (_PKG_CONFIG_SH_LIBS "${_PKG_CONFIG_SH_LIBS} -l${PKGCONFIG_LIBNAME}") -endif () - -set (_PKG_CONFIG_REQUIRES) - configure_file ( ${HDF_CONFIG_DIR}/libhdf5.pc.in ${HDF5_BINARY_DIR}/CMakeFiles/${HDF5_LIB_CORENAME}.pc @@ -1376,7 +1436,7 @@ install ( COMPONENT libraries ) -if (H5_HAVE_PKGCONFIG AND NOT HDF5_BUILD_HL_LIB) +if (H5_HAVE_PKGCONFIG) set (_PKG_CONFIG_COMPILER ${HDF5_H5CC_C_COMPILER}) configure_file ( ${HDF_CONFIG_DIR}/libh5cc.in