Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the rpath with option - plugins fail without #5298

Merged
merged 10 commits into from
Feb 14, 2025
4 changes: 3 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"ZLIB_USE_LOCALCONTENT": "OFF",
"LIBAEC_USE_LOCALCONTENT": "OFF",
"HDF5_USE_ZLIB_STATIC": "ON",
"HDF5_USE_LIBAEC_STATIC": "ON"
"HDF5_USE_LIBAEC_STATIC": "ON",
"HDF5_ENABLE_SZIP_SUPPORT": "ON",
"HDF5_ENABLE_ZLIB_SUPPORT": "ON"
}
},
{
Expand Down
23 changes: 23 additions & 0 deletions config/cmake/HDF5Macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ macro (H5_SET_LIB_OPTIONS libtarget libname libtype libpackage)
endif ()
endif ()
HDF_SET_LIB_OPTIONS (${libtarget} ${LIB_OUT_NAME} ${libtype})

#-- Apple Specific install_name for libraries
if (APPLE)
option (HDF5_BUILD_WITH_INSTALL_NAME "Build with library install_name set to the installation path" OFF)
if (HDF5_BUILD_WITH_INSTALL_NAME)
set_target_properties (${libtarget} PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
Copy link
Contributor

@haampie haampie Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not immediately related to the issue, is it? The default install name as of CMake 3.0 is @rpath/lib<name>.dylib (before it was lib<name>.dylib). When users link against the library, it copies the install name @rpath/lib<name>.dylib as a load command, so rpaths set by the user in the dependent executable/library are respected when searching for libhdf5.dylib at runtime. Then the situation is exactly the same as on Linux, where users also have to set an rpath. If you set it to an absolute path, then rpaths no longer work, and the library is always opened directly by absolute path (not relocatable). So, bit unclear why this is added now, and why the apple situation should be different from linux.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added as it was previously removed - can be removed if some apple developer knows this is not needed.

BUILD_WITH_INSTALL_RPATH ${HDF5_BUILD_WITH_INSTALL_NAME}
Copy link
Contributor

@haampie haampie Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why BUILD_WITH_INSTALL_RPATH?

Copy link
Contributor Author

@byrnHDF byrnHDF Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definition:


BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link the target in the build tree with the INSTALL_RPATH. This takes precedence over SKIP_BUILD_RPATH and avoids the need for relinking before installation.

This property is initialized by the value of the CMAKE_BUILD_WITH_INSTALL_RPATH variable if it is set when a target is created.

If policy CMP0068 is not NEW, this property also controls use of INSTALL_NAME_DIR in the build tree on macOS. Either way, the BUILD_WITH_INSTALL_NAME_DIR target property takes precedence.


Eliminating this option then just forces the change onto the user?

Copy link
Contributor

@haampie haampie Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the idea of adding these lines was to use $ORIGIN/.. style relative rpaths also during the build? (But then why if (APPLE)?) That I think is redundant, cause cmake sets build specific rpaths for any target you're linking, including the path to just-built libhdf5.dylib. CMake knows better where executables and libraries are located relatively during the build, and it may differ from where they are upon install, so using install rpath during the build is not helpful.

If you don't set anything related to build rpaths, and you need to run a just-built executable as part of the build (before install), cmake ensures that these executables can find their libraries. If you meddle with it, then maybe not.

I think the only case where you may benefit from setting build rpaths yourself is when you run just-built executables during the build that dlopen(...) just-built libraries that cmake is not aware of as part of target_link_libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the plugins.

I'm not aware of it's use by us in our CI. However, I also don't develop with macs either.
It is one of those long-ago implemented options, that just get brought along. I put it back, along with the other code to fix CI and plugins, but maybe it wasn't necessary?

)
endif ()
if (HDF5_BUILD_FRAMEWORKS)
if (${libtype} MATCHES "SHARED")
# adapt target to build frameworks instead of dylibs
set_target_properties(${libtarget} PROPERTIES
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
FRAMEWORK TRUE
FRAMEWORK_VERSION ${HDF5_PACKAGE_VERSION_MAJOR}
MACOSX_FRAMEWORK_IDENTIFIER org.hdfgroup.${libtarget}
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${HDF5_PACKAGE_VERSION_MAJOR}
MACOSX_FRAMEWORK_BUNDLE_VERSION ${HDF5_PACKAGE_VERSION_MAJOR})
endif ()
endif ()
endif ()
endmacro ()

# Initialize the list of VFDs to be used for testing and create a test folder for each VFD
Expand Down
10 changes: 10 additions & 0 deletions config/cmake/HDFMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,16 @@ macro (HDF_DIR_PATHS package_prefix)
endif ()
message(STATUS "Final: ${${package_prefix}_INSTALL_DOC_DIR}")

# Append the needed INSTALL_RPATH for HDF Standard binary packages
if (APPLE)
list(APPEND CMAKE_INSTALL_RPATH
"@loader_path/../${${package_prefix}_INSTALL_LIB_DIR}"
"@loader_path/"
)
else ()
list(APPEND CMAKE_INSTALL_RPATH "\$ORIGIN/../${${package_prefix}_INSTALL_LIB_DIR}:\$ORIGIN/")
endif ()

if (DEFINED ADDITIONAL_CMAKE_PREFIX_PATH AND EXISTS "${ADDITIONAL_CMAKE_PREFIX_PATH}")
set (CMAKE_PREFIX_PATH ${ADDITIONAL_CMAKE_PREFIX_PATH} ${CMAKE_PREFIX_PATH})
endif ()
Expand Down
6 changes: 6 additions & 0 deletions release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ Bug Fixes since HDF5-2.0.0 release

Configuration
-------------
- The relative rpaths ($ORIGIN / @loader_path) are appended to the CMAKE_INSTALL_RPATH

The RPATH settings were removed by a pull-request #5271, but the settings are needed
under certain conditions. These settings have been restored by appending the necessary paths
and will not override/overwrite any existing settings.

- When using a system installed zlib library, the shared library is expected to
be found in the system library path.

Expand Down
Loading