Skip to content

Commit ae1dc3b

Browse files
authored
Merge pull request #1549 from jphickey/fix-1538-multi-tables
Fix #1538, add capability to generate multiple tables
2 parents c4c237a + a47a581 commit ae1dc3b

File tree

2 files changed

+95
-72
lines changed

2 files changed

+95
-72
lines changed

cmake/arch_build.cmake

Lines changed: 94 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -148,80 +148,100 @@ endfunction(add_cfe_app_dependency)
148148
#
149149
function(add_cfe_tables APP_NAME TBL_SRC_FILES)
150150

151-
# The table source must be compiled using the same "include_directories"
152-
# as any other target, but it uses the "add_custom_command" so there is
153-
# no automatic way to do this (at least in the older cmakes)
154-
155-
# Create the intermediate table objects using the target compiler,
156-
# then use "elf2cfetbl" to convert to a .tbl file
157-
set(TBL_LIST)
158-
foreach(TBL ${TBL_SRC_FILES} ${ARGN})
159-
160-
# Get name without extension (NAME_WE) and append to list of tables
161-
get_filename_component(TBLWE ${TBL} NAME_WE)
162-
163-
foreach(TGT ${APP_STATIC_TARGET_LIST} ${APP_DYNAMIC_TARGET_LIST})
164-
set(TABLE_DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/tables_${TGT}")
165-
file(MAKE_DIRECTORY ${TABLE_DESTDIR})
166-
list(APPEND TBL_LIST "${TABLE_DESTDIR}/${TBLWE}.tbl")
167-
168-
# Check if an override exists at the mission level (recommended practice)
169-
# This allows a mission to implement a customized table without modifying
170-
# the original - this also makes for easier merging/updating if needed.
171-
if (EXISTS "${MISSION_DEFS}/tables/${TGT}_${TBLWE}.c")
172-
set(TBL_SRC "${MISSION_DEFS}/tables/${TGT}_${TBLWE}.c")
173-
elseif (EXISTS "${MISSION_SOURCE_DIR}/tables/${TGT}_${TBLWE}.c")
174-
set(TBL_SRC "${MISSION_SOURCE_DIR}/tables/${TGT}_${TBLWE}.c")
175-
elseif (EXISTS "${MISSION_DEFS}/tables/${TBLWE}.c")
176-
set(TBL_SRC "${MISSION_DEFS}/tables/${TBLWE}.c")
177-
elseif (EXISTS "${MISSION_SOURCE_DIR}/tables/${TBLWE}.c")
178-
set(TBL_SRC "${MISSION_SOURCE_DIR}/tables/${TBLWE}.c")
179-
elseif (EXISTS "${MISSION_DEFS}/${TGT}/tables/${TBLWE}.c")
180-
set(TBL_SRC "${MISSION_DEFS}/${TGT}/tables/${TBLWE}.c")
181-
elseif (IS_ABSOLUTE "${TBL}")
182-
set(TBL_SRC "${TBL}")
183-
else()
184-
set(TBL_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${TBL}")
185-
endif()
151+
if (TGTNAME)
152+
set (TABLE_TGTLIST ${TGTNAME})
153+
else()
154+
set (TABLE_TGTLIST ${TGTLIST_${APP_NAME}})
155+
endif()
186156

187-
if (NOT EXISTS "${TBL_SRC}")
188-
message(FATAL_ERROR "ERROR: No source file for table ${TBLWE}")
189-
else()
190-
message("NOTE: Selected ${TBL_SRC} as source for ${TBLWE}")
191-
endif()
157+
# The first parameter should match the name of an app that was
158+
# previously defined using "add_cfe_app". If target-scope properties
159+
# are used for include directories and compile definitions, this is needed
160+
# to compile tables with the same include path/definitions as the app has.
161+
# However historically this could have been any string, which still works
162+
# if directory-scope properties are used for includes, so this is not
163+
# an error.
164+
if (NOT TARGET ${APP_NAME})
165+
message("NOTE: \"${APP_NAME}\" passed to add_cfe_tables is not a previously-defined application target")
166+
endif()
167+
168+
# The table source must be compiled using the same "include_directories"
169+
# as any other target, but it uses the "add_custom_command" so there is
170+
# no automatic way to do this (at least in the older cmakes)
171+
172+
# Create the intermediate table objects using the target compiler,
173+
# then use "elf2cfetbl" to convert to a .tbl file
174+
foreach(TBL ${TBL_SRC_FILES} ${ARGN})
175+
176+
# Get name without extension (NAME_WE) and append to list of tables
177+
get_filename_component(TBLWE ${TBL} NAME_WE)
178+
179+
foreach(TGT ${TABLE_TGTLIST})
180+
set(TABLE_LIBNAME "${TGT}_${APP_NAME}_${TBLWE}")
181+
set(TABLE_DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/${TABLE_LIBNAME}")
182+
set(TABLE_BINARY "${TABLE_DESTDIR}/${TBLWE}.tbl")
183+
file(MAKE_DIRECTORY ${TABLE_DESTDIR})
184+
185+
# Check if an override exists at the mission level (recommended practice)
186+
# This allows a mission to implement a customized table without modifying
187+
# the original - this also makes for easier merging/updating if needed.
188+
if (EXISTS "${MISSION_DEFS}/tables/${TGT}_${TBLWE}.c")
189+
set(TBL_SRC "${MISSION_DEFS}/tables/${TGT}_${TBLWE}.c")
190+
elseif (EXISTS "${MISSION_SOURCE_DIR}/tables/${TGT}_${TBLWE}.c")
191+
set(TBL_SRC "${MISSION_SOURCE_DIR}/tables/${TGT}_${TBLWE}.c")
192+
elseif (EXISTS "${MISSION_DEFS}/${TGT}/tables/${TBLWE}.c")
193+
set(TBL_SRC "${MISSION_DEFS}/${TGT}/tables/${TBLWE}.c")
194+
elseif (EXISTS "${MISSION_DEFS}/tables/${TBLWE}.c")
195+
set(TBL_SRC "${MISSION_DEFS}/tables/${TBLWE}.c")
196+
elseif (EXISTS "${MISSION_SOURCE_DIR}/tables/${TBLWE}.c")
197+
set(TBL_SRC "${MISSION_SOURCE_DIR}/tables/${TBLWE}.c")
198+
elseif (IS_ABSOLUTE "${TBL}")
199+
set(TBL_SRC "${TBL}")
200+
else()
201+
set(TBL_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${TBL}")
202+
endif()
203+
204+
if (NOT EXISTS "${TBL_SRC}")
205+
message(FATAL_ERROR "ERROR: No source file for table ${TBLWE}")
206+
else()
207+
message("NOTE: Selected ${TBL_SRC} as source for ${APP_NAME}.${TBLWE} on ${TGT}")
208+
209+
# NOTE: On newer CMake versions this should become an OBJECT library which makes this simpler.
210+
# On older versions one may not referece the TARGET_OBJECTS property from the custom command.
211+
# As a workaround this is built into a static library, and then the desired object is extracted
212+
# before passing to elf2cfetbl. It is roundabout but it works.
213+
add_library(${TABLE_LIBNAME} STATIC ${TBL_SRC})
214+
target_link_libraries(${TABLE_LIBNAME} PRIVATE core_api)
215+
if (TARGET ${APP_NAME})
216+
target_include_directories(${TABLE_LIBNAME} PRIVATE $<TARGET_PROPERTY:${APP_NAME},INCLUDE_DIRECTORIES>)
217+
target_compile_definitions(${TABLE_LIBNAME} PRIVATE $<TARGET_PROPERTY:${APP_NAME},COMPILE_DEFINITIONS>)
218+
endif()
219+
220+
# IMPORTANT: This rule assumes that the output filename of elf2cfetbl matches
221+
# the input file name but with a different extension (.o -> .tbl)
222+
# The actual output filename is embedded in the source file (.c), however
223+
# this must match and if it does not the build will break. That's just the
224+
# way it is, because NO make system supports changing rules based on the
225+
# current content of a dependency (rightfully so).
226+
add_custom_command(
227+
OUTPUT ${TABLE_BINARY}
228+
COMMAND ${CMAKE_COMMAND}
229+
-DCMAKE_AR=${CMAKE_AR}
230+
-DTBLTOOL=${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl
231+
-DLIB=$<TARGET_FILE:${TABLE_LIBNAME}>
232+
-P ${CFE_SOURCE_DIR}/cmake/generate_table.cmake
233+
DEPENDS ${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl ${TABLE_LIBNAME}
234+
WORKING_DIRECTORY ${TABLE_DESTDIR}
235+
)
236+
237+
# Add a custom target to invoke the elf2cfetbl tool to generate the tbl file,
238+
# and install that binary file to the staging area.
239+
add_custom_target(${TABLE_LIBNAME}_tbl ALL DEPENDS ${TABLE_BINARY})
240+
install(FILES ${TABLE_BINARY} DESTINATION ${TGT}/${INSTALL_SUBDIR})
241+
endif()
242+
endforeach()
243+
endforeach()
192244

193-
# NOTE: On newer CMake versions this should become an OBJECT library which makes this simpler.
194-
# On older versions one may not referece the TARGET_OBJECTS property from the custom command.
195-
# As a workaround this is built into a static library, and then the desired object is extracted
196-
# before passing to elf2cfetbl. It is roundabout but it works.
197-
add_library(${TGT}_${TBLWE}-obj STATIC ${TBL_SRC})
198-
target_link_libraries(${TGT}_${TBLWE}-obj PRIVATE core_api)
199-
200-
# IMPORTANT: This rule assumes that the output filename of elf2cfetbl matches
201-
# the input file name but with a different extension (.o -> .tbl)
202-
# The actual output filename is embedded in the source file (.c), however
203-
# this must match and if it does not the build will break. That's just the
204-
# way it is, because NO make system supports changing rules based on the
205-
# current content of a dependency (rightfully so).
206-
add_custom_command(
207-
OUTPUT "${TABLE_DESTDIR}/${TBLWE}.tbl"
208-
COMMAND ${CMAKE_COMMAND}
209-
-DCMAKE_AR=${CMAKE_AR}
210-
-DTBLTOOL=${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl
211-
-DLIB=$<TARGET_FILE:${TGT}_${TBLWE}-obj>
212-
-P ${CFE_SOURCE_DIR}/cmake/generate_table.cmake
213-
DEPENDS ${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl ${TGT}_${TBLWE}-obj
214-
WORKING_DIRECTORY ${TABLE_DESTDIR}
215-
)
216-
# Create the install targets for all the tables
217-
install(FILES ${TABLE_DESTDIR}/${TBLWE}.tbl DESTINATION ${TGT}/${INSTALL_SUBDIR})
218-
endforeach(TGT ${APP_STATIC_TARGET_LIST} ${APP_DYNAMIC_TARGET_LIST})
219-
220-
221-
endforeach(TBL ${TBL_SRC_FILES} ${ARGN})
222-
223-
# Make a custom target that depends on all the tables
224-
add_custom_target(${APP_NAME}_tables ALL DEPENDS ${TBL_LIST})
225245

226246
endfunction(add_cfe_tables)
227247

@@ -689,6 +709,8 @@ function(process_arch SYSVAR)
689709
# Target to generate the actual executable file
690710
add_subdirectory(cmake/target ${TGTNAME})
691711

712+
include(${MISSION_DEFS}/${TGTNAME}/install_custom.cmake OPTIONAL)
713+
692714
foreach(INSTFILE ${${TGTNAME}_FILELIST})
693715
if(EXISTS ${MISSION_DEFS}/${TGTNAME}/${INSTFILE})
694716
set(FILESRC ${MISSION_DEFS}/${TGTNAME}/${INSTFILE})

cmake/generate_table.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ if (NOT RESULT EQUAL 0)
3838
endif()
3939

4040
# Finally invoke the table tool (elf2cfetbl) on the object
41+
message("Executing Process: ${TBLTOOL} ${OBJNAME}")
4142
execute_process(COMMAND ${TBLTOOL} "${OBJNAME}"
4243
RESULT_VARIABLE RESULT
4344
)

0 commit comments

Comments
 (0)