Skip to content

Commit

Permalink
Refactor locs, dependencies into generic sub build (#2360)
Browse files Browse the repository at this point in the history
* Refactor locs, dependencies into generic sub build

* Fixing CMake UTs for generic subbuild pattern

* Adding sub-build CMake UT

* Correcting sub-builds from UT results

* Adding include_guards to globally imported items

* Fixing CI and speed improvements

* sp

* Fixing review recommendations
  • Loading branch information
LeStarch authored Nov 13, 2023
1 parent 1e8d413 commit 3f6b3a9
Show file tree
Hide file tree
Showing 31 changed files with 707 additions and 591 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ MACROFILE
maincpp
makefiles
makeindex
MAKEFLAGS
MAKEVAR
MALLOCALLOCATOR
mallocator
Expand Down
3 changes: 1 addition & 2 deletions Ref/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0048 NEW)
project(Ref VERSION 1.0.0 LANGUAGES C CXX)

##
# Section 2: F prime Core
#
Expand All @@ -31,7 +30,7 @@ project(Ref VERSION 1.0.0 LANGUAGES C CXX)
##
include("${CMAKE_CURRENT_LIST_DIR}/../cmake/FPrime.cmake")
# NOTE: register custom targets between these two lines
include("${CMAKE_CURRENT_LIST_DIR}/../cmake/FPrime-Code.cmake")
fprime_setup_included_code()
##
# Section 3: Components and Topology
#
Expand Down
11 changes: 11 additions & 0 deletions Ref/SignalGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SignalGen.fpp"
"${CMAKE_CURRENT_LIST_DIR}/SignalGen.cpp"


)

register_fprime_module()









### UTs ###
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SignalGen.fpp"
Expand Down
40 changes: 22 additions & 18 deletions cmake/API.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# - Register an fprime build target/build stage to allow custom build steps. (Experimental)
#
####
include_guard()
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)
Expand Down Expand Up @@ -485,11 +486,10 @@ endfunction(register_fprime_ut)
# **TARGET_FILE_PATH:** include path or file path file defining above functions
###
macro(register_fprime_target TARGET_FILE_PATH)
# Normal registered targets don't run in prescan
if (NOT DEFINED FPRIME_PRESCAN)
register_fprime_list_helper("${TARGET_FILE_PATH}" FPRIME_TARGET_LIST)
setup_global_target("${TARGET_FILE_PATH}")
if (CMAKE_DEBUG_OUTPUT)
message(STATUS "[target] Registering custom target: ${TARGET_FILE_PATH}")
endif()
register_fprime_list_helper("${TARGET_FILE_PATH}" FPRIME_TARGET_LIST)
endmacro(register_fprime_target)

####
Expand All @@ -502,9 +502,11 @@ 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)
if (BUILD_TESTING)
if (CMAKE_DEBUG_OUTPUT)
message(STATUS "[target] Registering custom target: ${TARGET_FILE_PATH}")
endif()
register_fprime_list_helper("${TARGET_FILE_PATH}" FPRIME_UT_TARGET_LIST)
setup_global_target("${TARGET_FILE_PATH}")
endif()
endmacro(register_fprime_ut_target)

Expand All @@ -514,15 +516,17 @@ endmacro(register_fprime_ut_target)
# Helper function to do the actual registration. Also used to side-load prescan to bypass the not-on-prescan check.
####
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_property(TARGETS GLOBAL PROPERTY "${TARGET_LIST}")
if (NOT TARGET_FILE_PATH IN_LIST TARGETS)
set_property(GLOBAL APPEND PROPERTY "${TARGET_LIST}" "${TARGET_FILE_PATH}")
if (NOT DEFINED FPRIME_SUB_BUILD_TARGETS OR "${TARGET_FILE_PATH}" IN_LIST FPRIME_SUB_BUILD_TARGETS)
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_property(TARGETS GLOBAL PROPERTY "${TARGET_LIST}")
if (NOT TARGET_FILE_PATH IN_LIST TARGETS)
set_property(GLOBAL APPEND PROPERTY "${TARGET_LIST}" "${TARGET_FILE_PATH}")
endif()
endif()
endmacro(register_fprime_list_helper)

Expand All @@ -544,10 +548,10 @@ endmacro(register_fprime_list_helper)
###
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)
if (CMAKE_DEBUG_OUTPUT)
message(STATUS "[autocoder] Registering custom build target autocoder: ${TARGET_FILE_PATH}")
endif()
register_fprime_list_helper("${TARGET_FILE_PATH}" FPRIME_AUTOCODER_TARGET_LIST)
endmacro(register_fprime_build_autocoder)

#### Documentation links
Expand Down
46 changes: 8 additions & 38 deletions cmake/FPrime-Code.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,14 @@
# FPrime-Code:
#
# FPrime code. This cmake file includes the basic directories that make up the mainline F prime framework. This is
# separated from the CMake includes themselves such that this is built after all CMake setup. All F prime core folders
# should be added here and F prime CMake API function should be added elsewhere.
# separated from the CMake includes themselves such that this is built after all CMake setup.
#
# Note: given F prime's historical folder structure, this is not organized as an fprime library.
####
# Libraries that make-up F prime. Hurray!
# Ignore GTest for non-test builds
if (BUILD_TESTING AND NOT DEFINED FPRIME_PRESCAN)
include("${FPRIME_FRAMEWORK_PATH}/cmake/googletest-download/googletest.cmake")
add_subdirectory("${FPRIME_FRAMEWORK_PATH}/STest/" "${CMAKE_BINARY_DIR}/F-Prime/STest")
endif()
# By default we shutoff framework UTs
set(__FPRIME_NO_UT_GEN__ ON)
# Check for autocoder UTs
if (FPRIME_ENABLE_FRAMEWORK_UTS AND FPRIME_ENABLE_AUTOCODER_UTS)
set(__FPRIME_NO_UT_GEN__ OFF)
endif()
add_subdirectory("${FPRIME_FRAMEWORK_PATH}/Autocoders/" "${CMAKE_BINARY_DIR}/F-Prime/Autocoders")
# Check if we are allowing framework UTs
if (FPRIME_ENABLE_FRAMEWORK_UTS)
set(__FPRIME_NO_UT_GEN__ OFF)
endif()
# Faux libraries used as interfaces to non-autocoded fpp items
add_library(Fpp INTERFACE)
set(FPRIME_CURRENT_MODULE config)
add_subdirectory("${FPRIME_CONFIG_DIR}" "${CMAKE_BINARY_DIR}/config")
include_directories("${CMAKE_BINARY_DIR}/config")
set(_FP_CORE_PACKAGES Fw Svc Os Drv CFDP Utils)
foreach (_FP_PACKAGE_DIR IN LISTS _FP_CORE_PACKAGES)
set(FPRIME_CURRENT_MODULE "${_FP_PACKAGE_DIR}")
add_subdirectory("${FPRIME_FRAMEWORK_PATH}/${_FP_PACKAGE_DIR}/" "${CMAKE_BINARY_DIR}/F-Prime/${_FP_PACKAGE_DIR}")
endforeach ()
unset(FPRIME_CURRENT_MODULE)
# Always enable UTs for a project
set(__FPRIME_NO_UT_GEN__ OFF)
foreach (LIBRARY_DIR IN LISTS FPRIME_LIBRARY_LOCATIONS)
file(GLOB MANIFESTS RELATIVE "${LIBRARY_DIR}" CONFIGURE_DEPENDS "${LIBRARY_DIR}/*.cmake")
foreach (MANIFEST IN LISTS MANIFESTS)
include("${LIBRARY_DIR}/${MANIFEST}")
endforeach()
endforeach()
include_guard()

# Ensure that the FPrime build system is setup
include("${CMAKE_CURRENT_LIST_DIR}/FPrime.cmake")

# Setup fprime code followed by all libraries
fprime_setup_included_code()
Loading

0 comments on commit 3f6b3a9

Please sign in to comment.