-# This is done here so that relative search paths are more reasonable
-if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt")
+set(IRRLICHTMT_BUILD_DIR "" CACHE PATH "Path to IrrlichtMt build directory.")
+if(NOT "${IRRLICHTMT_BUILD_DIR}" STREQUAL "")
+ find_package(IrrlichtMt QUIET
+ PATHS "${IRRLICHTMT_BUILD_DIR}"
+ NO_DEFAULT_PATH
+ )
+
+ if(NOT TARGET IrrlichtMt::IrrlichtMt)
+ # find_package() searches certain subdirectories. ${PATH}/cmake is not
+ # the only one, but it is the one where IrrlichtMt is supposed to export
+ # IrrlichtMtConfig.cmake
+ message(FATAL_ERROR "Could not find IrrlichtMtConfig.cmake in ${IRRLICHTMT_BUILD_DIR}/cmake.")
+ endif()
+elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt")