#------------------------------------------------------------------------------#
# Copyright (c) 2014 Los Alamos National Security, LLC
# All rights reserved.
#------------------------------------------------------------------------------#

function(cinch_make_common_header target headers)

    option(ENABLE_COMMON_HEADER "Enable common header creation" OFF)

    if(ENABLE_COMMON_HEADER)
        set(output "${CMAKE_BINARY_DIR}/include/${target}.h")

        file(WRITE "${output}" "/*--------------------------------------"
                 "--------------------------------------* \n")
        file(APPEND "${output}"
            " * Common header for ${target} project.\n")
        file(APPEND "${output}"
            " * This file was automatically generated by cinch.\n")
        file(APPEND "${output}" " *--------------------------------------"
            "--------------------------------------*/\n")

        string(REGEX REPLACE "-" "_" guard ${target})

        file(APPEND "${output}" "\n")
        file(APPEND "${output}" "#ifndef ${guard}_h\n")
        file(APPEND "${output}" "#define ${guard}_h\n")
        file(APPEND "${output}" "\n")

        foreach(hdr ${headers})
            file(APPEND "${output}" "#include <${hdr}>\n")
        endforeach(hdr)

        file(APPEND "${output}" "\n")
        file(APPEND "${output}" "#endif // ${guard}_h\n")

        include_directories(${CMAKE_BINARY_DIR}/include)
        install(FILES ${output} DESTINATION include${CINCH_CONFIG_INSTTAG})
    endif(ENABLE_COMMON_HEADER)

endfunction(cinch_make_common_header)

#------------------------------------------------------------------------------#
# Formatting options for emacs and vim.
# vim: set tabstop=4 shiftwidth=4 expandtab :
#------------------------------------------------------------------------------#
