File: ResourceCompiler.cmake

package info (click to toggle)
ezquake 3.6.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,956 kB
  • sloc: ansic: 180,729; sh: 324; objc: 139; tcl: 107; xml: 64; makefile: 10
file content (19 lines) | stat: -rw-r--r-- 686 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Generate C code with some content encoded as an array of unsigned char.
# See AddResources.cmake for more information.

set(input_file "${CMAKE_ARGV3}")
set(output_file "${CMAKE_ARGV4}")

get_filename_component(base_name "${input_file}" NAME)
string(REGEX REPLACE "[.]" "_" variable_name "${base_name}")

file(READ "${input_file}" content HEX)

string(LENGTH "${content}" content_length)
math(EXPR data_length "${content_length} / 2")

string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," data "${content}")

string(APPEND data "0x00,")

file(WRITE "${output_file}" "const unsigned char ${variable_name}[] = {\n${data}\n};\nconst unsigned int ${variable_name}_len = ${data_length};\n")