# creates a dummy target for displaying the headers of header-only libs in the IDE
include(target_cpp_standard)
include(CMakeParseArguments)
function(add_header_only_library target)
    # dummy target prefix
    # parse arguments
    set(option_value_params
        GENERATE_DUMMY_TARGET
    )
    set(one_value_params
        DUMMY_POSTFIX
        CXX_STD
    )
    set(multi_value_params
        SOURCES
        INCLUDE_DIRS
        LINK_LIBS
    )
    cmake_parse_arguments(
        header_only
        "${option_value_params}"
        "${one_value_params}"
        "${multi_value_params}"
        ${ARGN}
    )
    add_library(${target} INTERFACE)
    target_sources(${target} INTERFACE $<BUILD_INTERFACE:${header_only_SOURCES}>)
    target_include_directories(${target} INTERFACE ${header_only_INCLUDE_DIRS})
    target_link_libraries(${target} INTERFACE ${header_only_LINK_LIBS})
    set_target_cxx_standard_interface(${target} ${header_only_CXX_STD})
    # create dummy file for making the target "compilable"
    if(header_only_GENERATE_DUMMY_TARGET)
        file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/${target}${header_only_DUMMY_POSTFIX}.cpp")
        file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${target}${header_only_DUMMY_POSTFIX}.cpp" "// [AUTOGENERATED] This is dummy file for making the header only library sources visible and editable in the IDE.")
        add_library("${target}${header_only_DUMMY_POSTFIX}" STATIC ${header_only_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/${target}${header_only_DUMMY_POSTFIX}.cpp")
        target_link_libraries("${target}${header_only_DUMMY_POSTFIX}" PRIVATE ${target})
    endif()
endfunction()