## Copyright 2009-2021 Intel Corporation
## SPDX-License-Identifier: Apache-2.0

SET(EMBREE_ZE_LOADER_RUNTIME_LINK_NAME_LINUX "libze_loader.so.1" CACHE STRING "Name of the ze_loader lib that is looked for at runtime on Linux")
SET(EMBREE_ZE_LOADER_RUNTIME_LINK_NAME_WINDOWS "ze_loader.dll" CACHE STRING "Name of the ze_loader lib that is looked for at runtime on Windows")

MARK_AS_ADVANCED(EMBREE_ZE_LOADER_RUNTIME_LINK_NAME_LINUX)
MARK_AS_ADVANCED(EMBREE_ZE_LOADER_RUNTIME_LINK_NAME_WINDOWS)

ADD_LIBRARY(ze_wrapper STATIC ze_wrapper.cpp)

target_include_directories(ze_wrapper INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
TARGET_COMPILE_DEFINITIONS(ze_wrapper PRIVATE ZE_LOADER_NAME_LINUX="${EMBREE_ZE_LOADER_RUNTIME_LINK_NAME_LINUX}")
TARGET_COMPILE_DEFINITIONS(ze_wrapper PRIVATE ZE_LOADER_NAME_WINDOWS="${EMBREE_ZE_LOADER_RUNTIME_LINK_NAME_WINDOWS}")

IF (NOT EMBREE_SYCL_L0_RTAS_BUILDER)
  TARGET_LINK_LIBRARIES(ze_wrapper PUBLIC embree_rthwif)
ELSE()
  TARGET_COMPILE_DEFINITIONS(ze_wrapper PRIVATE ZE_RAYTRACING_DISABLE_INTERNAL_BUILDER)
ENDIF()

SET_PROPERTY(TARGET ze_wrapper PROPERTY FOLDER common)
SET_PROPERTY(TARGET ze_wrapper APPEND PROPERTY COMPILE_FLAGS " ${FLAGS_LOWEST}")

IF (EMBREE_STATIC_LIB)
  INSTALL(TARGETS ze_wrapper EXPORT ze_wrapper-targets ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel)
  INSTALL(EXPORT ze_wrapper-targets DESTINATION "${EMBREE_CMAKEEXPORT_DIR}" COMPONENT devel)
ENDIF()
