2019-03-28 03:59:54 +00:00
|
|
|
function(make_object out_var)
|
|
|
|
set(result)
|
|
|
|
set(result_h)
|
|
|
|
foreach(in_f ${ARGN})
|
|
|
|
file(RELATIVE_PATH out_f ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/${in_f}")
|
|
|
|
set(out_h "${CMAKE_CURRENT_BINARY_DIR}/${out_f}.h")
|
2024-01-26 07:05:01 +00:00
|
|
|
set(out_f "${out_f}.o")
|
2021-08-10 07:27:26 +00:00
|
|
|
string(REGEX REPLACE "[/.-]" "_" sym_in "${in_f}")
|
2019-03-28 03:59:54 +00:00
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${out_f}
|
2024-01-26 07:05:01 +00:00
|
|
|
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/${in_f} ${out_f}.tmp
|
|
|
|
COMMAND dd if=/dev/zero bs=1 count=1 of=${out_f}.tmp oflag=append conv=notrunc status=none
|
|
|
|
COMMAND ${CMAKE_LINKER} -r -b binary -o ${out_f} ${out_f}.tmp
|
2019-03-28 03:59:54 +00:00
|
|
|
COMMAND ${CMAKE_OBJCOPY} --rename-section .data=.rodata,CONTENTS,ALLOC,LOAD,READONLY,DATA ${out_f} ${out_f}
|
2024-01-26 07:05:01 +00:00
|
|
|
COMMAND ${CMAKE_OBJCOPY} --redefine-sym _binary_${sym_in}_o_tmp_start=b_${sym_in} ${out_f} ${out_f}
|
|
|
|
COMMAND ${CMAKE_OBJCOPY} --redefine-sym _binary_${sym_in}_o_tmp_end=b_${sym_in}_end ${out_f} ${out_f}
|
|
|
|
COMMAND ${CMAKE_OBJCOPY} --redefine-sym _binary_${sym_in}_o_tmp_size=b_${sym_in}_size ${out_f} ${out_f}
|
2019-03-28 03:59:54 +00:00
|
|
|
COMMAND ${CMAKE_OBJCOPY} --strip-symbol _binary_${sym_in}_size ${out_f} ${out_f}
|
2021-08-09 09:15:42 +00:00
|
|
|
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${in_f}"
|
2024-01-26 07:05:01 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
2019-03-28 03:59:54 +00:00
|
|
|
COMMENT "Creating object from ${in_f}"
|
|
|
|
VERBATIM
|
|
|
|
)
|
|
|
|
|
2021-08-10 07:27:26 +00:00
|
|
|
file(WRITE ${out_h} "extern const char b_${sym_in}[];\n")
|
|
|
|
file(APPEND ${out_h} "extern const char b_${sym_in}_end[];\n")
|
|
|
|
file(APPEND ${out_h} "#define b_${sym_in}_size (b_${sym_in}_end - b_${sym_in})\n")
|
2019-03-28 03:59:54 +00:00
|
|
|
|
|
|
|
get_filename_component(h_dir ${out_h} DIRECTORY)
|
|
|
|
list(APPEND result_h ${h_dir})
|
|
|
|
list(APPEND result ${out_f})
|
|
|
|
endforeach()
|
|
|
|
list(REMOVE_DUPLICATES result_h)
|
|
|
|
|
|
|
|
set(${out_var}_OBJS "${result}" PARENT_SCOPE)
|
|
|
|
set(${out_var}_INCS "${result_h}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
2021-02-21 02:26:23 +00:00
|
|
|
|
|
|
|
function(make_defines in_file out_file)
|
2024-01-26 07:05:01 +00:00
|
|
|
file(RELATIVE_PATH rel_f ${CMAKE_CURRENT_SOURCE_DIR} "${in_file}")
|
2021-02-21 02:26:23 +00:00
|
|
|
add_custom_command(OUTPUT ${out_file}
|
|
|
|
COMMAND grep "^#define" "${in_file}" > "${out_file}"
|
|
|
|
DEPENDS ${in_file}
|
2024-01-26 07:05:01 +00:00
|
|
|
COMMENT "Creating #defines from ${rel_f}"
|
2021-02-21 02:26:23 +00:00
|
|
|
)
|
|
|
|
endfunction()
|