Skip to content

Commit

Permalink
Fix nasa#972, Reorganize CFE core into separate modules
Browse files Browse the repository at this point in the history
Significant reorganization of the CFE core directory
and header file structure.

All modules become separate subdirectories under fsw/modules.

Additionally, the interfaces to CFE core (public and internal)
are also separated into modules.

CMake "interface libraries" and related constructs are used to
manage the include paths to all the separate modules.
  • Loading branch information
jphickey committed Mar 3, 2021
1 parent 274c150 commit 3c4b9cf
Show file tree
Hide file tree
Showing 240 changed files with 9,620 additions and 953 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ set(CMAKE_LEGACY_CYGWIN_WIN32 0)
# (this is not required, and the directory can be empty/nonexistent)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../psp/cmake/Modules" ${CMAKE_MODULE_PATH})

# The minimum CMake version is chosen because 2.6.4 is what is
# included by default with RHEL/Centos 5.x
cmake_minimum_required(VERSION 2.6.4)
# The minimum CMake version is chosen because v3.5.1 is what is
# available by default with Ubuntu 16.04 LTS at the time of development
# RHEL/CentOS users should install the "cmake3" package from EPEL repo
cmake_minimum_required(VERSION 3.5)

# This top-level file does not define ANY targets directly but we know
# that the subdirectories will at least use the "C" language, so
Expand Down
73 changes: 44 additions & 29 deletions cmake/arch_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ endfunction(initialize_globals)
function(add_psp_module MOD_NAME MOD_SRC_FILES)

# Include the PSP shared directory so it can get to cfe_psp_module.h
include_directories(${MISSION_SOURCE_DIR}/psp/fsw/shared/inc)
add_definitions(-D_CFE_PSP_MODULE_)

# Create the module
Expand All @@ -89,6 +88,7 @@ function(add_cfe_app APP_NAME APP_SRC_FILES)

# Create the app module
add_library(${APP_NAME} ${APPTYPE} ${APP_SRC_FILES} ${ARGN})
target_link_libraries(${APP_NAME} cfe_app_intf)

# An "install" step is only needed for dynamic/runtime loaded apps
if (APP_DYNAMIC_TARGET_LIST)
Expand All @@ -105,11 +105,6 @@ endfunction(add_cfe_app)
#
function(add_cfe_tables APP_NAME TBL_SRC_FILES)

# The table source must be compiled using the same "include_directories"
# as any other target, but it uses the "add_custom_command" so there is
# no automatic way to do this (at least in the older cmakes)
get_current_cflags(TBL_CFLAGS ${CMAKE_C_FLAGS})

# Create the intermediate table objects using the target compiler,
# then use "elf2cfetbl" to convert to a .tbl file
set(TBL_LIST)
Expand Down Expand Up @@ -148,6 +143,9 @@ function(add_cfe_tables APP_NAME TBL_SRC_FILES)
message("NOTE: Selected ${TBL_SRC} as source for ${TBLWE}")
endif()

add_library(${TGT}_${TBLWE}-obj OBJECT ${TBL_SRC})
target_link_libraries(${TGT}_${TBLWE}-obj PRIVATE cfe_app_intf)

# IMPORTANT: This rule assumes that the output filename of elf2cfetbl matches
# the input file name but with a different extension (.o -> .tbl)
# The actual output filename is embedded in the source file (.c), however
Expand All @@ -156,9 +154,9 @@ function(add_cfe_tables APP_NAME TBL_SRC_FILES)
# current content of a dependency (rightfully so).
add_custom_command(
OUTPUT "${TABLE_DESTDIR}/${TBLWE}.tbl"
COMMAND ${CMAKE_C_COMPILER} ${TBL_CFLAGS} -c -o ${TBLWE}.o ${TBL_SRC}
COMMAND ${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl ${TBLWE}.o
DEPENDS ${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl ${TBL_SRC}
#COMMAND ${CMAKE_C_COMPILER} ${TBL_CFLAGS} -c -o ${TBLWE}.o ${TBL_SRC}
COMMAND ${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl $<TARGET_OBJECTS:${TGT}_${TBLWE}-obj>
DEPENDS ${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl ${TGT}_${TBLWE}-obj
WORKING_DIRECTORY ${TABLE_DESTDIR}
)
# Create the install targets for all the tables
Expand Down Expand Up @@ -254,6 +252,38 @@ function(cfs_app_do_install APP_NAME)

endfunction(cfs_app_do_install)

##################################################################
#
# FUNCTION: cfs_app_check_intf
#
# Adds a special target that checks the structure of header files
# in the public interface for this module. A synthetic .c source file
# is created which has a "#include" of each individual header, which
# then compiled as part of the validation. The intent is to confirm
# that each header is valid in a standalone fashion and have no
# implicit prerequisites.
#
function(cfs_app_check_intf MODULE_NAME)
set(${MODULE_NAME}_hdrcheck_SOURCES)
foreach(HDR ${ARGN})
configure_file(${CFE_SOURCE_DIR}/cmake/check_header.c.in ${CMAKE_CURRENT_BINARY_DIR}/src/check_${HDR}.c)
list(APPEND ${MODULE_NAME}_hdrcheck_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/src/check_${HDR}.c)
endforeach(HDR ${ARGN})
add_library(${MODULE_NAME}_headercheck OBJECT ${${MODULE_NAME}_hdrcheck_SOURCES})

# This causes the check to compile with the same set of defines and include dirs as specified
# in the "INTERFACE" properties of the actual module
target_link_libraries(${MODULE_NAME}_headercheck PRIVATE
cfe_app_intf
${DEP}
)

# Build this as part of the synthetic "check-headers" target
add_dependencies(check-headers ${MODULE_NAME}_headercheck)
endfunction(cfs_app_check_intf)




##################################################################
#
Expand Down Expand Up @@ -329,6 +359,7 @@ function(process_arch SYSVAR)

# Generate a list of targets that share this system architecture
set(INSTALL_TARGET_LIST ${TGTSYS_${SYSVAR}})
message("INSTALL_TARGET_LIST=${INSTALL_TARGET_LIST}")

# Assume use of an OSAL BSP of the same name as the CFE PSP
# This can be overridden by the PSP-specific build_options but normally this is expected.
Expand All @@ -350,33 +381,17 @@ function(process_arch SYSVAR)
include_directories(${MISSION_BINARY_DIR}/inc)
include_directories(${CMAKE_BINARY_DIR}/inc)

# Add a custom target for "headercheck" - this is a special target confirms that
# checks the sanity of headers within the public interface of modules
add_custom_target(check-headers)

# Configure OSAL target first, as it also determines important compiler flags
add_subdirectory("${osal_MISSION_DIR}" osal)

# The OSAL displays its selected OS, so it is logical to display the selected PSP
# This can help with debugging if things go wrong.
message(STATUS "PSP Selection: ${CFE_SYSTEM_PSPNAME}")

# Add all widely-used public headers to the include path chain
include_directories(${MISSION_SOURCE_DIR}/osal/src/os/inc)
include_directories(${MISSION_SOURCE_DIR}/psp/fsw/inc)
include_directories(${MISSION_SOURCE_DIR}/cfe/fsw/cfe-core/src/inc)
include_directories(${MISSION_SOURCE_DIR}/cfe/cmake/target/inc)

# propagate any OSAL interface compile definitions and include directories to this build
# This is set as a directory property here at the top level so it will apply to all code.
# This includes MODULE libraries that do not directly/statically link with OSAL but still
# should be compiled with these flags.
get_target_property(OSAL_COMPILE_DEFINITIONS osal INTERFACE_COMPILE_DEFINITIONS)
get_target_property(OSAL_INCLUDE_DIRECTORIES osal INTERFACE_INCLUDE_DIRECTORIES)

if (OSAL_COMPILE_DEFINITIONS)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "${OSAL_COMPILE_DEFINITIONS}")
endif (OSAL_COMPILE_DEFINITIONS)
if (OSAL_INCLUDE_DIRECTORIES)
include_directories(${OSAL_INCLUDE_DIRECTORIES})
endif (OSAL_INCLUDE_DIRECTORIES)

# Append the PSP and OSAL selections to the Doxyfile so it will be included
# in the generated documentation automatically.
# Also extract the "-D" options within CFLAGS and inform Doxygen about these
Expand Down
4 changes: 4 additions & 0 deletions cmake/check_header.c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "@HDR@"

/* A no-op function so this compilation unit is not empty */
void CheckHeader(void) {}
14 changes: 9 additions & 5 deletions cmake/global_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,25 @@ endfunction(read_targetconfig)
#
function(get_current_cflags OUTPUT_LIST)

message(FATAL_ERROR "BROKEN!")

# Start by converting the supplied string to a list
set(FLAGLIST)
foreach (FLGSTR ${ARGN})
string(REGEX REPLACE " +" ";" TEMPFLG ${FLGSTR})
list(APPEND FLAGLIST ${TEMPFLG})
endforeach (FLGSTR ${ARGN})

# Append any compile definitions from the directory properties
get_directory_property(CURRENT_DEFS COMPILE_DEFINITIONS)
foreach(DEF ${CURRENT_DEFS})
# Append any compile definitions from the CFE API
get_target_property(CURRENT_DEFS cfe_app INTERFACE_COMPILE_DEFINITIONS)
message("DEFS=${CURRENT_DEFS}")
foreach(DEF $<TARGET_PROPERTY:cfe_app,INTERFACE_COMPILE_DEFINITIONS>)
list(APPEND FLAGLIST "-D${DEF}")
endforeach(DEF ${CURRENT_DEFS})

# Append any include directories from the directory properties
get_directory_property(CURRENT_INCDIRS INCLUDE_DIRECTORIES)
# Append any include directories from the CFE API
get_target_property(CURRENT_INCDIRS cfe_app INTERFACE_INCLUDE_DIRECTORIES)
message("INCDIRS=${CURRENT_INCDIRS}")
foreach(INC ${CURRENT_INCDIRS})
list(APPEND FLAGLIST "-I${INC}")
endforeach(INC ${CURRENT_INCDIRS})
Expand Down
29 changes: 24 additions & 5 deletions cmake/mission_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ function(generate_build_version_templates)

endfunction(generate_build_version_templates)


##################################################################
#
# FUNCTION: prepare
Expand Down Expand Up @@ -249,7 +248,7 @@ function(prepare)

foreach(APP ${MISSION_DEPS})
# OSAL is handled specially, as only part of it is used
if (NOT APP STREQUAL "osal" AND NOT APP STREQUAL "cfe-core")
if (NOT APP STREQUAL "osal")
if (EXISTS "${${APP}_MISSION_DIR}/docs/${APP}.doxyfile.in")
# If the module provides its own doxyfile, then include it directly
# This allows for app-specific fine-tuning of the sources, based on its own source tree
Expand Down Expand Up @@ -283,11 +282,19 @@ function(prepare)
"${CMAKE_BINARY_DIR}/doc/osconfig-example.h")

# The user guide should include the doxygen from the _public_ API files from CFE + OSAL
# NOTE: the userguide is built against the headers of the default core apps. Even if
# an alternate version of the module is in use, it should adhere to the same interface.
file(GLOB MISSION_USERGUIDE_HEADERFILES
"${cfe-core_MISSION_DIR}/src/inc/*.h"
"${es_MISSION_DIR}/fsw/inc/*.h"
"${evs_MISSION_DIR}/fsw/inc/*.h"
"${fs_MISSION_DIR}/fsw/inc/*.h"
"${sb_MISSION_DIR}/fsw/inc/*.h"
"${tbl_MISSION_DIR}/fsw/inc/*.h"
"${time_MISSION_DIR}/fsw/inc/*.h"
"${osal_MISSION_DIR}/src/os/inc/*.h"
"${psp_MISSION_DIR}/psp/fsw/inc/*.h"
"${CMAKE_BINARY_DIR}/doc/osconfig-example.h"
"${MISSION_SOURCE_DIR}/psp/fsw/inc/*.h")
)
string(REPLACE ";" " \\\n" MISSION_USERGUIDE_HEADERFILES "${MISSION_USERGUIDE_HEADERFILES}")

# OSAL API GUIDE include PUBLIC API
Expand All @@ -312,7 +319,7 @@ function(prepare)

add_custom_target(osalguide
doxygen osalguide.doxyfile
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/doc")
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/doc")

# Pull in any application-specific mission-scope configuration
# This may include user configuration files such as cfe_mission_cfg.h,
Expand Down Expand Up @@ -360,6 +367,18 @@ function(prepare)
generate_build_version_templates()

# Generate the tools for the native (host) arch
# Add all public include dirs for core components to include path for tools
include_directories(
${cfe_app_intf_MISSION_DIR}/fsw/inc
#${es_MISSION_DIR}/fsw/inc
#${evs_MISSION_DIR}/fsw/inc
#${fs_MISSION_DIR}/fsw/inc
#${sb_MISSION_DIR}/fsw/inc
#${tbl_MISSION_DIR}/fsw/inc
#${time_MISSION_DIR}/fsw/inc
${osal_MISSION_DIR}/src/os/inc
${psp_MISSION_DIR}/psp/fsw/inc
)
add_subdirectory(${MISSION_SOURCE_DIR}/tools tools)

# Add a dependency on the table generator tool as this is required for table builds
Expand Down
11 changes: 9 additions & 2 deletions cmake/mission_defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
# The "MISSION_CORE_MODULES" will be built and statically linked as part
# of the CFE core executable on every target. These can be used to amend
# or override parts of the CFE core on a mission-specific basis.
# The "intf" modules are headers only, and define the interface(s) between components
set(MISSION_CORE_MODULES
"cfe-core"
"cfe_app_intf"
"cfe_internal_intf"
"es"
"evs"
"fs"
"sb"
"tbl"
"time"
"osal"
"psp"
"msg"
Expand Down Expand Up @@ -45,7 +53,6 @@ set(MISSION_MODULE_SEARCH_PATH
# a variable named "<component>_SEARCH_PATH". This is
# used for locating cfe-core and osal which are not part
# of the standard search path.
set(cfe-core_SEARCH_PATH "cfe/fsw")
set(osal_SEARCH_PATH ".")
set(psp_SEARCH_PATH ".")

Expand Down
2 changes: 1 addition & 1 deletion cmake/target/src/target_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "cfe_platform_cfg.h"
#include "cfe_es.h"
#include "cfe_time.h"
#include "private/cfe_es_resetdata_typedef.h"
#include "cfe_es_resetdata_typedef.h"
#include "cfe_version.h" /* for CFE_VERSION_STRING */
#include "osapi-version.h" /* for OS_VERSION_STRING */

Expand Down
Loading

0 comments on commit 3c4b9cf

Please sign in to comment.