# This is not gonna work for windows

find_package(PkgConfig)

pkg_check_modules(SHADERC          QUIET shaderc) #shared
pkg_check_modules(SHADERC_COMBINED QUIET shaderc_combined)
pkg_check_modules(SHADERC_STATIC   QUIET shaderc_static) #static

find_library(SHADERC_LOCATION NAMES shaderc_shared HINTS
  ${SHADERC_LIBRARY_DIRS}
  ${SHADERC_STATIC_LIBRARY_DIRS}
  )
find_library(SHADERC_STATIC_LOCATION NAMES shaderc HINTS
  ${SHADERC_STATIC_LIBRARY_DIRS}
  ${SHADERC_LIBRARY_DIRS}
  )
find_library(SHADERC_COMBINED_LOCATION NAMES shaderc_combined HINTS
  ${SHADERC_COMBINED_LIBRARY_DIRS}
  )

#no idea why, but you get either INCLUDE_DIRS or INCLUDEDIR
set(SHADERC_INCLUDE_DIRS ${SHADERC_INCLUDE_DIRS} ${SHADERC_INCLUDEDIR})
set(SHADERC_STATIC_INCLUDE_DIRS ${SHADERC_STATIC_INCLUDE_DIRS} ${SHADERC_STATIC_INCLUDEDIR})
set(SHADERC_COMBINED_INCLUDE_DIRS ${SHADERC_COMBINED_INCLUDE_DIRS} ${SHADERC_COMBINED_INCLUDEDIR})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Shaderc DEFAULT_MSG
  SHADERC_LIBRARIES          SHADERC_INCLUDE_DIRS
  SHADERC_STATIC_LIBRARIES   SHADERC_STATIC_INCLUDE_DIRS
  SHADERC_COMBINED_LIBRARIES SHADERC_COMBINED_INCLUDE_DIRS
  )
mark_as_advanced(SHADERC_LIBRARIES          SHADERC_INCLUDE_DIRS
  SHADERC_STATIC_LIBRARIES   SHADERC_STATIC_INCLUDE_DIRS
  SHADERC_COMBINED_LIBRARIES SHADERC_COMBINED_INCLUDE_DIRS)


#### shaderc
if (SHADERC_FOUND AND NOT TARGET shaderc::shaderc)
  add_library(shaderc::shaderc UNKNOWN IMPORTED)
  set_target_properties(shaderc::shaderc  PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
    IMPORTED_LOCATION "${SHADERC_LOCATION}"
    INTERFACE_LINK_DIRECTORIES "${SHADERC_LIBRARY_DIRS}"
    INTERFACE_LINK_LIBRARIES "${SHADERC_LIBRARIES}"
    INTERFACE_INCLUDE_DIRECTORIES "${SHADERC_INCLUDE_DIRS}"
    )
endif()

if (SHADERC_STATIC_FOUND AND NOT TARGET shaderc::static)
  add_library(shaderc::static UNKNOWN IMPORTED)
  set_target_properties(shaderc::static PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
    IMPORTED_LOCATION "${SHADERC_STATIC_LOCATION}"
    INTERFACE_LINK_DIRECTORIES "${SHADERC_STATIC_LIBRARY_DIRS}"
    INTERFACE_LINK_LIBRARIES "${SHADERC_STATIC_LIBRARIES}"
    INTERFACE_INCLUDE_DIRECTORIES "${SHADERC_STATIC_INCLUDE_DIRS}"
    )
endif()

if (SHADERC_COMBINED_FOUND AND NOT TARGET shaderc::combined)
  add_library(shaderc::combined UNKNOWN IMPORTED)
  set_target_properties(shaderc::combined PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
    IMPORTED_LOCATION "${SHADERC_COMBINED_LOCATION}"
    INTERFACE_LINK_DIRECTORIES "${SHADERC_COMBINED_LIBRARY_DIRS}"
    INTERFACE_LINK_LIBRARIES "${SHADERC_COMBINED_LIBRARIES}"
    INTERFACE_INCLUDE_DIRECTORIES "${SHADERC_COMBINED_INCLUDE_DIRS}"
    )
endif()
