-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathfunctions.cmake
More file actions
96 lines (83 loc) · 3.88 KB
/
functions.cmake
File metadata and controls
96 lines (83 loc) · 3.88 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
cmake_minimum_required(VERSION 3.16)
set(frogfs_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
macro(generate_frogfs_rules)
if(NOT ESP_PLATFORM)
set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
cmake_parse_arguments(ARG "" "CONFIG;NAME;REQUIREMENTS" "TOOLS;PIP" ${ARGN})
if(NOT DEFINED ARG_CONFIG)
set(ARG_CONFIG frogfs.yaml)
endif()
if(NOT DEFINED ARG_NAME)
set(ARG_NAME frogfs)
endif()
foreach(TOOL ARG_TOOLS)
set(TOOLS ${TOOLS} --tools ${TOOL})
endforeach()
set(OUTPUT ${BUILD_DIR}/CMakeFiles/${ARG_NAME})
find_package(Python3 REQUIRED COMPONENTS Interpreter)
set(Python3_VENV ${BUILD_DIR}/CMakeFiles/frogfs-venv)
if(CMAKE_HOST_WIN32)
set(Python3_VENV_EXECUTABLE ${Python3_VENV}/Scripts/python.exe)
else()
set(Python3_VENV_EXECUTABLE ${Python3_VENV}/bin/python)
endif()
if(NOT TARGET frogfs_venv)
add_custom_target(frogfs_venv
COMMAND ${Python3_EXECUTABLE} -m venv ${Python3_VENV}
COMMENT "Initializing Python virtualenv"
BYPRODUCTS ${Python3_VENV}
)
file(GLOB_RECURSE venv FOLLOW_SYMLINKS LIST_DIRECTORIES true CONFIGURE_DEPENDS "${Python3_VENV}/*")
set_property(TARGET frogfs_venv PROPERTY ADDITIONAL_CLEAN_FILES "${venv}")
endif()
# Build the commands list for requirements installation
set(_frogfs_req_cmds)
list(APPEND _frogfs_req_cmds COMMAND ${Python3_VENV_EXECUTABLE} -m pip install -r ${frogfs_DIR}/requirements.txt)
if (ARG_REQUIREMENTS)
list(APPEND _frogfs_req_cmds COMMAND ${Python3_VENV_EXECUTABLE} -m pip install -r ${ARG_REQUIREMENTS})
endif()
if (ARG_PIP)
list(APPEND _frogfs_req_cmds COMMAND ${Python3_VENV_EXECUTABLE} -m pip install ${ARG_PIP})
endif()
if (NOT TARGET frogfs_requirements)
add_custom_target(frogfs_requirements
${_frogfs_req_cmds}
COMMAND ${CMAKE_COMMAND} -E touch ${Python3_VENV}.stamp
DEPENDS ${frogfs_DIR}/requirements.txt $<$<BOOL:${ARG_REQUIREMENTS}>:${ARG_REQUIREMENTS}>
BYPRODUCTS ${Python3_VENV}.stamp
COMMENT "Installing Python requirements"
)
add_dependencies(frogfs_requirements frogfs_venv)
endif()
add_custom_target(frogfs_preprocess_${ARG_NAME}
COMMAND ${Python3_VENV_EXECUTABLE} -B ${frogfs_DIR}/tools/mkfrogfs.py -C ${CMAKE_SOURCE_DIR} ${TOOLS} ${ARG_CONFIG} ${BUILD_DIR} ${OUTPUT}.bin
DEPENDS ${ARG_CONFIG}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS ${BUILD_DIR}/${ARG_NAME}-cache ${BUILD_DIR}/${ARG_NAME}-cache-state.json ${OUTPUT}.bin
COMMENT "Running mkfrogfs.py for ${ARG_NAME}.bin"
USES_TERMINAL
)
add_dependencies(frogfs_preprocess_${ARG_NAME} frogfs_requirements)
file(GLOB_RECURSE cache LIST_DIRECTORIES true CONFIGURE_DEPENDS "${BUILD_DIR}/${ARG_NAME}-cache/*")
set_property(TARGET frogfs_preprocess_${ARG_NAME} PROPERTY ADDITIONAL_CLEAN_FILES "${cache}")
file(GLOB_RECURSE node_modules FOLLOW_SYMLINKS LIST_DIRECTORIES true CONFIGURE_DEPENDS "${BUILD_DIR}/node_modules/*")
set_property(TARGET frogfs_preprocess_${ARG_NAME} APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${node_modules};${BUILD_DIR}/node_modules")
# Always ensure Python requirements are installed before preprocess
endmacro()
function(target_add_frogfs target)
LIST(REMOVE_AT ARGV 0)
generate_frogfs_rules(${ARGV})
add_custom_command(OUTPUT ${OUTPUT}_bin.c
COMMAND ${Python3_VENV_EXECUTABLE} -B ${frogfs_DIR}/tools/bin2c.py ${OUTPUT}.bin ${OUTPUT}_bin.c
DEPENDS ${OUTPUT}.bin
COMMENT "Generating frogfs source file ${ARG_NAME}_bin.c"
)
target_sources(${target} PRIVATE ${OUTPUT}_bin.c)
endfunction()
function(declare_frogfs_bin)
generate_frogfs_rules(${ARGV})
add_custom_target(generate_${ARG_NAME}_bin
DEPENDS frogfs_preprocess_${ARG_NAME} ${OUTPUT}.bin
)
endfunction()