forked from nasa/fprime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPrime.cmake
232 lines (214 loc) · 10 KB
/
FPrime.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
####
# FPrime.cmake:
#
# This file is the entry point for building fprime projects, libraries. It does not setup F prime as a project, but
# rather allows the users to build against fprime, fprime libraries while taking advantage of fprime's autocoding
# support. This file includes the cmake build system setup for building like fprime.
####
include_guard()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
include(utilities)
include(options)
include(sanitizers) # Enable sanitizers if they are requested
include(required)
# Add project root's cmake folder to module path
if (IS_DIRECTORY "${FPRIME_PROJECT_ROOT}/cmake")
list(APPEND CMAKE_MODULE_PATH "${FPRIME_PROJECT_ROOT}/cmake")
endif()
# for adding libraries from the _fprime_packages directory
if (IS_DIRECTORY "${FPRIME_PROJECT_ROOT}/_fprime_packages")
if (EXISTS "${FPRIME_PROJECT_ROOT}/_fprime_packages/packages.cmake")
include("${FPRIME_PROJECT_ROOT}/_fprime_packages/packages.cmake")
message(STATUS "[FPRIME] Including libraries from ${FPRIME_PROJECT_ROOT}/_fprime_packages")
else()
message(WARNING "[FPRIME] ${FPRIME_PROJECT_ROOT}/_fprime_packages/packages.cmake does not exist. Skipping.")
endif()
endif()
# Setup fprime library locations
list(REMOVE_DUPLICATES FPRIME_LIBRARY_LOCATIONS)
set(FPRIME_BUILD_LOCATIONS "${FPRIME_FRAMEWORK_PATH}" ${FPRIME_LIBRARY_LOCATIONS} "${FPRIME_PROJECT_ROOT}")
list(REMOVE_DUPLICATES FPRIME_BUILD_LOCATIONS)
# Message describing the fprime setup
message(STATUS "[FPRIME] Module locations: ${FPRIME_BUILD_LOCATIONS}")
message(STATUS "[FPRIME] Configuration module: ${FPRIME_CONFIG_DIR}")
message(STATUS "[FPRIME] Installation directory: ${CMAKE_INSTALL_PREFIX}")
include(platform/platform) # Now that module locations are known, load platform settings
# Module setup functions, attaches targets to modules, etc.
include(module)
# Support for autocoder implementations
include(autocoder/autocoder)
# Support for build target registration
include(target/target)
# Load domain-specific CMake functions
include(API)
# Sub-build support
include(sub-build/sub-build)
# C and C++ settings for building the framework
include(settings)
####
# Function `fprime_setup_global_includes`:
#
# Adds basic include directories that make fprime work. This ensures that configuration, framework, and project all
# function as expected. This will also include the internal build-cache directories.
####
function(fprime_setup_global_includes)
# Setup the global include directories that exist outside of the build cache
include_directories("${FPRIME_FRAMEWORK_PATH}")
include_directories("${FPRIME_CONFIG_DIR}")
include_directories("${FPRIME_PROJECT_ROOT}")
# Setup the include directories that exist within the build-cache
include_directories("${CMAKE_BINARY_DIR}")
include_directories("${CMAKE_BINARY_DIR}/F-Prime")
include_directories("${CMAKE_BINARY_DIR}/config")
endfunction(fprime_setup_global_includes)
####
# Function `fprime_detect_libraries`:
#
# This function detects libraries using the FPRIME_LIBRARY_LOCATIONS variable. Fore each library path, the following is
# done:
# 1. Detect a manifest file from in-order: `library.cmake`, and then `<library name>.cmake`
# 2. Add the library's top-level cmake directory to the CMAKE_MODULE_PATH
# 3. Add the library root as an include directory
# 4. Add option() to disable library UTs
####
macro(fprime_detect_libraries)
foreach (LIBRARY_DIRECTORY IN LISTS FPRIME_LIBRARY_LOCATIONS)
get_filename_component(LIBRARY_NAME "${LIBRARY_DIRECTORY}" NAME)
get_fprime_library_option_string(LIBRARY_OPTION "${LIBRARY_NAME}")
# Detect manifest file:
# 1. library.cmake (preferred)
# 2. <library>.cmake (old standard)
if (EXISTS "${LIBRARY_DIRECTORY}/library.cmake")
set(MANIFEST_FILE "${LIBRARY_DIRECTORY}/library.cmake")
elseif (EXISTS "${LIBRARY_DIRECTORY}/${LIBRARY_NAME}.cmake")
set(MANIFEST_FILE "${LIBRARY_DIRECTORY}/${LIBRARY_NAME}.cmake")
else()
message(WARNING "[LIBRARY] ${LIBRARY_DIRECTORY} does not define library.cmake nor ${LIBRARY_NAME}.cmake. Skipping.")
continue()
endif()
message(STATUS "[LIBRARY] Including library ${LIBRARY_NAME} at ${LIBRARY_DIRECTORY}")
if (CMAKE_DEBUG_OUTPUT)
message(STATUS "[LIBRARY] ${LIBRARY_NAME} using manifest ${MANIFEST_FILE}")
endif()
append_list_property("${MANIFEST_FILE}" GLOBAL PROPERTY FPRIME_LIBRARY_MANIFESTS)
# Check to see if the cmake directory exists and add it
if (IS_DIRECTORY "${LIBRARY_DIRECTORY}/cmake")
list(APPEND CMAKE_MODULE_PATH "${LIBRARY_DIRECTORY}/cmake")
endif()
include_directories("${LIBRARY_DIRECTORY}")
option(FPRIME_ENABLE_${LIBRARY_OPTION}_UTS "Enable UT generation for ${LIBRARY_NAME}" ON)
endforeach()
endmacro(fprime_detect_libraries)
####
# Function `fprime_setup_standard_targets`:
#
# Registers the targets required for a standard fprime build. This will be changed when FPRIME_SUB_BUILD_TARGETS.
####
macro(fprime_setup_standard_targets)
# Prevent registration of standard targets when specific targets are supplied
# This is done for efficiency to not load all the below files
if (NOT DEFINED FPRIME_SUB_BUILD_TARGETS)
# FPP locations must come at the front of the list, then build
register_fprime_target(target/build)
register_fprime_build_autocoder(autocoder/fpp OFF)
register_fprime_build_autocoder(autocoder/ai_xml OFF)
register_fprime_build_autocoder(autocoder/packets OFF)
register_fprime_target(target/version)
register_fprime_target(target/install)
register_fprime_ut_target(target/ut)
if (FPRIME_ENABLE_UTIL_TARGETS)
register_fprime_target(target/refresh_cache)
register_fprime_ut_target(target/check)
endif()
endif()
endmacro(fprime_setup_standard_targets)
####
# Function `fprime_setup_override_targets`:
#
# Override the targets that are registered by the default build with those supplied in FPRIME_SUB_BUILD_TARGETS. If
# FPRIME_SUB_BUILD_TARGETS is defined, nothing happens.
#####
macro(fprime_setup_override_targets)
# Required to prevent overriding when not used
if (FPRIME_SUB_BUILD_TARGETS)
foreach (OVERRIDE_TARGET IN LISTS FPRIME_SUB_BUILD_TARGETS)
register_fprime_target("${OVERRIDE_TARGET}")
endforeach ()
elseif(CMAKE_DEBUG_OUTPUT)
message(STATUS "FPRIME_SUB_BUILD_TARGETS not defined, skipping.")
endif()
endmacro(fprime_setup_override_targets)
macro(fprime_initialize_build_system)
cmake_minimum_required(VERSION 3.16)
fprime_setup_global_includes()
fprime_detect_libraries()
fprime_setup_standard_targets()
fprime_setup_override_targets()
set_property(GLOBAL PROPERTY FPRIME_BUILD_SYSTEM_LOADED ON)
# Perform necessary sub-builds
run_sub_build(info-cache target/fpp_locs target/fpp_depend)
endmacro(fprime_initialize_build_system)
####
# Function `fprime_setup_included_code`:
#
# Sets up the code/build for fprime and libraries. Call after all project specific targets and autocoders are set up and
# registered.
####
function(fprime_setup_included_code)
# Must be done before code is registered but after custom target registration
setup_global_targets()
# For BUILD_TESTING builds then set up libraries that support testing
if (BUILD_TESTING AND NOT DEFINED FPRIME_SUB_BUILD_TARGETS)
if (NOT EXISTS "${FPRIME_FRAMEWORK_PATH}/googletest/CMakeLists.txt")
message(FATAL_ERROR "googletest submodule not initialized or corrupted. Please run `git submodule update --init --recursive`.")
endif()
add_subdirectory("${FPRIME_FRAMEWORK_PATH}/googletest/" "${CMAKE_BINARY_DIR}/F-Prime/googletest")
endif()
if (BUILD_TESTING)
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()
message(STATUS "[LIBRARY] Adding modules from F´ framework")
# Faux libraries used as interfaces to non-autocoded fpp items
add_library(Fpp INTERFACE)
# Specific configuration handling
set(FPRIME_CURRENT_MODULE config)
add_subdirectory("${FPRIME_CONFIG_DIR}" "${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)
message(STATUS "[LIBRARY] Adding modules from F´ framework - DONE")
get_property(FPRIME_LIBRARY_MANIFESTS GLOBAL PROPERTY FPRIME_LIBRARY_MANIFESTS)
foreach (LIBRARY_MANIFEST IN LISTS FPRIME_LIBRARY_MANIFESTS)
set(__FPRIME_NO_UT_GEN__ OFF)
get_filename_component(LIBRARY_DIRECTORY "${LIBRARY_MANIFEST}" DIRECTORY)
get_filename_component(LIBRARY_NAME "${LIBRARY_DIRECTORY}" NAME)
get_fprime_library_option_string(LIBRARY_OPTION "${LIBRARY_NAME}")
if (NOT FPRIME_ENABLE_${LIBRARY_OPTION}_UTS)
set(__FPRIME_NO_UT_GEN__ ON)
endif()
message(STATUS "[LIBRARY] Adding modules from ${LIBRARY_NAME}")
include("${LIBRARY_MANIFEST}")
message(STATUS "[LIBRARY] Adding modules from ${LIBRARY_NAME} - DONE")
endforeach()
# Always enable UTs for a project
set(__FPRIME_NO_UT_GEN__ OFF)
endfunction(fprime_setup_included_code)
# Load the build system exactly one time
get_property(FPRIME_BUILD_SYSTEM_LOADED GLOBAL PROPERTY FPRIME_BUILD_SYSTEM_LOADED)
if (NOT FPRIME_BUILD_SYSTEM_LOADED)
fprime_initialize_build_system()
endif ()