-
Notifications
You must be signed in to change notification settings - Fork 210
/
Copy patharch_build.cmake
831 lines (701 loc) · 32 KB
/
arch_build.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
##################################################################
#
# Core Flight System architecture-specific build recipes
#
# This file is invoked by the top-level mission recipe for
# to build cFE/cFS for each target processor
#
# Note that the target CPUs may use different architectures, therefore each
# architecture must be done as a separate sub-build since none of the binaries
# can be shared.
#
##################################################################
# define a custom property to track dependencies on CFE module targets.
# users should not typically manipulate this directly
define_property(TARGET PROPERTY CFE_MODULE_DEPENDENCIES
BRIEF_DOCS
"A set of CFE module dependencies"
FULL_DOCS
"This is a CFE-specific target property that is added to CFE modules that contains the module dependencies"
)
##################################################################
#
# FUNCTION: initialize_globals
#
# Set up global mission configuration variables.
# This function determines the mission configuration directory and
# also reads any startup state info from file(s) on the disk
#
# In the CPU (cross) build this only reads a cache file that was
# generated by the mission (top-level) build. Therefore all
# architecture-specific cross builds will get the same settings.
#
function(initialize_globals)
# Sanity check -- the parent build script should have set MISSION_BINARY_DIR
if (NOT IS_DIRECTORY "${MISSION_BINARY_DIR}")
message(FATAL_ERROR "BUG -- MISSION_BINARY_DIR not a valid directory in arch_build.cmake")
endif()
# Read the variable values from the cache file.
set(MISSION_IMPORTED_VARS)
file(READ "${MISSION_BINARY_DIR}/mission_vars.cache" PARENTVARS)
string(REGEX REPLACE ";" "\\\\;" PARENTVARS "${PARENTVARS}")
string(REGEX REPLACE "\n" ";" PARENTVARS "${PARENTVARS}")
foreach(PV ${PARENTVARS})
if (VARNAME)
set(${VARNAME} ${PV} PARENT_SCOPE)
list(APPEND MISSION_IMPORTED_VARS ${VARNAME})
unset(VARNAME)
else()
set(VARNAME ${PV})
endif()
endforeach(PV ${PARENTVARS})
unset(VARNAME)
unset(PARENTVARS)
set(MISSION_IMPORTED_VARS ${MISSION_IMPORTED_VARS} PARENT_SCOPE)
endfunction(initialize_globals)
##################################################################
#
# FUNCTION: add_psp_module
#
# Simplified routine to add a driver to the PSP in use on this arch
# Called by module listfiles
#
function(add_psp_module MOD_NAME MOD_SRC_FILES)
# Create the module
add_library(${MOD_NAME} STATIC ${MOD_SRC_FILES} ${ARGN})
target_link_libraries(${MOD_NAME} PRIVATE psp_module_api)
target_compile_definitions(${MOD_NAME} PRIVATE
_CFE_PSP_MODULE_
)
endfunction(add_psp_module)
##################################################################
#
# FUNCTION: add_cfe_app
#
# Simplified routine to add a CFS app or lib this arch
# Called by module listfiles
#
function(add_cfe_app APP_NAME APP_SRC_FILES)
# currently this will build an app with either static linkage or shared/module linkage,
# but this does not currently support both for a single arch (could be revised if that is needed)
if (APP_DYNAMIC_TARGET_LIST)
set(APPTYPE "MODULE")
else()
set(APPTYPE "STATIC")
endif()
# Create the app module
add_library(${APP_NAME} ${APPTYPE} ${APP_SRC_FILES} ${ARGN})
target_link_libraries(${APP_NAME} core_api)
# If using "local" EDS linkage, then link the app with the EDS library here.
# Note that the linker will only pull in the compilation unit that actually
# resolves an undefined symbol, which in this case would be the app-specific
# DATATYPE_DB object if one is referenced at all.
#
# By linking with the respective application like this, the net result is that
# only the _referenced_ EDS DBs (i.e. those for loaded apps) are held in memory.
if (CFE_EDS_ENABLED_BUILD AND CFE_EDS_LINK_MODE STREQUAL LOCAL)
target_link_libraries($(APP_NAME) cfe_edsdb_static)
endif()
# An "install" step is only needed for dynamic/runtime loaded apps
if (APP_DYNAMIC_TARGET_LIST)
cfs_app_do_install(${APP_NAME} ${APP_DYNAMIC_TARGET_LIST})
endif (APP_DYNAMIC_TARGET_LIST)
# Add an interface target is added with a ".table" suffix,
# this should reflect all the INCLUDE_DIRECTORIES and COMPILE_DEFINITIONS that
# were used when compiling the app itself, such that tables (and other items) can be
# added later and reference the same set.
add_library(${APP_NAME}.table INTERFACE)
get_directory_property(CURRENT_INCLUDE_DIRS INCLUDE_DIRECTORIES)
if (NOT CURRENT_INCLUDE_DIRS)
set(CURRENT_INCLUDE_DIRS) # make it empty, not -NOTFOUND
endif()
get_directory_property(CURRENT_COMPILE_DEFS COMPILE_DEFINITIONS)
if (NOT CURRENT_COMPILE_DEFS)
set(CURRENT_COMPILE_DEFS) # make it empty, not -NOTFOUND
endif()
list (APPEND CURRENT_INCLUDE_DIRS
$<TARGET_PROPERTY:${APP_NAME},INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:core_api,INTERFACE_INCLUDE_DIRECTORIES>
)
list (APPEND CURRENT_COMPILE_DEFS
$<TARGET_PROPERTY:${APP_NAME},COMPILE_DEFINITIONS>
$<TARGET_PROPERTY:core_api,INTERFACE_COMPILE_DEFINITIONS>
)
target_include_directories(${APP_NAME}.table INTERFACE ${CURRENT_INCLUDE_DIRS})
target_compile_definitions(${APP_NAME}.table INTERFACE ${CURRENT_COMPILE_DEFS} CFE_APP_NAME="${APP_NAME}")
endfunction(add_cfe_app)
##################################################################
#
# FUNCTION: add_cfe_app_dependency
#
# Adds a library dependency to a previously-created
# app/library target
#
# it adds the interface include directories and compile definitions
# of the dependency into the compilation for the module.
#
function(add_cfe_app_dependency MODULE_NAME DEPENDENCY_MODULE)
# assemble a list of include directories and compile definitions
set(INCLUDE_LIST)
set(COMPILE_DEF_LIST)
foreach(DEP ${DEPENDENCY_MODULE} ${ARGN})
list(APPEND INCLUDE_LIST "$<TARGET_PROPERTY:${DEP},INTERFACE_INCLUDE_DIRECTORIES>")
list(APPEND COMPILE_DEF_LIST "$<TARGET_PROPERTY:${DEP},INTERFACE_COMPILE_DEFINITIONS>")
endforeach()
target_include_directories(${MODULE_NAME} PUBLIC
${INCLUDE_LIST}
)
target_compile_definitions(${MODULE_NAME} PUBLIC
${COMPILE_DEF_LIST}
)
# append to the custom property to track this dependency (this helpful for UT)
set_property(TARGET ${MODULE_NAME} APPEND PROPERTY CFE_MODULE_DEPENDENCIES ${DEPENDENCY_MODULE} ${ARGN})
endfunction(add_cfe_app_dependency)
##################################################################
#
# FUNCTION: add_cfe_tables
#
# Simplified routine to add CFS tables to be built with an app
#
# For apps with just a single table, the TABLE_FQNAME may be the
# same as the app name, which is simple.
#
# For apps with multiple tables, the TABLE_FQNAME may be of the
# form "${APP_NAME}.${TABLE_NAME}" where ${APP_NAME} refers to an
# app target that was registered via the "add_cfe_app" function.
#
# Note that for backward compatibility, any name will be accepted
# for TABLE_FQNAME. However if this function cannot determine which
# app the table is associated with, it will only have a default set
# of INCLUDE_DIRECTORIES when building the C source file(s). By
# associating a table with an app using the conventions above, the
# INCLUDE_DIRECTORIES from the parent app will be used when building the
# tables.
#
# This function produces one or more library targets in CMake, using names
# of the form: "tblobj_${TGT}_{TABLE_FQNAME}" where TGT reflects the name
# of the target from targets.cmake and TABLE_FQNAME reflects the first
# parameter to this function.
#
# The table tool must provide an implementation to use with add_cfe_tables().
#
function(add_cfe_tables TABLE_FQNAME TBL_DEFAULT_SRC_FILES)
if (NOT TBL_DEFAULT_SRC_FILES)
message(FATAL_ERROR "Table source file list is empty")
endif()
get_filename_component(APP_NAME ${TABLE_FQNAME} NAME_WE)
# The passed-in name allows for a qualifier (in the form of APP_NAME.QUALIFIER) to get
# uniqueness in the generated target names. If there is no qualifier, then there
# will potentially be a target name conflict. To avoid this, generate a hash of the
# context of this call - the current directory, app/tgt names, and source files. This
# should be unique but also produce the same hash when CMake is re-run. The hash
# can then be used as a qualifier.
if (TABLE_FQNAME STREQUAL APP_NAME)
string(SHA1 CONTEXT_HASH
"${CMAKE_CURRENT_LIST_DIR}+${TGTNAME}+${APP_NAME}+${TBL_DEFAULT_SRC_FILES};${ARGN}"
)
set(TABLE_FQNAME "${APP_NAME}.tbl${CONTEXT_HASH}")
if ($ENV{VERBOSE})
message("No suffix specified, table build using ${TABLE_FQNAME} for ${APP_NAME} table")
endif()
endif()
# If "TGTNAME" is set, then use it directly
set(TABLE_TGTLIST ${TGTNAME})
if (TARGET ${APP_NAME}.table)
if (NOT TABLE_TGTLIST)
set (TABLE_TGTLIST ${TGTLIST_${APP_NAME}})
endif()
else()
# The first parameter should match the name of an app that was
# previously defined using "add_cfe_app". If target-scope properties
# are used for include directories and compile definitions, this is needed
# to compile tables with the same include path/definitions as the app has.
# However historically this could have been any string, which still works
# if directory-scope properties are used for includes, so this is not
# an error.
message("NOTE: \"${APP_NAME}\" passed to add_cfe_tables is not a previously-defined application target")
if (NOT TABLE_TGTLIST)
set (TABLE_TGTLIST ${APP_STATIC_TARGET_LIST} ${APP_DYNAMIC_TARGET_LIST})
endif()
endif()
# 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)
foreach(TGT ${TABLE_TGTLIST})
do_add_cfe_tables_impl("${TABLE_FQNAME}"
APP_NAME "${APP_NAME}"
TARGET_NAME "${TGT}"
INSTALL_SUBDIR "${INSTALL_SUBDIR}"
${TBL_DEFAULT_SRC_FILES} ${ARGN}
)
endforeach(TGT ${TABLE_TGTLIST})
endfunction(add_cfe_tables)
##################################################################
#
# FUNCTION: add_cfe_coverage_dependency
#
# Adds a stub library dependency to a previously-created
# coverage test runner target
#
# If a unit under test calls functions provided by another unit
# (such as a library) then the stubs from that library will be
# added to the LINK_LIBRARIES of the coverage test.
#
function(add_cfe_coverage_dependency MODULE_NAME UNIT_NAME DEPENDENCY_MODULE)
# the stub library correlating to the module should be named:
# coverage-${MODULE_NAME}-stubs
# (assuming it was added by the add_cfe_coverage_stubs above)
set(DEP_LIST)
foreach(DEP ${DEPENDENCY_MODULE} ${ARGN})
list(APPEND DEP_LIST "coverage-${DEP}-stubs")
endforeach()
target_link_libraries(coverage-${MODULE_NAME}-${UNIT_NAME}-testrunner
${DEP_LIST}
)
endfunction(add_cfe_coverage_dependency)
##################################################################
#
# FUNCTION: add_cfe_coverage_test
#
# Add executable target for coverage testing. This builds the target
# units with extra compiler flags for coverage instrumentation, along with
# a "testrunner" executable to run the tests. It also registers
# that testrunner with ctest via the add_test() function.
#
# NOTE: The first argument (MODULE_NAME) must match the name that was previously
# passed to the add_cfe_app() function - as this references that previous
# target to use the same compile definitions and include paths.
#
# The executable target name follows the pattern:
# "coverage-${MODULE_NAME}-${UNIT_NAME}-testrunner"
#
# The calling script may call target_link_libraries() (or other target functions)
# to customize this target as needed.
#
function(add_cfe_coverage_test MODULE_NAME UNIT_NAME TESTCASE_SRC UT_SRCS)
# A consistent name convention for all targets generated by this function
set(TEST_NAME "coverage-${MODULE_NAME}-${UNIT_NAME}")
set(OBJECT_TARGET "${TEST_NAME}-object")
set(RUNNER_TARGET "${TEST_NAME}-testrunner")
# Compile the source unit(s) under test as a separate library
# This is done so that special coverage-specific compile flags can be used on these files
add_library(${OBJECT_TARGET} OBJECT
${UT_SRCS} ${ARGN}
)
# Apply the UT_COVERAGE_COMPILE_FLAGS to the units under test
# This should enable coverage analysis on platforms that support this
target_compile_options(${OBJECT_TARGET} PRIVATE
${UT_COVERAGE_COMPILE_FLAGS}
)
# Include the same set of include dirs/definitions that is used from the app target
target_include_directories(${OBJECT_TARGET} PUBLIC
$<TARGET_PROPERTY:${MODULE_NAME},INCLUDE_DIRECTORIES>
)
target_compile_definitions(${OBJECT_TARGET} PUBLIC
$<TARGET_PROPERTY:${MODULE_NAME},COMPILE_DEFINITIONS>
)
# Compile a test runner application, which contains the
# actual coverage test code (test cases) and the unit under test
add_executable(${RUNNER_TARGET}
${TESTCASE_SRC}
$<TARGET_OBJECTS:${OBJECT_TARGET}>
)
# Include the same set of include dirs/definitions that is used from the app target
target_include_directories(${RUNNER_TARGET} PUBLIC
$<TARGET_PROPERTY:${MODULE_NAME},INCLUDE_DIRECTORIES>
)
target_compile_definitions(${RUNNER_TARGET} PUBLIC
$<TARGET_PROPERTY:${MODULE_NAME},COMPILE_DEFINITIONS>
)
# This also needs to be linked with UT_COVERAGE_LINK_FLAGS (for coverage)
# This is also linked with any other stub libraries needed,
# as well as the UT assert framework
target_link_libraries(${RUNNER_TARGET}
${UT_COVERAGE_LINK_FLAGS}
ut_core_api_stubs
ut_assert
)
# for whatever app/lib dependencies the real FSW app had, the unit test
# should have the same dependencies but on the stubs instead.
get_target_property(MODULE_DEPENDENCIES ${MODULE_NAME} CFE_MODULE_DEPENDENCIES)
if (MODULE_DEPENDENCIES)
add_cfe_coverage_dependency(${MODULE_NAME} ${UNIT_NAME} ${MODULE_DEPENDENCIES})
endif(MODULE_DEPENDENCIES)
# Add it to the set of tests to run as part of "make test"
add_test(${TEST_NAME} ${RUNNER_TARGET})
foreach(TGT ${INSTALL_TARGET_LIST})
install(TARGETS ${RUNNER_TARGET} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR})
endforeach()
endfunction(add_cfe_coverage_test)
##################################################################
#
# FUNCTION: add_cfe_coverage_unit_include
#
# Add an "override" include directory for a specific unit test
#
# This can be used if a coverage test needs to override certain
# C library header files only for a specific unit under test. The
# include path is added only for the particular source files in the
# specified coverage test unit. (Not for the coverage test itself).
#
# The executable target name follows the pattern:
# "coverage-${MODULE_NAME}-${UNIT_NAME}-testrunner"
#
function(add_cfe_coverage_unit_include MODULE_NAME UNIT_NAME OVERRIDE_INCLUDE_DIRS)
# For the object target only, the "override" includes should be injected
# into the include path. Note it is important that this is only included
# for the specific unit under test (object lib) not the coverage
# test executable or test cases, since these typically need the real
# version of these functions.
target_include_directories(coverage-${MODULE_NAME}-${UNIT_NAME}-object PRIVATE
${OVERRIDE_INCLUDE_DIRS} ${ARGN}
)
endfunction(add_cfe_coverage_unit_include)
##################################################################
#
# FUNCTION: add_cfe_coverage_stubs
#
# Add stub library target for coverage testing. The stub library should
# contain a stub implementation for every function defined in the public
# API of the current module.
#
# NOTE: The first argument (MODULE_NAME) should match a name that was previously
# passed to the add_cfe_app() function - as this references that previous
# target to use the same compile definitions and include paths.
# (however this does also allow extra stub libs to be created that are not
# related to an existing module)
#
# The stub library target name follows the pattern:
# "coverage-${MODULE_NAME}-stubs"
#
# The calling script may call target_link_libraries() (or other target functions)
# to customize this target as needed.
#
# NOTE: To simplify linking and avoid possible problems there should ideally be a 1:1
# relationship between module source files and the stub files. Each stub file
# should provide the same set of functions that the fsw source file provides.
# (although its is not strictly required, it does help keep things more manageable).
#
function(add_cfe_coverage_stubs MODULE_NAME STUB_SRCS)
set(STUB_TARGET "coverage-${MODULE_NAME}-stubs")
add_library(${STUB_TARGET} STATIC
${STUB_SRCS} ${ARGN}
)
# If the MODULE_NAME refers to an existing CFE APP/LIB target, then
# use the same set of include dirs/definitions that is used from the app target
# This is not required; "extra" stub libs may be created that are not
# directly associated with an existing module.
if (TARGET ${MODULE_NAME})
target_include_directories(${STUB_TARGET} PUBLIC
$<TARGET_PROPERTY:${MODULE_NAME},INCLUDE_DIRECTORIES>
)
target_compile_definitions(${STUB_TARGET} PUBLIC
$<TARGET_PROPERTY:${MODULE_NAME},COMPILE_DEFINITIONS>
)
endif()
target_link_libraries(${STUB_TARGET} ut_assert)
endfunction(add_cfe_coverage_stubs)
##################################################################
#
# FUNCTION: cfe_exec_do_install
#
# Called to install a CFE core executable target to the staging area.
# Some architectures/OS's need special extra steps, and this
# function can be overridden in a custom cmake file for those platforms
#
function(cfe_exec_do_install CPU_NAME)
# By default just stage it to a directory of the same name
install(TARGETS core-${CPU_NAME} DESTINATION ${CPU_NAME})
endfunction(cfe_exec_do_install)
##################################################################
#
# FUNCTION: cfs_app_do_install
#
# Called to install a CFS application target to the staging area.
# Some architectures/OS's need special extra steps, and this
# function can be overridden in a custom cmake file for those platforms
#
function(cfs_app_do_install APP_NAME)
# override the default behavior of attaching a "lib" prefix
set_target_properties(${APP_NAME} PROPERTIES
PREFIX "" OUTPUT_NAME "${APP_NAME}")
# Create the install targets for this shared/modular app
foreach(TGT ${ARGN})
install(TARGETS ${APP_NAME} DESTINATION ${TGT}/${INSTALL_SUBDIR})
endforeach()
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 STATIC EXCLUDE_FROM_ALL ${${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
core_api
${DEP}
)
# Build this as part of the synthetic "check-headers" target
add_dependencies(check-headers ${MODULE_NAME}_headercheck)
endfunction(cfs_app_check_intf)
##################################################################
#
# FUNCTION: setup_platform_msgids
#
# This is intended to support cases where MsgIDs for all apps
# and modules are assigned in a single/unified header file
#
function(setup_platform_msgids)
set(PLATFORM_MSGID_HEADERFILE)
# In an EDS build, the msg IDs always come from EDS, there should not be a local msgids.h file
if (NOT CFE_EDS_ENABLED_BUILD)
# Check for the presence of a platform-specific msgid file
# This uses cfe_locate_implementation_file() as this returns whether or not it found one
cfe_locate_implementation_file(PLATFORM_MSGID_HEADERFILE "msgids.h"
PREFIX ${BUILD_CONFIG} cfs
SUBDIR config
)
# If a top level file was found, then create a wrapper around it called "cfs_msgids.h"
# Note that at this point it could be a list
if (PLATFORM_MSGID_HEADERFILE)
set(TEMP_WRAPPER_FILE_CONTENT)
foreach(SELECTED_FILE ${PLATFORM_MSGID_HEADERFILE})
file(TO_NATIVE_PATH "${SELECTED_FILE}" SRC_NATIVE_PATH)
list(APPEND TEMP_WRAPPER_FILE_CONTENT "#include \"${SRC_NATIVE_PATH}\"\n")
endforeach()
# Generate a header file
generate_c_headerfile("${CMAKE_BINARY_DIR}/inc/cfs_msgids.h" ${TEMP_WRAPPER_FILE_CONTENT})
unset(TEMP_WRAPPER_FILE_CONTENT)
# From here on use the wrapper file
set(PLATFORM_MSGID_HEADERFILE "cfs_msgids.h")
endif(PLATFORM_MSGID_HEADERFILE)
endif(NOT CFE_EDS_ENABLED_BUILD)
# Finally, export a CFGFILE_SRC variable for each of the deps
# This should make each respective "mission_build" create a wrapper
# that points directly at this global file, ignoring the default
if (PLATFORM_MSGID_HEADERFILE)
# Historically there has been a cfe_msgids.h defined at the core api level
# be sure to include this in the export list
set (OUTPUT_VAR_LIST
CORE_API_CFGFILE_SRC_cfe_msgids
)
# Slight inconsistency: for CFE core components, the cfe_ prefix is omitted in DEP_NAME
# To make this work without major impact, add it back in here
foreach(DEP_NAME ${MISSION_CORE_MODULES})
string(TOUPPER "${DEP_NAME}_CFGFILE_SRC" CFGSRC)
list(APPEND OUTPUT_VAR_LIST ${CFGSRC}_cfe_${DEP_NAME}_msgids)
endforeach(DEP_NAME ${MISSION_CORE_MODULES})
foreach(DEP_NAME ${MISSION_APPS})
string(TOUPPER "${DEP_NAME}_CFGFILE_SRC" CFGSRC)
list(APPEND OUTPUT_VAR_LIST ${CFGSRC}_${DEP_NAME}_msgids)
endforeach(DEP_NAME ${MISSION_APPS})
# This is the actual export to parent scope
foreach(VAR_NAME ${OUTPUT_VAR_LIST})
set(${VAR_NAME} ${PLATFORM_MSGID_HEADERFILE} PARENT_SCOPE)
endforeach(VAR_NAME ${OUTPUT_VAR_LIST})
endif (PLATFORM_MSGID_HEADERFILE)
endfunction(setup_platform_msgids)
##################################################################
#
# FUNCTION: prepare
#
# Called by the top-level CMakeLists.txt to set up prerequisites
#
function(prepare)
# "cfetables" is a top level target to build all table files
# all generated table files will be added as dependencies to this target
add_custom_target(cfetables)
# The table tool must provide an implementation to use with add_cfe_tables().
# this is determined by the CFS_TABLETOOL_SCRIPT_DIR that must be exported
# from the parent build.
#
include(${CFS_TABLETOOL_SCRIPT_DIR}/add_cfe_tables_impl.cmake)
# Choose the configuration file to use for OSAL on this system
set(OSAL_CONFIGURATION_FILE)
foreach(CONFIG ${BUILD_CONFIG_${TARGETSYSTEM}} ${OSAL_SYSTEM_OSCONFIG})
if (EXISTS "${MISSION_DEFS}/${CONFIG}_osconfig.cmake")
list(APPEND OSAL_CONFIGURATION_FILE "${MISSION_DEFS}/${CONFIG}_osconfig.cmake")
endif()
endforeach()
list(REVERSE OSAL_CONFIGURATION_FILE)
set(OSAL_CONFIGURATION_FILE ${OSAL_CONFIGURATION_FILE} PARENT_SCOPE)
# Allow sources to "ifdef" certain things if running on simulated hardware
# This should be used sparingly, typically to fake access to hardware that is not present
if (SIMULATION)
add_definitions(-DSIMULATION=${SIMULATION})
endif (SIMULATION)
# Check that PSPNAME is set properly for this arch
if (NOT CFE_SYSTEM_PSPNAME)
if (CMAKE_CROSSCOMPILING)
message(FATAL_ERROR "Cross-compile toolchain ${CMAKE_TOOLCHAIN_FILE} must define CFE_SYSTEM_PSPNAME")
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR
"${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
# Export the variables determined here up to the parent scope
SET(CFE_SYSTEM_PSPNAME "pc-linux" PARENT_SCOPE)
else ()
# Not cross compiling and host system is not recognized
message(FATAL_ERROR "Do not know how to set CFE_SYSTEM_PSPNAME on ${CMAKE_SYSTEM_NAME} system")
endif()
endif (NOT CFE_SYSTEM_PSPNAME)
# Truncate the global TGTSYS_LIST to be only the target architecture
set(TGTSYS_LIST ${TARGETSYSTEM} PARENT_SCOPE)
# set the BUILD_CONFIG variable from the cached data
set(BUILD_CONFIG ${BUILD_CONFIG_${TARGETSYSTEM}})
list(REMOVE_AT BUILD_CONFIG 0)
set(BUILD_CONFIG ${BUILD_CONFIG} PARENT_SCOPE)
# Check if the user has provided a platform-specific "msgids.h" file and set up a wrapper to it
setup_platform_msgids()
# Pull in any application-specific platform-scope configuration
# This may include user configuration files such as cfe_platform_cfg.h,
# or any other configuration/preparation that needs to happen at
# platform/arch scope.
foreach(DEP_NAME ${MISSION_DEPS})
include("${${DEP_NAME}_MISSION_DIR}/arch_build.cmake" OPTIONAL)
endforeach(DEP_NAME ${MISSION_DEPS})
endfunction(prepare)
##################################################################
#
# FUNCTION: process_arch
#
# Called by the top-level CMakeLists.txt to set up targets for this arch
# This is where the real work is done
#
function(process_arch SYSVAR)
# Check if something actually uses this arch;
# if this list is empty then do nothing, skip building osal/psp
if (NOT DEFINED TGTSYS_${SYSVAR})
return()
endif()
# Generate a list of targets that share this system architecture
set(INSTALL_TARGET_LIST ${TGTSYS_${SYSVAR}})
# 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.
set(CFE_PSP_EXPECTED_OSAL_BSPTYPE ${CFE_SYSTEM_PSPNAME})
# Include any specific compiler flags or config from the selected PSP
include(${psp_MISSION_DIR}/fsw/${CFE_SYSTEM_PSPNAME}/make/build_options.cmake)
if (NOT DEFINED OSAL_SYSTEM_BSPTYPE)
# Implicitly use the OSAL BSP that corresponds with the CFE PSP
set(OSAL_SYSTEM_BSPTYPE ${CFE_PSP_EXPECTED_OSAL_BSPTYPE})
elseif (NOT OSAL_SYSTEM_BSPTYPE STREQUAL CFE_PSP_EXPECTED_OSAL_BSPTYPE)
# Generate a warning about the BSPTYPE not being expected.
# Not calling this a fatal error because it could possibly be intended during development
message(WARNING "Mismatched PSP/BSP: ${CFE_SYSTEM_PSPNAME} implies ${CFE_PSP_EXPECTED_OSAL_BSPTYPE}, but ${OSAL_SYSTEM_BSPTYPE} is configured")
endif()
# The "inc" directory in the binary dir contains the generated wrappers, if any
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}")
# Create a documentation content file, with any system-specific doxygen info
# this is done here in arch_build where the CFE_SYSTEM_PSPNAME is known
file(WRITE "${MISSION_BINARY_DIR}/docs/tgtsystem-content-${SYSVAR}.doxyfile"
"INPUT += ${CMAKE_BINARY_DIR}/inc\n"
)
# The PSP and/or OSAL should have defined where to install the binaries.
# If not, just install them in /cf as a default (this can be modified
# by the packaging script if it is wrong for the target)
if (NOT INSTALL_SUBDIR)
set(INSTALL_SUBDIR cf)
endif (NOT INSTALL_SUBDIR)
# confirm that all dependencies have a MISSION_DIR defined that indicates the source.
# This should have been set up by the parent script. However, if any dir is not set,
# this may result in "add_subdirectory" of itself which causes a loop. This can happen
# if the variables/lists were modified unexpectedly.
foreach(DEP
${MISSION_CORE_INTERFACES}
${MISSION_CORE_MODULES}
${TGTSYS_${SYSVAR}_PSPMODULES}
${TGTSYS_${SYSVAR}_STATICAPPS}
${TGTSYS_${SYSVAR}_APPS})
if(NOT DEFINED ${DEP}_MISSION_DIR)
message(FATAL_ERROR "ERROR: core module ${DEP} has no MISSION_DIR defined")
endif()
endforeach()
# Add all core modules
# The osal is handled explicitly (above) since this has special extra config
foreach(DEP ${MISSION_CORE_INTERFACES} ${MISSION_CORE_MODULES})
if(NOT DEP STREQUAL "osal")
message(STATUS "Building Core Module: ${DEP}")
add_subdirectory("${${DEP}_MISSION_DIR}" ${DEP})
endif(NOT DEP STREQUAL "osal")
endforeach(DEP ${MISSION_CORE_MODULES})
# For the PSP it may define the FSW as either
# "psp-${CFE_SYSTEM_PSPNAME}" or just simply "psp"
if (NOT TARGET psp)
add_library(psp ALIAS psp-${CFE_SYSTEM_PSPNAME})
endif (NOT TARGET psp)
# Process each PSP module that is referenced on this system architecture (any cpu)
foreach(PSPMOD ${TGTSYS_${SYSVAR}_PSPMODULES})
message(STATUS "Building PSP Module: ${PSPMOD}")
add_subdirectory("${${PSPMOD}_MISSION_DIR}" psp/${PSPMOD})
endforeach()
# Process each app that is used on this system architecture
# First Pass: Assemble the list of apps that should be compiled
foreach(APP ${TGTSYS_${SYSVAR}_APPS} ${TGTSYS_${SYSVAR}_STATICAPPS})
set(TGTLIST_${APP})
endforeach()
foreach(TGTNAME ${TGTSYS_${SYSVAR}})
# Append to the app install list for this CPU
foreach(APP ${${TGTNAME}_APPLIST} ${${TGTNAME}_STATIC_APPLIST})
list(APPEND TGTLIST_${APP} ${TGTNAME})
endforeach(APP ${${TGTNAME}_APPLIST})
endforeach(TGTNAME ${TGTSYS_${SYSVAR}})
foreach(APP ${TGTSYS_${SYSVAR}_STATICAPPS})
set(APP_STATIC_TARGET_LIST ${TGTLIST_${APP}})
message(STATUS "Building Static App: ${APP} targets=${APP_STATIC_TARGET_LIST}")
add_subdirectory("${${APP}_MISSION_DIR}" apps/${APP})
endforeach()
unset(APP_STATIC_TARGET_LIST)
# Process each app that is used on this system architecture
foreach(APP ${TGTSYS_${SYSVAR}_APPS})
set(APP_DYNAMIC_TARGET_LIST ${TGTLIST_${APP}})
message(STATUS "Building Dynamic App: ${APP} targets=${APP_DYNAMIC_TARGET_LIST}")
add_subdirectory("${${APP}_MISSION_DIR}" apps/${APP})
endforeach()
unset(APP_DYNAMIC_TARGET_LIST)
# Process each target that shares this system architecture
# Second Pass: Build and link final target executable
foreach(TGTNAME ${TGTSYS_${SYSVAR}})
# Target to generate the actual executable file
add_subdirectory(cmake/target ${TGTNAME})
include(${MISSION_DEFS}/${TGTNAME}/install_custom.cmake OPTIONAL)
foreach(INSTFILE ${${TGTNAME}_FILELIST})
if(EXISTS ${MISSION_DEFS}/${TGTNAME}/${INSTFILE})
set(FILESRC ${MISSION_DEFS}/${TGTNAME}/${INSTFILE})
elseif(EXISTS ${MISSION_DEFS}/${TGTNAME}_${INSTFILE})
set(FILESRC ${MISSION_DEFS}/${TGTNAME}_${INSTFILE})
elseif(EXISTS ${MISSION_DEFS}/${INSTFILE})
set(FILESRC ${MISSION_DEFS}/${INSTFILE})
else()
set(FILESRC)
endif()
if (FILESRC)
# In case the file is a symlink, follow it to get to the actual file
get_filename_component(FILESRC "${FILESRC}" REALPATH)
message(STATUS "NOTE: Selected ${FILESRC} as source for ${INSTFILE} on ${TGTNAME}")
install(FILES ${FILESRC} DESTINATION ${TGTNAME}/${INSTALL_SUBDIR} RENAME ${INSTFILE})
else(FILESRC)
message("WARNING: Install file ${INSTFILE} for ${TGTNAME} not found")
endif (FILESRC)
endforeach(INSTFILE ${${TGTNAME}_FILELIST})
endforeach(TGTNAME ${TGTSYS_${SYSVAR}})
endfunction(process_arch SYSVAR)