cmake_minimum_required(VERSION 3.16)
project(CheckCxxWrap LANGUAGES NONE)

# Inspect exactly the override the wrapper will use, without falling back to
# another installation or requiring a compiler/CUDA for this check.
find_package(JlCxx REQUIRED CONFIG PATHS "${JlCxx_DIR}" NO_DEFAULT_PATH)
foreach(target JlCxx::cxxwrap_julia JlCxx::cxxwrap_julia_stl)
    if(NOT TARGET ${target})
        message(FATAL_ERROR "Missing target ${target}")
    endif()
    get_target_property(includes ${target} INTERFACE_INCLUDE_DIRECTORIES)
    if(NOT includes)
        message(FATAL_ERROR "Missing include directories for ${target}")
    endif()
    foreach(path IN LISTS includes)
        if(path STREQUAL "")
            continue()
        endif()
        if(NOT IS_DIRECTORY "${path}")
            message(FATAL_ERROR "Missing include directory: ${path}")
        endif()
    endforeach()
    get_target_property(configs ${target} IMPORTED_CONFIGURATIONS)
    set(properties IMPORTED_LOCATION)
    foreach(config IN LISTS configs)
        string(TOUPPER "${config}" config)
        list(APPEND properties "IMPORTED_LOCATION_${config}")
    endforeach()
    set(found_location FALSE)
    foreach(property IN LISTS properties)
        get_target_property(path ${target} ${property})
        if(path)
            set(found_location TRUE)
            if(NOT EXISTS "${path}")
                message(FATAL_ERROR "Missing library: ${path}")
            endif()
        endif()
    endforeach()
    if(NOT found_location)
        message(FATAL_ERROR "Missing library location for ${target}")
    endif()
endforeach()
