Skip to content

Commit af07f5f

Browse files
committed
Merge pull request #2483 from jphickey:fix-2483-tblbuild
Fix #2483, clean up and move table build scripts
2 parents 5a8bbc4 + dd43aaf commit af07f5f

9 files changed

+782
-235
lines changed

cmake/arch_build.cmake

+18-106
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,14 @@ endfunction(add_cfe_app_dependency)
190190
# of the target from targets.cmake and TABLE_FQNAME reflects the first
191191
# parameter to this function.
192192
#
193+
# The table tool must provide an implementation to use with add_cfe_tables().
194+
#
193195
function(add_cfe_tables TABLE_FQNAME TBL_DEFAULT_SRC_FILES)
194196

197+
if (NOT TBL_DEFAULT_SRC_FILES)
198+
message(FATAL_ERROR "Table source file list is empty")
199+
endif()
200+
195201
get_filename_component(APP_NAME ${TABLE_FQNAME} NAME_WE)
196202

197203
# The passed-in name allows for a qualifier (in the form of APP_NAME.QUALIFIER) to get
@@ -213,23 +219,11 @@ function(add_cfe_tables TABLE_FQNAME TBL_DEFAULT_SRC_FILES)
213219

214220
# If "TGTNAME" is set, then use it directly
215221
set(TABLE_TGTLIST ${TGTNAME})
216-
set(TABLE_TEMPLATE "${CFE_SOURCE_DIR}/cmake/tables/table_rule_template.d.in")
217-
set(TABLE_CMD_BASIC_OPTS
218-
-DTEMPLATE_FILE="${TABLE_TEMPLATE}"
219-
-DAPP_NAME="${APP_NAME}"
220-
)
221-
222-
if (INSTALL_SUBDIR)
223-
list(APPEND TABLE_CMD_BASIC_OPTS
224-
-DINSTALL_SUBDIR="${INSTALL_SUBDIR}"
225-
)
226-
endif()
227222

228223
if (TARGET ${APP_NAME}.table)
229224
if (NOT TABLE_TGTLIST)
230225
set (TABLE_TGTLIST ${TGTLIST_${APP_NAME}})
231226
endif()
232-
set(TABLE_PARENT_TGT ${APP_NAME}.table)
233227
else()
234228
# The first parameter should match the name of an app that was
235229
# previously defined using "add_cfe_app". If target-scope properties
@@ -242,108 +236,21 @@ function(add_cfe_tables TABLE_FQNAME TBL_DEFAULT_SRC_FILES)
242236
if (NOT TABLE_TGTLIST)
243237
set (TABLE_TGTLIST ${APP_STATIC_TARGET_LIST} ${APP_DYNAMIC_TARGET_LIST})
244238
endif()
245-
# No (known) parent app, just use core_api in this case. It will only get global-scope includes and defines.
246-
set(TABLE_PARENT_TGT core_api)
247239
endif()
248240

249-
set(TABLE_GENSCRIPT "${CFE_SOURCE_DIR}/cmake/tables/generate_elf_table_rules.cmake")
250-
251241
# The table source must be compiled using the same "include_directories"
252242
# as any other target, but it uses the "add_custom_command" so there is
253243
# no automatic way to do this (at least in the older cmakes)
254244
foreach(TGT ${TABLE_TGTLIST})
255245

256-
set(TABLE_CMD_TGT_OPTS
257-
-DTARGET_NAME="${TGT}"
246+
do_add_cfe_tables_impl("${TABLE_FQNAME}"
247+
APP_NAME "${APP_NAME}"
248+
TARGET_NAME "${TGT}"
249+
INSTALL_SUBDIR "${INSTALL_SUBDIR}"
250+
${TBL_DEFAULT_SRC_FILES} ${ARGN}
258251
)
259252

260-
set(TABLE_LIBNAME "tblobj_${TGT}_${TABLE_FQNAME}")
261-
list(APPEND TABLE_CMD_TGT_OPTS "-DARCHIVE_FILE=\"$<TARGET_FILE:${TABLE_LIBNAME}>\"")
262-
263-
# Note that the TBL_DEFAULT_SRC_FILES is just a default - we now need
264-
# to find the active source, which typically comes from the MISSION_DEFS dir.
265-
# The TABLE_SELECTED_SRCS will become this list of active/selected source files
266-
set(TABLE_SELECTED_SRCS)
267-
foreach(TBL ${TBL_DEFAULT_SRC_FILES} ${ARGN})
268-
269-
# The file source basename (without directory or ext) should be the same as the table
270-
# binary filename with a ".tbl" extension (this is the convention assumed by elf2cfetbl)
271-
get_filename_component(TABLE_SRC_NEEDED ${TBL} NAME)
272-
get_filename_component(TABLE_BASENAME ${TBL} NAME_WE)
273-
274-
275-
# Check if an override exists at the mission level (recommended practice)
276-
# This allows a mission to implement a customized table without modifying
277-
# the original - this also makes for easier merging/updating if needed.
278-
# Note this path list is in reverse-priority order, and only a single file
279-
# will be end up being selected.
280-
cfe_locate_implementation_file(TBL_SRC "${TABLE_SRC_NEEDED}"
281-
OPTIONAL
282-
FALLBACK_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${TBL}"
283-
PREFIX ${TGT}
284-
SUBDIR tables
285-
)
286-
287-
list(APPEND TABLE_SELECTED_SRCS ${TBL_SRC})
288-
289-
if (TBL_SRC)
290-
message(STATUS "Using ${TBL_SRC} as table definition for ${TABLE_BASENAME} on ${TGT}")
291-
else()
292-
message(FATAL_ERROR "No table definition for ${APP_NAME}.${TABLE_BASENAME} on ${TGT} found")
293-
endif()
294-
295-
# Set a preprocessor macro so when the .c file is compiled it knows what its
296-
# input and (by convention) output name is supposed to be.
297-
if (TABLE_LIBNAME)
298-
set_property(SOURCE "${TBL_SRC}" APPEND PROPERTY COMPILE_DEFINITIONS
299-
CFE_TABLE_NAME=${TABLE_BASENAME}
300-
)
301-
endif()
302-
303-
# Note the table is not generated directly here, as it may require the native system compiler, so
304-
# the call to the table tool (eds2cfetbl in this build) is deferred to the parent scope. Instead, this
305-
# generates a file that captures the state (include dirs, source files, targets) for use in a future step.
306-
set(TABLE_RULEFILE "${MISSION_BINARY_DIR}/tables/${TGT}_${TABLE_FQNAME}.${TABLE_BASENAME}.d")
307-
add_custom_command(
308-
OUTPUT "${TABLE_RULEFILE}"
309-
COMMAND ${CMAKE_COMMAND}
310-
${TABLE_CMD_BASIC_OPTS}
311-
${TABLE_CMD_TGT_OPTS}
312-
-DOUTPUT_FILE="${TABLE_RULEFILE}"
313-
-DTABLE_NAME="${TABLE_BASENAME}"
314-
-DSOURCES="${TBL_SRC}"
315-
-DOBJEXT="${CMAKE_C_OUTPUT_EXTENSION}"
316-
-P "${TABLE_GENSCRIPT}"
317-
WORKING_DIRECTORY
318-
${WORKING_DIRECTORY}
319-
DEPENDS
320-
${TABLE_TEMPLATE}
321-
${TABLE_GENSCRIPT}
322-
${TABLE_PARENT_TGT}
323-
)
324-
325-
# Add a custom target to generate the config file
326-
add_custom_target(generate_table_${TGT}_${APP_NAME}_${TABLE_BASENAME}
327-
DEPENDS "${TABLE_RULEFILE}" ${TABLE_LIBNAME}
328-
)
329-
add_dependencies(cfetables generate_table_${TGT}_${APP_NAME}_${TABLE_BASENAME})
330-
331-
endforeach()
332-
333-
if (TABLE_LIBNAME)
334-
# NOTE: On newer CMake versions this should become an OBJECT library which makes this simpler.
335-
# On older versions one may not reference the TARGET_OBJECTS property from the custom command.
336-
# As a workaround this is built into a static library, and then the desired object is extracted
337-
# before passing to elf2cfetbl. It is roundabout but it works.
338-
add_library(${TABLE_LIBNAME} STATIC EXCLUDE_FROM_ALL ${TABLE_SELECTED_SRCS})
339-
target_compile_definitions(${TABLE_LIBNAME} PRIVATE
340-
CFE_CPU_NAME=${TGT}
341-
)
342-
target_link_libraries(${TABLE_LIBNAME} ${TABLE_PARENT_TGT})
343-
endif()
344-
345-
endforeach()
346-
253+
endforeach(TGT ${TABLE_TGTLIST})
347254

348255
endfunction(add_cfe_tables)
349256

@@ -673,7 +580,6 @@ function(setup_platform_msgids)
673580

674581
# This is the actual export to parent scope
675582
foreach(VAR_NAME ${OUTPUT_VAR_LIST})
676-
message("${VAR_NAME}=${PLATFORM_MSGID_HEADERFILE}")
677583
set(${VAR_NAME} ${PLATFORM_MSGID_HEADERFILE} PARENT_SCOPE)
678584
endforeach(VAR_NAME ${OUTPUT_VAR_LIST})
679585

@@ -695,6 +601,12 @@ function(prepare)
695601
# all generated table files will be added as dependencies to this target
696602
add_custom_target(cfetables)
697603

604+
# The table tool must provide an implementation to use with add_cfe_tables().
605+
# this is determined by the CFS_TABLETOOL_SCRIPT_DIR that must be exported
606+
# from the parent build.
607+
#
608+
include(${CFS_TABLETOOL_SCRIPT_DIR}/add_cfe_tables_impl.cmake)
609+
698610
# Choose the configuration file to use for OSAL on this system
699611
set(OSAL_CONFIGURATION_FILE)
700612
foreach(CONFIG ${BUILD_CONFIG_${TARGETSYSTEM}} ${OSAL_SYSTEM_OSCONFIG})

cmake/generate_git_module_version.cmake

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ function(get_version DEP)
2727
endif()
2828
set(DIR ${${DEP}_MISSION_DIR})
2929
endif()
30-
message("inside get_version for ${DEP}")
30+
31+
if ($ENV{VERBOSE})
32+
message("inside get_version for ${DEP}")
33+
endif()
34+
3135
execute_process(
3236
COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty
3337
WORKING_DIRECTORY ${DIR}

cmake/mission_build.cmake

+81-59
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,53 @@ function(setup_global_topicids)
233233

234234
endfunction(setup_global_topicids)
235235

236+
##################################################################
237+
#
238+
# FUNCTION: export_variable_cache
239+
#
240+
# Export variables to a "mission_vars.cache" file so they can be
241+
# referenced by the target-specific builds. This list is ingested
242+
# during the startup phase of all the subordinate cmake invocations.
243+
#
244+
# The passed-in USER_VARLIST should be the names of additional variables
245+
# to export. These can be cache vars or normal vars.
246+
#
247+
function(export_variable_cache USER_VARLIST)
248+
249+
# The set of variables that should always be exported
250+
set(FIXED_VARLIST
251+
"MISSION_NAME"
252+
"SIMULATION"
253+
"MISSION_DEFS"
254+
"MISSION_SOURCE_DIR"
255+
"MISSION_BINARY_DIR"
256+
"MISSIONCONFIG"
257+
"MISSION_APPS"
258+
"MISSION_PSPMODULES"
259+
"MISSION_DEPS"
260+
"MISSION_EDS_FILELIST"
261+
"MISSION_EDS_SCRIPTLIST"
262+
"ENABLE_UNIT_TESTS"
263+
)
264+
265+
set(MISSION_VARCACHE)
266+
foreach(VARL ${FIXED_VARLIST} ${USER_VARLIST} ${ARGN})
267+
# It is important to avoid putting any blank lines in the output,
268+
# This will cause the reader to misinterpret the data
269+
if (NOT "${${VARL}}" STREQUAL "")
270+
string(APPEND MISSION_VARCACHE "${VARL}\n${${VARL}}\n")
271+
endif (NOT "${${VARL}}" STREQUAL "")
272+
endforeach()
273+
274+
# Write the file -- the subprocess will read this file and re-create
275+
# variables out of them. The alternative to this is to specify many "-D"
276+
# parameters to the subordinate build but that would not scale well to many vars,
277+
# and it would go through the shell meaning quoting/escaping for safety becomes
278+
# very difficult. Using the file method avoids shell interpretation.
279+
file(WRITE "${CMAKE_BINARY_DIR}/mission_vars.cache" "${MISSION_VARCACHE}")
280+
281+
endfunction(export_variable_cache)
282+
236283
##################################################################
237284
#
238285
# FUNCTION: prepare
@@ -246,15 +293,16 @@ function(prepare)
246293
add_definitions(-DSIMULATION=${SIMULATION})
247294
endif (SIMULATION)
248295

249-
# Prepare the table makefile - Ensure the list of tables is initially empty
250-
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/tables")
251-
file(WRITE "${MISSION_BINARY_DIR}/tables/Makefile"
252-
"MISSION_BINARY_DIR := ${MISSION_BINARY_DIR}\n"
253-
"TABLE_BINARY_DIR := ${MISSION_BINARY_DIR}/tables\n"
254-
"MISSION_SOURCE_DIR := ${MISSION_SOURCE_DIR}\n"
255-
"MISSION_DEFS := ${MISSION_DEFS}\n\n"
256-
"include \$(wildcard ${CFE_SOURCE_DIR}/cmake/tables/*.mk) \$(wildcard *.d)\n"
257-
)
296+
# Create directories to hold generated files/wrappers
297+
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/eds")
298+
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/obj")
299+
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/inc")
300+
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/src")
301+
302+
# Certain runtime variables need to be "exported" to the subordinate build, such as
303+
# the specific arch settings and the location of all the apps. This list is collected
304+
# during this function execution and exported at the end.
305+
set(EXPORT_VARLIST)
258306

259307
# Create custom targets for building and cleaning all architectures
260308
# This is required particularly for doing extra stuff in the clean step
@@ -428,76 +476,46 @@ function(prepare)
428476
# msgid definitions, or any other configuration/preparation that needs to
429477
# happen at mission/global scope.
430478
foreach(DEP_NAME ${MISSION_DEPS})
479+
list(APPEND EXPORT_VARLIST "${DEP_NAME}_MISSION_DIR")
431480
include("${${DEP_NAME}_MISSION_DIR}/mission_build.cmake" OPTIONAL)
432481
endforeach(DEP_NAME ${MISSION_DEPS})
433482

434-
# Certain runtime variables need to be "exported" to the subordinate build, such as
435-
# the specific arch settings and the location of all the apps. This is done by creating
436-
# a temporary file within the dir and then the subprocess will read that file and re-create
437-
# variables out of them. The alternative to this is to specify many "-D" parameters to the
438-
# subordinate build but that would not scale well to many vars.
439-
set(VARLIST
440-
"MISSION_NAME"
441-
"SIMULATION"
442-
"MISSION_DEFS"
443-
"MISSION_SOURCE_DIR"
444-
"MISSION_BINARY_DIR"
445-
"MISSIONCONFIG"
446-
"MISSION_APPS"
447-
"MISSION_PSPMODULES"
448-
"MISSION_DEPS"
449-
"ENABLE_UNIT_TESTS"
450-
)
451-
foreach(APP ${MISSION_DEPS})
452-
list(APPEND VARLIST "${APP}_MISSION_DIR")
453-
endforeach()
454-
455483
foreach(SYSVAR ${TGTSYS_LIST})
456-
list(APPEND VARLIST "BUILD_CONFIG_${SYSVAR}")
484+
list(APPEND EXPORT_VARLIST "BUILD_CONFIG_${SYSVAR}")
457485
endforeach(SYSVAR ${TGTSYS_LIST})
458486

459-
set(MISSION_VARCACHE)
460-
foreach(VARL ${VARLIST})
461-
# It is important to avoid putting any blank lines in the output,
462-
# This will cause the reader to misinterpret the data
463-
if (NOT "${${VARL}}" STREQUAL "")
464-
set(MISSION_VARCACHE "${MISSION_VARCACHE}${VARL}\n${${VARL}}\n")
465-
endif (NOT "${${VARL}}" STREQUAL "")
466-
endforeach(VARL ${VARLIST})
467-
file(WRITE "${CMAKE_BINARY_DIR}/mission_vars.cache" "${MISSION_VARCACHE}")
468-
469487
generate_build_version_templates()
470488

471489
# Generate the tools for the native (host) arch
472490
# Add all public include dirs for core components to include path for tools
473491
include_directories(
492+
${MISSION_BINARY_DIR}/inc
474493
${core_api_MISSION_DIR}/fsw/inc
475494
${osal_MISSION_DIR}/src/os/inc
476495
${psp_MISSION_DIR}/fsw/inc
477496
)
478497
add_subdirectory(${MISSION_SOURCE_DIR}/tools tools)
479498

480499
# Add a dependency on the table generator tool as this is required for table builds
481-
# The "elf2cfetbl" target should have been added by the "tools" above
482-
add_dependencies(mission-prebuild elf2cfetbl)
483-
set(TABLETOOL_EXEC $<TARGET_FILE:elf2cfetbl>)
484-
485-
add_custom_target(tabletool-execute
486-
COMMAND $(MAKE)
487-
CC="${CMAKE_C_COMPILER}"
488-
CFLAGS="${CMAKE_C_FLAGS}"
489-
AR="${CMAKE_AR}"
490-
TBLTOOL="${TABLETOOL_EXEC}"
491-
cfetables
492-
WORKING_DIRECTORY
493-
"${CMAKE_BINARY_DIR}/tables"
494-
DEPENDS
495-
mission-cfetables
500+
# The table tool target should have been added by the "tools" above
501+
if (NOT DEFINED CFS_TABLETOOL_SCRIPT_DIR)
502+
message(FATAL_ERROR "Table Tool missing: CFS_TABLETOOL_SCRIPT_DIR must be defined by the tools")
503+
endif()
504+
list(APPEND EXPORT_VARLIST CFS_TABLETOOL_SCRIPT_DIR)
505+
506+
# Prepare the table makefile - Ensure the list of tables is initially empty
507+
file(REMOVE_RECURSE "${MISSION_BINARY_DIR}/tables")
508+
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/tables")
509+
file(WRITE "${MISSION_BINARY_DIR}/tables/Makefile"
510+
"MISSION_BINARY_DIR := ${MISSION_BINARY_DIR}\n"
511+
"TABLE_BINARY_DIR := ${MISSION_BINARY_DIR}/tables\n"
512+
"TABLETOOL_SCRIPT_DIR := ${CFS_TABLETOOL_SCRIPT_DIR}\n"
513+
"MISSION_SOURCE_DIR := ${MISSION_SOURCE_DIR}\n"
514+
"MISSION_DEFS := ${MISSION_DEFS}\n\n"
515+
"include \$(wildcard $(TABLETOOL_SCRIPT_DIR)/*.mk) \$(wildcard *.d)\n"
496516
)
497-
add_dependencies(mission-all tabletool-execute)
498-
add_dependencies(mission-install tabletool-execute)
517+
499518
add_dependencies(mission-cfetables mission-prebuild)
500-
install(DIRECTORY ${CMAKE_BINARY_DIR}/tables/staging/ DESTINATION .)
501519

502520
# Build version information should be generated as part of the pre-build process
503521
add_dependencies(mission-prebuild mission-version)
@@ -507,6 +525,10 @@ function(prepare)
507525
install(DIRECTORY ${MISSION_DEFS}/functional-test/ DESTINATION ${FT_INSTALL_SUBDIR})
508526
endif()
509527

528+
# Export the important state variables collected during this function.
529+
# This is done last such that everything should have its correct value
530+
export_variable_cache(${EXPORT_VARLIST})
531+
510532
endfunction(prepare)
511533

512534
##################################################################

0 commit comments

Comments
 (0)