-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembedFile.cmake
More file actions
54 lines (43 loc) · 1.99 KB
/
embedFile.cmake
File metadata and controls
54 lines (43 loc) · 1.99 KB
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
52
53
function(GET_EXEC_PATH OUT_PATH)
if(WIN32)
file(GLOB_RECURSE EMBED_EXEC_PATH "${CMAKE_CURRENT_BINARY_DIR}/*/Embed2C.exe")
else()
file(GLOB_RECURSE EMBED_EXEC_PATH "${CMAKE_CURRENT_BINARY_DIR}/*/Embed2C")
endif()
list(LENGTH EMBED_EXEC_PATH EMBED_EXEC_PATH_LENGTH)
if(EMBED_EXEC_PATH STREQUAL "")
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "MSVC")
message(WARNING "Embed2C not found, please build the Embed2C target inside Visual Studio first")
else()
message(WARNING "Embed2C not found, please run \"cmake --build . --target Embed2C\" in the build folder")
endif()
set(OUT_PATH "" PARENT_SCOPE)
elseif(NOT EMBED_EXEC_PATH_LENGTH EQUAL 1)
message(FATAL_ERROR "More than 1 Embed2C executable found: ${EMBED_EXEC_PATH}")
else()
set(${OUT_PATH} ${EMBED_EXEC_PATH} PARENT_SCOPE)
endif()
endfunction()
function(EMBED_FILES EMBED_PATH OUTPUT_FILE_PATH FILES_TO_EMBED)
if(EMBED_PATH STREQUAL "")
message(WARNING "Failed to run embed2C")
return()
endif()
set(PRINT_EMBED_COMMAND_ARGS)
foreach(FILE_TO_EMBED ${FILES_TO_EMBED})
set(PRINT_EMBED_COMMAND_ARGS "${PRINT_EMBED_COMMAND_ARGS}\"${FILE_TO_EMBED}\" ")
endforeach()
get_filename_component(OUTPUT_FILE_DIR ${OUTPUT_FILE_PATH} DIRECTORY)
if(NOT EXISTS ${OUTPUT_FILE_DIR})
message(FATAL_ERROR "The directory ${OUTPUT_FILE_DIR} does not exist")
endif()
execute_process(OUTPUT_FILE ${OUTPUT_FILE_PATH}
RESULT_VARIABLE RET
COMMAND ${EMBED_PATH} ${FILES_TO_EMBED})
if(NOT RET EQUAL "0")
message("RET: ${RET}")
message("OUTPUT_FILE_PATH: ${OUTPUT_FILE_PATH}")
message("Ran command ${EMBED_PATH} ${PRINT_EMBED_COMMAND_ARGS}")
message(FATAL_ERROR "Failed to embed files, see error message in ${OUTPUT_FILE_PATH}")
endif()
endfunction()