PyImath CMake targets are not relocatable
SimonBoorer opened this issue · comments
The PyImath CMake targets are not relocatable because they add Boost_INCLUDE_DIR to the INTERFACE_INCLUDE_DIRECTORIES:
https://github.com/AcademySoftwareFoundation/Imath/blob/main/src/python/config/ModuleDefine.cmake#L39-L41
Note that it is not advisable to populate the INSTALL_INTERFACE of the INTERFACE_INCLUDE_DIRECTORIES of a target with absolute paths to the include directories of dependencies. That would hard-code into installed packages the include directory paths for dependencies as found on the machine the package was made on.
The INSTALL_INTERFACE of the INTERFACE_INCLUDE_DIRECTORIES is only suitable for specifying the required include directories for headers provided with the target itself, not those provided by the transitive dependencies listed in its INTERFACE_LINK_LIBRARIES target property. Those dependencies should themselves be targets that specify their own header locations in INTERFACE_INCLUDE_DIRECTORIES.
The resulting ImathTargets.cmake contain hard-coded paths to the Boost include directories:
set_target_properties(Imath::PyImath_Python3_10 PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "IMATH_DLL"
INTERFACE_COMPILE_FEATURES "cxx_std_14"
INTERFACE_INCLUDE_DIRECTORIES "C:/src/boost-py310-win-x64-d_e562/include"
INTERFACE_LINK_LIBRARIES "Imath::Imath"
)
It also prevents building when Boost is contained in the source directory:
CMake Error in src/python/PyImath/CMakeLists.txt:
Target "PyImath_Python3_10" INTERFACE_INCLUDE_DIRECTORIES property contains
path:
"C:/src/Imath/artifacts/Stevedore/boost-py310-win-x64-d_e562/include"
which is prefixed in the source directory