hpc-io / vfd-gds

Other
16 stars 11 forks source link

`CMakeLists.txt` should use relative install dirs #15

Open Jacobfaib opened 1 month ago

Jacobfaib commented 1 month ago

CMakeLists.txt has

if(NOT HDF5_VFD_GDS_INSTALL_BIN_DIR)
  set(HDF5_VFD_GDS_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
endif()
if(NOT HDF5_VFD_GDS_INSTALL_LIB_DIR)
  set(HDF5_VFD_GDS_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib)
endif()
if(NOT HDF5_VFD_GDS_INSTALL_INCLUDE_DIR)
  # Interface include will default to prefix/include
  set(HDF5_VFD_GDS_INSTALL_INTERFACE include)
  set(HDF5_VFD_GDS_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
else()
  set(HDF5_VFD_GDS_INSTALL_INTERFACE ${HDF5_VFD_GDS_INSTALL_INCLUDE_DIR})
endif()
if(NOT HDF5_VFD_GDS_INSTALL_DATA_DIR)
  set(HDF5_VFD_GDS_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share)
endif()

The main issue is that this sets the install prefix in stone at configure-time, making any install-time prefix modifications impossible:

$ cmake --install build --prefix /another/prefix # does not do what you expect!

These should be amended to:

  1. Using the GNUInstallDirs variables for portability.
  2. Using relative paths.
include(GNUInstallDirs)
if(NOT HDF5_VFD_GDS_INSTALL_BIN_DIR)
  set(HDF5_VFD_GDS_INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR})
endif()
if(NOT HDF5_VFD_GDS_INSTALL_LIB_DIR)
  set(HDF5_VFD_GDS_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT HDF5_VFD_GDS_INSTALL_INCLUDE_DIR)
  # Interface include will default to prefix/include
  set(HDF5_VFD_GDS_INSTALL_INTERFACE include)
  set(HDF5_VFD_GDS_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
else()
  set(HDF5_VFD_GDS_INSTALL_INTERFACE ${HDF5_VFD_GDS_INSTALL_INCLUDE_DIR})
endif()
if(NOT HDF5_VFD_GDS_INSTALL_DATA_DIR)
  set(HDF5_VFD_GDS_INSTALL_DATA_DIR ${CMAKE_INSTALL_DATAROOTDIR})
endif()

At install-time CMake will prefixes relative paths with CMAKE_INSTALL_PREFIX automatically, meaning that the behavior is unchanged.