-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile_to_str.cmake
51 lines (40 loc) · 1.05 KB
/
file_to_str.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
# Copyright (C) 2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
cmake_minimum_required(VERSION 3.12)
string(REPLACE " " ";" src_list "${SRC}")
string(REPLACE "\\;" " " src_list "${src_list}")
list(LENGTH src_list num_src)
set(generated_output
"/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
// This is a generated file, please don't hand-modify
#pragma once
#include <cstddef>
struct FileAsStr{
const char *fname;
size_t len;
const char *src;
};
static const FileAsStr ${VAR}[${num_src}] = {"
)
foreach(src_fname ${src_list})
file(READ ${src_fname} contents)
string(LENGTH "${contents}" contents_len)
string(REPLACE "${SRC_ROOT}/" "" relative_path ${src_fname})
string(REPLACE "${SRC_ROOT}" "" relative_path ${relative_path})
set(generated_output "${generated_output}
{ \"${relative_path}\", ${contents_len}, R\"===|===(${contents})===|===\"},"
)
endforeach()
set(generated_output "${generated_output}
};"
)
set(dst_fname ${DST})
file(WRITE ${dst_fname} "${generated_output}")