forked from aguinet/dragonffi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeClangRes.txt
36 lines (34 loc) · 1.67 KB
/
CMakeClangRes.txt
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
# Copyright 2018 Adrien Guinet <adrien@guinet.me>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
file(GLOB_RECURSE CLANG_RES_GLOB LIST_DIRECTORIES false "${CLANG_RES_DIR}/*")
string(LENGTH "${CLANG_RES_DIR}" CLANG_RES_DIR_LENGTH)
set(VFS_INIT "")
set(FILE_IDX 0)
file(WRITE "${CLANG_RES_HEADER}" "")
foreach(RES ${CLANG_RES_GLOB})
get_filename_component(RES "${RES}" ABSOLUTE)
string(SUBSTRING "${RES}" 0 ${CLANG_RES_DIR_LENGTH} RES_ROOT)
if (NOT "${RES_ROOT}" STREQUAL "${CLANG_RES_DIR}")
message(FATAL_ERROR "Unknown directory for ressource '${RES}'")
endif()
MATH(EXPR IDX_START "${CLANG_RES_DIR_LENGTH}+1")
string(SUBSTRING "${RES}" ${IDX_START} -1 RES_NAME)
file(READ "${RES}" RES_DATA HEX)
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," RES_DATA_ARRAY "${RES_DATA}")
set(VAR_NAME "__file_${FILE_IDX}")
file(APPEND "${CLANG_RES_HEADER}" "static const uint8_t ${VAR_NAME}[] = { ${RES_DATA_ARRAY} 0x00 };\n")
set(VFS_INIT "${VFS_INIT}addPath(VFS, \"include/${RES_NAME}\", ${VAR_NAME}, sizeof(${VAR_NAME})-1);\n")
MATH(EXPR FILE_IDX "${FILE_IDX}+1")
endforeach()
file(APPEND "${CLANG_RES_HEADER}" "void initVFS(llvm::vfs::InMemoryFileSystem& VFS) {\n ${VFS_INIT} \n}")