|
| 1 | +#### |
| 2 | +# fpp_to_json.cmake: |
| 3 | +# |
| 4 | +# fpp_to_json is a special target used to generate the JSON representation of the FPP model. This allows tools built on |
| 5 | +# the JSON model representation to integrate with the build system. |
| 6 | +#### |
| 7 | +include_guard() |
| 8 | +set(FPP__INTERNAL_ARGS_FROM_FILE "${PYTHON}" "${CMAKE_CURRENT_LIST_DIR}/../tools/arguments-from-file.py") |
| 9 | +#### |
| 10 | +# Function `fpp_to_json_add_global_target`: |
| 11 | +# |
| 12 | +# Sets up the `fpp_to_json` target used to generate depend output across the whole build. |
| 13 | +# - **TARGET:** name of the target to setup (fpp_to_json) |
| 14 | +#### |
| 15 | +function(fpp_to_json_add_global_target TARGET) |
| 16 | + add_custom_target("${TARGET}") |
| 17 | +endfunction(fpp_to_json_add_global_target) |
| 18 | + |
| 19 | +#### |
| 20 | +# Function `fpp_to_json_add_deployment_target`: |
| 21 | +# |
| 22 | +# Pass-through to fpp_to_json_add_module_target. FULL_DEPENDENCIES is unused. |
| 23 | +#### |
| 24 | +function(fpp_to_json_add_deployment_target MODULE TARGET SOURCES DEPENDENCIES FULL_DEPENDENCIES) |
| 25 | + fpp_to_json_add_module_target("${MODULE}" "${TARGET}" "${SOURCES}" "${DEPENDENCIES}") |
| 26 | +endfunction(fpp_to_json_add_deployment_target) |
| 27 | + |
| 28 | +#### |
| 29 | +# Function `fpp_to_json_add_module_target`: |
| 30 | +# |
| 31 | +# Generates the cached fpp-to-json output fore each module and registers the target to the global fpp_to_json target. |
| 32 | +# - **MODULE:** module name, unused |
| 33 | +# - **TARGET:** name of the target to setup (fpp_depend) |
| 34 | +# - **SOURCES:** list of sources filtered to .fpp |
| 35 | +# - **DEPENDENCIES:** module dependencies, unused. |
| 36 | +#### |
| 37 | +function(fpp_to_json_add_module_target MODULE TARGET SOURCES_UNUSED DEPENDENCIES) |
| 38 | + get_target_property(AUTOCODER_INPUTS "${MODULE}" AUTOCODER_INPUTS) |
| 39 | + set(FPP_SOURCES "") |
| 40 | + # Check each source for FPP support |
| 41 | + foreach(SOURCE IN LISTS AUTOCODER_INPUTS) |
| 42 | + fpp_is_supported("${SOURCE}") |
| 43 | + if (IS_SUPPORTED) |
| 44 | + list(APPEND FPP_SOURCES "${SOURCE}") |
| 45 | + endif() |
| 46 | + endforeach() |
| 47 | + file(RELATIVE_PATH OFFSET "${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") |
| 48 | + set(LOCAL_DIR "${CMAKE_CURRENT_BINARY_DIR}") |
| 49 | + set(DELIVERY_DIR "${FPRIME_BINARY_DIR}/${OFFSET}") |
| 50 | + file(MAKE_DIRECTORY "${LOCAL_DIR}") |
| 51 | + file(MAKE_DIRECTORY "${DELIVERY_DIR}") |
| 52 | + if (FPP_SOURCES) |
| 53 | + set(OUTPUT_FILES |
| 54 | + "${LOCAL_DIR}/fpp-ast.json" |
| 55 | + "${LOCAL_DIR}/fpp-analysis.json" |
| 56 | + "${LOCAL_DIR}/fpp-loc-map.json" |
| 57 | + ) |
| 58 | + add_custom_command( |
| 59 | + OUTPUT ${OUTPUT_FILES} |
| 60 | + COMMAND ${FPP__INTERNAL_ARGS_FROM_FILE} |
| 61 | + "${LOCAL_DIR}/fpp-cache/stdout.txt" |
| 62 | + "fpp-to-json" |
| 63 | + ${FPP_SOURCES} |
| 64 | + DEPENDS |
| 65 | + fpp_depend |
| 66 | + ${FPP_SOURCES} |
| 67 | + "${LOCAL_DIR}/fpp-cache/stdout.txt" |
| 68 | + ) |
| 69 | + add_custom_target("${TARGET}_${MODULE}" DEPENDS ${OUTPUT_FILES} |
| 70 | + COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${OUTPUT_FILES} "${DELIVERY_DIR}" |
| 71 | + ) |
| 72 | + else() |
| 73 | + add_custom_target("${TARGET}_${MODULE}") |
| 74 | + endif() |
| 75 | + add_dependencies("${TARGET}" "${TARGET}_${MODULE}") |
| 76 | +endfunction(fpp_to_json_add_module_target) |
0 commit comments