From 430ac7151eaae8ce6dd817bbfad76d42900f62b8 Mon Sep 17 00:00:00 2001 From: Anthony Limiero Date: Thu, 7 Jul 2022 17:00:46 -0700 Subject: [PATCH] Cmake changes to enable custom autocoder registration --- cmake/API.cmake | 40 +++++++++++++++++++++++ cmake/target/build.cmake | 3 +- docs/UsersGuide/dev/target-integration.md | 2 +- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/cmake/API.cmake b/cmake/API.cmake index dd89e4c3c33..62e25b1ffa8 100644 --- a/cmake/API.cmake +++ b/cmake/API.cmake @@ -13,6 +13,7 @@ #### set(FPRIME_TARGET_LIST "" CACHE INTERNAL "FPRIME_TARGET_LIST: custom fprime targets" FORCE) set(FPRIME_UT_TARGET_LIST "" CACHE INTERNAL "FPRIME_UT_TARGET_LIST: custom fprime targets" FORCE) +set(FPRIME_AUTOCODER_TARGET_LIST "" CACHE INTERNAL "FPRIME_AUTOCODER_TARGET_LIST: custom fprime targets" FORCE) #### # Function `add_fprime_subdirectory`: # @@ -467,6 +468,45 @@ macro(register_fprime_target_helper TARGET_FILE_PATH TARGET_LIST) endmacro(register_fprime_target_helper) +#### +# Macro `register_fprime_autocoder`: +# +# Identical to the above `register_fprime_target` function +# +### +macro(register_fprime_autocoder TARGET_FILE_PATH) + # Normal registered targets don't run in prescan + message(STATUS "REGISTER_FPRIME_AUTOCODER: ${TARGET_FILE_PATH}") + if (NOT DEFINED FPRIME_PRESCAN) + register_fprime_autocoder_helper("${TARGET_FILE_PATH}" FPRIME_AUTOCODER_TARGET_LIST) + endif() +endmacro(register_fprime_autocoder) + + +#### +# Macro `register_fprime_autocoder_helper`: +# +# Helper function to do the actual registration. +# +#### +macro(register_fprime_autocoder_helper TARGET_FILE_PATH TARGET_LIST) + include("${TARGET_FILE_PATH}") + # Prevent out-of-order setups + get_property(MODULE_DETECTION_STARTED GLOBAL PROPERTY MODULE_DETECTION SET) + if (MODULE_DETECTION_STARTED) + message(FATAL_ERROR "Cannot register fprime autocoder after including subdirectories or FPrime-Code.cmake'") + endif() + # Get the target list to add this target to or use default + set(LIST_NAME FPRIME_AUTOCODER_TARGET_LIST) + if (${ARGC} GREATER 1) + set(LIST_NAME "${ARGV1}") + endif() + get_property(TARGETS GLOBAL PROPERTY "${TARGET_LIST}") + if (NOT TARGET_FILE_PATH IN_LIST TARGETS) + set_property(GLOBAL APPEND PROPERTY "${LIST_NAME}" "${TARGET_FILE_PATH}") + endif() +endmacro(register_fprime_autocoder_helper) + #### Documentation links # Next Topics: # - Setting Options: [Options](Options.md) are used to vary a CMake build. diff --git a/cmake/target/build.cmake b/cmake/target/build.cmake index 81f000bfdee..03c3fa0152f 100644 --- a/cmake/target/build.cmake +++ b/cmake/target/build.cmake @@ -114,7 +114,8 @@ endfunction() function(build_add_module_target MODULE TARGET SOURCES DEPENDENCIES) get_target_property(MODULE_TYPE "${MODULE}" FP_TYPE) message(STATUS "Adding ${MODULE_TYPE}: ${MODULE}") - run_ac_set("${SOURCES}" autocoder/fpp autocoder/ai_xml) + get_property(CUSTOM_AUTOCODERS GLOBAL PROPERTY FPRIME_AUTOCODER_TARGET_LIST) + run_ac_set("${SOURCES}" autocoder/fpp autocoder/ai_xml ${CUSTOM_AUTOCODERS}) resolve_dependencies(RESOLVED ${DEPENDENCIES} ${AC_DEPENDENCIES} ) build_setup_build_module("${MODULE}" "${SOURCES}" "${AC_GENERATED}" "${AC_SOURCES}" "${RESOLVED}") # Special flags applied to modules when compiling with testing enabled diff --git a/docs/UsersGuide/dev/target-integration.md b/docs/UsersGuide/dev/target-integration.md index 3823f3f347f..98a4f77d19c 100644 --- a/docs/UsersGuide/dev/target-integration.md +++ b/docs/UsersGuide/dev/target-integration.md @@ -11,7 +11,7 @@ globally. Module targets run on every module defining the `_register_fpr targets run on deployments defined with the `_register_fprime_deployment` calls, and global targets run once. Targets are CMake files that define three functions, one for each level, and are described below. The filename of this -CMake without the `.cmake` extension is determines the`` name. e.g. `utility.cmake` will define the `utility` +CMake without the `.cmake` extension determines the`` name. e.g. `utility.cmake` will define the `utility` target. Targets stages are defined in the following order: