
# Call with the output var, then with one or more dependencies (imported targets)
function(get_search_dirs _var)
    set(properties_to_check LOCATION)
    set(configs ${CMAKE_CONFIGURATION_TYPES})
    if(CMAKE_BUILD_TYPE)
        list(APPEND configs ${CMAKE_BUILD_TYPE})
    endif()

    if(configs)
        foreach(config ${configs})
            string(TOUPPER ${config} config_uc)
            list(APPEND properties_to_check LOCATION_${config_uc})
        endforeach()
    endif()

    set(searchdirs)
    foreach(dep ${ARGN})
        if(TARGET ${dep})
            foreach(prop ${properties_to_check})
                get_property(loc_set TARGET ${dep} PROPERTY ${prop} SET)
                if(loc_set)
                    get_property(loc TARGET ${dep} PROPERTY ${prop})
                    get_filename_component(dir "${loc}" DIRECTORY)
                    list(APPEND searchdirs "${dir}")
                endif()
            endforeach()
        endif()
    endforeach()

    if(searchdirs)
        list(REMOVE_DUPLICATES searchdirs)
    endif()
    set(${_var} ${searchdirs} PARENT_SCOPE)
endfunction()
