# get prefix of the install tree from this file's location (usually `get_filename_component(DIRECTORY)` a number of times on the current file's location
set("${CMAKE_FIND_PACKAGE_NAME}_CMAKE_PREFIX_PATH_save" "${CMAKE_PREFIX_PATH}")
list(INSERT CMAKE_PREFIX_PATH 0
${${CMAKE_FIND_PACKAGE_NAME}_PREFIX_PATH})
# The above code handles ospray and embree in the same install prefix.
# If embree is elsewhere, include a helper file optionally.
include("${CMAKE_CURRENT_LIST_DIR}/embree-helpers.cmake" OPTIONAL)
find_package(embree) # much more likely to Just Work now
# Restore the prefix.
set(CMAKE_PREFIX_PATH "${${CMAKE_FIND_PACKAGE_NAME}_CMAKE_PREFIX_PATH_save}")
unset("${CMAKE_FIND_PACKAGE_NAME}_CMAKE_PREFIX_PATH_save")
The helper file can be controlled by an option like OSPRAY_RELOCATABLE_INSTALL (and installed only if this isn't set). This is to help the install tree not bake in host filesystem paths. The helper file would contain something like:
if (NOT embree_DIR)
set(embree_DIR "<path ospray had when configured>")
endif ()
In VTK, we use a pattern akin to the following:
The helper file can be controlled by an option like
OSPRAY_RELOCATABLE_INSTALL
(and installed only if this isn't set). This is to help the install tree not bake in host filesystem paths. The helper file would contain something like:and always exist in the build tree.