# "Unity build" found at
# https://cheind.wordpress.com/2009/12/10/reducing-compilation-time-unity-builds/
function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
    set(files ${${SOURCE_VARIABLE_NAME}})
    # Generate a unique filename for the unity build translation unit
    set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/ub_${UB_SUFFIX}.cpp)
    # Exclude all translation units from compilation
    set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true)
    # Open the ub file
    file(WRITE ${unit_build_file} "// Unity Build generated by CMake\n")
    # Add include statement for each translation unit
    foreach(source_file ${files})
        file(APPEND ${unit_build_file} "#include <${source_file}>\n")
    endforeach(source_file)
    # Complement list of translation units with the name of ub
    set(${SOURCE_VARIABLE_NAME} ${${SOURCE_VARIABLE_NAME}} ${unit_build_file} PARENT_SCOPE)
endfunction(enable_unity_build)


if(Qt5WebEngineWidgets_FOUND)
    add_definitions(
        -DHAVE_WEBENGINEWIDGETS
    )
endif(Qt5WebEngineWidgets_FOUND)

if(Qt5WebKitWidgets_FOUND)
    add_definitions(
        -DHAVE_WEBKITWIDGETS
    )
endif(Qt5WebKitWidgets_FOUND)

if(Qt5WebEngineWidgets_FOUND)
    if(Qt5WebKitWidgets_FOUND)
        message(STATUS "Found both QtWebEngine and QtWebKit, preferring to use QtWebEngine")
    else(Qt5WebKitWidgets_FOUND)
        message(STATUS "Found QtWebEngine, but not QtWebKit, therefore going to use QtWebEngine")
    endif(Qt5WebKitWidgets_FOUND)
else(Qt5WebEngineWidgets_FOUND)
    if(Qt5WebKitWidgets_FOUND)
        message(STATUS "Found QtWebKit, but not QtWebEngine, therefore going to use QtWebKit")
    else(Qt5WebKitWidgets_FOUND)
        message(STATUS "Found neither QtWebEngine nor QtWebKit, therefore trying to locate a KPart for HTML data")
    endif(Qt5WebKitWidgets_FOUND)
endif(Qt5WebEngineWidgets_FOUND)


add_subdirectory(
    config
)
add_subdirectory(
    data
)
add_subdirectory(
    io
)
add_subdirectory(
    processing
)
add_subdirectory(
    networking
)
add_subdirectory(
    gui
)
add_subdirectory(
    program
)
add_subdirectory(
    parts
)
if(
    BUILD_TESTING
)
    add_subdirectory(
        test
    )
endif(
    BUILD_TESTING
)

# install(
#     FILES
#     kbibtexnamespace.h
#     DESTINATION
#     ${INCLUDE_INSTALL_DIR}/kbibtex
#     COMPONENT
#     development
# )
