Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom autocoders #1558

Merged
merged 3 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions cmake/API.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
#
Expand Down Expand Up @@ -423,7 +424,8 @@ endfunction(register_fprime_ut)
macro(register_fprime_target TARGET_FILE_PATH)
# Normal registered targets don't run in prescan
if (NOT DEFINED FPRIME_PRESCAN)
register_fprime_target_helper("${TARGET_FILE_PATH}" FPRIME_TARGET_LIST)
register_fprime_list_helper("${TARGET_FILE_PATH}" FPRIME_TARGET_LIST)
setup_global_target("${TARGET_FILE_PATH}")
endif()
endmacro(register_fprime_target)

Expand All @@ -438,35 +440,53 @@ endmacro(register_fprime_target)
macro(register_fprime_ut_target TARGET_FILE_PATH)
# UT targets only allowed when testing
if (BUILD_TESTING AND NOT DEFINED FPRIME_PRESCAN)
register_fprime_target_helper("${TARGET_FILE_PATH}" FPRIME_UT_TARGET_LIST)
register_fprime_list_helper("${TARGET_FILE_PATH}" FPRIME_UT_TARGET_LIST)
setup_global_target("${TARGET_FILE_PATH}")
endif()
endmacro(register_fprime_ut_target)

####
# Macro `register_fprime_target_helper`:
# Macro `register_fprime_list_helper`:
#
# Helper function to do the actual registration. Also used to side-load prescan to bypass the not-on-prescan check.
####
macro(register_fprime_target_helper TARGET_FILE_PATH TARGET_LIST)
macro(register_fprime_list_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 target after including subdirectories or FPrime-Code.cmake'")
endif()
# Get the target list to add this target to or use default
set(LIST_NAME FPRIME_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}")
setup_global_target("${TARGET_FILE_PATH}")
set_property(GLOBAL APPEND PROPERTY "${TARGET_LIST}" "${TARGET_FILE_PATH}")
endif()
endmacro(register_fprime_target_helper)
endmacro(register_fprime_list_helper)


####
# Macro `register_fprime_build_autocoder`:
#
# This function allows users to register custom autocoders into the build system. These autocoders will execute during
# the build process. An autocoder is defined in a CMake file and must do three things:
# 1. Call one of `autocoder_setup_for_individual_sources()` or `autocoder_setup_for_multiple_sources()` from file scope
# 2. Implement `<autocoder name>_is_supported(AC_POSSIBLE_INPUT_FILE)` returning true the autocoder processes given source
# 3. Implement `<autocoder name>_setup_autocode AC_INPUT_FILE)` to run the autocoder on files filter by item 2.
# See: [Autocoders](dev/autocoder_integration.md).
#
# This function takes in either a file path to a CMake file defining an autocoder target, or an short include path that accomplishes
# the same thing. Note: make sure the directory is on the CMake include path to use the second form.
#
# **TARGET_FILE_PATH:** include path or file path file defining above functions
###
macro(register_fprime_build_autocoder TARGET_FILE_PATH)
# Normal registered targets don't run in prescan
message(STATUS "Registering custom autocoder: ${TARGET_FILE_PATH}")
if (NOT DEFINED FPRIME_PRESCAN)
register_fprime_list_helper("${TARGET_FILE_PATH}" FPRIME_AUTOCODER_TARGET_LIST)
endif()
endmacro(register_fprime_build_autocoder)

#### Documentation links
# Next Topics:
# - Setting Options: [Options](Options.md) are used to vary a CMake build.
Expand Down
7 changes: 5 additions & 2 deletions cmake/FPrime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ endforeach()
include_directories("${FPRIME_FRAMEWORK_PATH}")
include_directories("${FPRIME_CONFIG_DIR}")

# To prescan, either we register the prescan target or we run the prescan CMake
# To prescan,register target process around safety check
if (DEFINED FPRIME_PRESCAN)
register_fprime_target_helper(target/prescan FPRIME_TARGET_LIST)
register_fprime_list_helper(target/prescan FPRIME_TARGET_LIST)
setup_global_target(target/prescan)
else()
perform_prescan()
endif()

# FPP locations must come at the front of the list, then build
register_fprime_target(target/fpp_locs)
register_fprime_target(target/build)
register_fprime_build_autocoder(autocoder/fpp)
register_fprime_build_autocoder(autocoder/ai_xml)
register_fprime_target(target/noop)
register_fprime_target(target/version)
register_fprime_target(target/dict)
Expand Down
3 changes: 2 additions & 1 deletion cmake/target/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}" ${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
Expand Down
2 changes: 1 addition & 1 deletion docs/UsersGuide/dev/target-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ globally. Module targets run on every module defining the `<target>_register_fpr
targets run on deployments defined with the `<target>_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`<target>` name. e.g. `utility.cmake` will define the `utility`
CMake without the `.cmake` extension determines the`<target>` name. e.g. `utility.cmake` will define the `utility`
target.

Targets stages are defined in the following order:
Expand Down