# For each library, fuses all sources to a single .cc file.
#----------------------------------------------------------

# Start with new content
string(CONCAT output_content "" "// This file is autogenerated. Do not modify it.\n\n")

# Patches arguments so that cmake interprate it as a list.
string (REPLACE " " ";" ozz_target_source_files "${ozz_target_source_files}")

# Concat all sources to the output.
foreach(src_file ${ozz_target_source_files})
  get_filename_component(src_file_ext ${src_file} EXT)

  # Handle source files.
  if(src_file_ext STREQUAL ".cc")
    file(READ "${ozz_fuse_target_dir}/${src_file}" src_file_content)

    string(CONCAT output_content "${output_content}" "// Including ${src_file} file.\n\n")
    string(CONCAT output_content "${output_content}" "${src_file_content}\n")

  endif()
endforeach()

# Handle private include files (they are not prefixed by "ozz/").
string(REGEX MATCHALL "#include \"[\^\"ozz\"]([^\"]+)\"" internal_include_lines ${output_content})

foreach(internal_include_line ${internal_include_lines})

  STRING(REGEX REPLACE "#include \"([^\"]+)\"" "\\1" internal_include_file "${internal_include_line}" )

  file(READ "${ozz_fuse_src_dir}/src/${internal_include_file}" internal_src_file_content)

  string(REPLACE "${internal_include_line}" "\n// Includes internal include file ${internal_include_file}\n\n${internal_src_file_content}" output_content "${output_content}")

endforeach()

file(WRITE "${ozz_fuse_output_file}" "${output_content}")