2021-11-11 21:22:24 +01:00
# For each library, fuses all sources to a single .cc file.
#----------------------------------------------------------
# Start with new content
2023-03-26 11:44:29 +02:00
string ( CONCAT output_content "" "// This file is autogenerated. Any modification might be lost.\n\n" )
2021-11-11 21:22:24 +01:00
2023-03-26 11:44:29 +02:00
# Patches arguments so that cmake take them as a list.
separate_arguments ( ozz_target_source_files )
string ( REPLACE "\\ " " " ozz_fuse_target_dir "${ozz_fuse_target_dir}" )
string ( REPLACE "\\ " " " ozz_fuse_src_dir "${ozz_fuse_src_dir}" )
string ( REPLACE "\\ " " " ozz_fuse_output_file "${ozz_fuse_output_file}" )
2021-11-11 21:22:24 +01:00
# Concat all sources to the output.
foreach ( src_file ${ ozz_target_source_files } )
2023-03-26 11:44:29 +02:00
get_filename_component ( absolute_src_file ${ src_file } ABSOLUTE BASE_DIR ${ ozz_fuse_target_dir } )
get_filename_component ( src_file_ext ${ absolute_src_file } EXT )
2021-11-11 21:22:24 +01:00
# Handle source files.
if ( src_file_ext STREQUAL ".cc" )
2023-03-26 11:44:29 +02:00
file ( READ "${absolute_src_file}" src_file_content )
2021-11-11 21:22:24 +01:00
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}" )
2023-03-26 11:44:29 +02:00
get_filename_component ( internal_src_file src/ ${ internal_include_file } ABSOLUTE BASE_DIR ${ ozz_fuse_src_dir } )
file ( READ "${internal_src_file}" internal_src_file_content )
2021-11-11 21:22:24 +01:00
string ( REPLACE "${internal_include_line}" "\n// Includes internal include file ${internal_include_file}\n\n${internal_src_file_content}" output_content "${output_content}" )
endforeach ( )
2023-03-26 11:44:29 +02:00
# Output new file
2021-11-11 21:22:24 +01:00
file ( WRITE "${ozz_fuse_output_file}" "${output_content}" )