Skip to content

Commit 21faffa

Browse files
authored
CMake documentation refactor (#3981)
* CMake documentation refactor * sp * Update cmake-implementations.md
1 parent dfaf496 commit 21faffa

9 files changed

Lines changed: 93 additions & 370 deletions

File tree

cmake/docs/sdd.md

Lines changed: 52 additions & 194 deletions
Large diffs are not rendered by default.

docs/user-manual/build-system/01-cmake-intro.md

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,20 @@
22

33
F´ leverages CMake as its underlying build system, adding an [API layer](../../reference/api/cmake/API.md) for ease of use.
44

5-
Since this F´ CMake system is designed to follow CMake norms, certain caveats must be understood before beginning to use CMake. These are described below:
6-
7-
1. CMake should not be used in tandem with the original make system. If it is needed to switch
8-
between make systems, perform a `git clean -xdf` command or otherwise remove **all** generated files.
9-
2. CMake in-source builds are dangerous. Use CMake out-of-source builds.
10-
11-
125
Installation guides for CMake can be found here: [https://cmake.org/install/](https://cmake.org/install/).
136

147
A Basic CMake tutorial can be found here: [https://cmake.org/cmake/help/latest/guide/tutorial/index.html](https://cmake.org/cmake/help/latest/guide/tutorial/index.html).
158
Although fprime tries to simplify CMake usage for fprime-specific tasks, an understanding of basic CMake is useful.
169

1710
## Getting Started with CMake and F´
1811

19-
CMake as a system auto-generates OS-specific make files for building F´. Once these file are generated, standard make tools can be run to perform the compiling, assembling, linking, etc. In other words, CMake is a high-level build system that defers low-level build systems to build. It generates the inputs to these low-level systems in a straightforward way.
12+
CMake as a system auto-generates OS-specific build files for building F´. Once these files are generated, standard build tools can be run to perform the compiling, assembling, linking, etc. In other words, CMake is a high-level build system that defers low-level build systems to build. It generates the inputs to these low-level systems in a straightforward way.
2013

21-
fprime sets up CMake in such a way that adding a module (component, port, deployment) is easy and automatically takes
14+
sets up CMake in such a way that adding a module (component, port, deployment) is easy and automatically takes
2215
advantage of the autocoding capabilities of fprime. To add new modules to the CMake system, users need to perform the following steps:
2316

2417
1. Define a `CMakeLists.txt` file to define the module's source files and dependencies
25-
2. Ensure that `register_fprime_module` or `register_fprime_executable` is called in that `CMakeLists.txt`
18+
2. Ensure that `register_fprime_module` or `register_fprime_deployment` is called in that `CMakeLists.txt`
2619
3. Make sure this new directory defining the `CMakeLists.txt` is added to the deployment `CMakeLists.txt` using
2720
`add_fprime_subdirectory`.
2821

@@ -33,22 +26,14 @@ steps can be found in [API](./cmake-api.md). This document will explain the usag
3326

3427
The CMakeList.txt file defines the steps needed to build **something** in CMake. In fprime, we use this file to define the source, autocoder, and module dependencies for modules in fprime. A `register_` function is called to tie into the fprime autocoder environment. This keeps fprime modules simple, although all of CMake's power can be used when needed.
3528

36-
Users need only set the `SOURCE_FILES` variable to a list of autocoder and code sources and then call
37-
`register_fprime_module` to setup a module for fprime (Port/Component). Deployments are done similarly, but since these
38-
`CMakeLists.txt` files are the entry point to a build, more setup is needed. Deployments should also call
39-
`register_fprime_executable` as a binary output is desired. `add_fprime_subdirectory` is also used in deployments to
40-
link to all the other modules they use.
29+
Users need only set the `AUTOCODER_INPUTS` and `SOURCES` directives to a list of autocoder and code sources as part of the
30+
`register_fprime_module` call to setup a module for fprime (Port/Component). Deployments are done similarly but use the
31+
`register_fprime_deployment` call instead.
4132

4233
`add_fprime_subdirectory`, `register_fprime_module`, `register_fprime_executable` docs are here: [API](./cmake-api.md).
4334

44-
A template module `CMakeLists.txt` is documented: [module-CMakeLists.txt-template.md](../../../cmake/module-CMakeLists.txt.template)
45-
Remember it should be renamed to `CMakeLists.txt` in your module's folder.
46-
47-
A template deployment `CMakeLists.txt` is documented: [deployment-CMakeLists.txt-template.md](../../../cmake/deployment-CMakeLists.txt.template).
48-
Remember it should be renamed to `CMakeLists.txt` in your deployments folder.
4935

50-
When building a module, ensure it at least calls `register_fprime_module`. Deployments may call
51-
`register_fprime_executable` in the deployment `CMakeLists.txt` or in any child (usually Top/CMakeLists.txt).
36+
When defining a module, ensure it at least calls `register_fprime_module`, or `register_fprime_deployment`.
5237

5338
When building a module, remember to add it to the deployment by adding a line `add_fprime_subdirectory(path/module/dir)`
5439
to the deployment `CMakeLists.txt`.

docs/user-manual/build-system/cmake-advanced.md

Lines changed: 0 additions & 102 deletions
This file was deleted.

docs/user-manual/build-system/cmake-customization.md

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,25 @@ cannot be found herein.
1111
## Build F Prime Utilities
1212

1313
Adding a utility executable that depends on F prime code is easy. Just perform a standard call to
14-
`register_fprime_executable`. Care should be taken to set the variable `EXECUTABLE_NAME` before
15-
making this call in order to set the utility's name. This executable will then be output as part
16-
of the deployment's build. A separate tools deployment may be used to build only utilities.
14+
`register_fprime_executable`. Care should be taken to set the executable name as the first argument to that
15+
call. This executable will then be output as part of the deployment's build and may be built directly by name.
16+
A separate tools deployment may be used to build only utilities.
1717

1818
See: [API](cmake-api.md)
1919

2020
## Custom Build-System Commands (Make Targets)
2121

2222
Custom build targets that need to be built against modules and global targets can be generated
23-
using the hook pattern. This pattern involves creating a file with two functions - `add_global_target` and `add_module_target`. These functions are called to add targets to the top level and each module respectively.
23+
using the hook pattern. This pattern involves creating a file with three functions - `<target>_add_global_target`, `<target>_add_module_target`, and `<target>_add_deployment_target`. These functions are called to add targets to the top level and each module respectively.
2424
Then this file is registered with `register_fprime_target`.
2525

26-
In the two add functions, the user is expected to call the `add_custom_target` CMake command in order to compose the target itself. **Note:** the user may simply call this function directly to
27-
add targets that don't have both per-module and global steps.
26+
These functions can have any code the target needs, but typically uses `add_custom_target` to register the actual target.
2827

2928
See:
3029
- [add_custom_target](https://cmake.org/cmake/help/latest/command/add_custom_target.html) to view
3130
information on CMake targets.
3231
- [API](cmake-api.md) for the syntax of the register call
3332
- [Targets](cmake-targets.md) for information on the built-in targets
34-
- [F´ standard targets](https://github.com/nasa/fprime/tree/devel/cmake/target) as an example of adding targets
35-
36-
**Example (Raw Global Target):**
37-
38-
```
39-
add_custom_target(
40-
dict
41-
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/dict/serializable ${CMAKE_SOURCE_DIR}/py_dict/serializable
42-
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_SOURCE_DIR}/py_dict/serializable/__init__.py
43-
)
44-
```
45-
**Running Example:**
46-
47-
```
48-
cmake ../Ref
49-
make dict
50-
```
5133

5234
## Custom External Libraries With Other Build Systems
5335

@@ -60,7 +42,5 @@ dependency, and `add_custom_command` is used when the system needs access to the
6042
Alternatively, `ExternalProject_Add` can be used if the external library requires download,
6143
version control, and building steps.
6244

63-
**Supporting Documentation:**
64-
1. [https://cmake.org/cmake/help/latest/command/add_custom_target.html](https://cmake.org/cmake/help/latest/command/add_custom_target.html)
65-
2. [https://cmake.org/cmake/help/latest/command/add_custom_command.html](https://cmake.org/cmake/help/latest/command/add_custom_command.html)
66-
3. [https://cmake.org/cmake/help/latest/module/ExternalProject.html](https://cmake.org/cmake/help/latest/module/ExternalProject.html)
45+
For a guide on integrating with another build system see:
46+
[How To: Integrate External Libraries](../../how-to/integrate-external-libraries.md).

docs/user-manual/build-system/package-implementations.md renamed to docs/user-manual/build-system/cmake-implementations.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
1-
# Package Implementations
1+
# CMake Implementations
22

33
Certain parts of F´ have different implementations that a project may choose from. The canonical example of this is a file system implementation. Projects may wish to use the stubbed implementation of the file system, the platform supplied standard implementation, or something project-specific like a flash chip or SD card.
44

55
These packages must be fully specified. Thus, every platform must specify a specific implementation for every package. These specific implementations may be overridden for a specific executable deployment or unit test.
66

77
## Requiring an Implementation
88

9-
Modules that require an implementation should call the CMake API function `require_fprime_implementation()` to declare a requirement on a specific implementation. For example, the Os module `require_fprime_implementation(Os/Task)` declares that some implementation of `Os/Task` is required.
9+
Modules that require an implementation should use the directive `REQUIRES_IMPLEMENTATIONS` in the `register_fprime_module` call.
1010

1111
> [!NOTE]
12-
> Only `Os` requires an implementation of `Os/Task` as users of the `Os` package get the implementation through `Os` and should not specify it directly.
12+
> `REQUIRES_IMPLEMENTATIONS` is only needed for modules that have a direct dependency on the implementation, not on their dependents.
1313
1414
## Choosing an Implementation
1515

1616
Platform developers *must* specify an implementation of every package used in the system. Failing to do so means that a given functionality is undefined and impossible to link. Stub implementations are provided in the case that a platform does not support a given package's functionality.
1717

18-
Choosing an implementation is done with a series of `choose_fprime_implementation` calls. One for each required implementation defined in the system. These calls are put in a platform CMake file.
18+
Choosing an implementation is done with the `CHOOSES_IMPLEMENTATIONS` directive available to `register_fprime_config`. Platform developers should choose implementations as part of the platform definition.
19+
20+
https://github.com/nasa/fprime/blob/dfaf496263bdfff04461179eb99fb3f906a10009/cmake/platform/Linux.cmake#L15-L17
1921

2022
## Overriding an Implementation Choice
2123

22-
Some executables, unit tests, and deployments may wish to use a different implementation than that specified by the platform. This can be done by a `choose_fprime_implementation` call in the deployment, executable, or unit test's module. For example, a unit test may wish to choose `Os_File_Stub` as an implementation of `Os_File` to disable platform file system support for the given unit test.
24+
Executables, unit tests, and deployments may wish to use a different implementation than that specified by the platform. This can be done by using `CHOOSES_IMPLEMENTATIONS` directive call in the deployment, executable, or unit test's registration. For example, a unit test may wish to choose `Os_File_Stub` as an implementation of `Os_File` to disable platform file system support for the given unit test:
25+
26+
```
27+
register_fprime_ut(
28+
...
29+
CHOOSES_IMPLEMENTATIONS
30+
Os_File_Stub
31+
)
32+
```
2333

2434
> [!NOTE]
2535
> A CMake target with the name of the chosen implementor *must* be defined somewhere in F´, an F´ library used by the project, or by the project itself.
2636
2737
## Defining an Implementation
2838

29-
To define an implementation, developers should declare an F´ module (using `register_fprime_module`) that implements the needed interface of the package. Then call `register_fprime_implementation` to specify this module is an implementation.
39+
To define an implementation, developers should declare an F´ module (using `register_fprime_module`) that implements the needed interface of the package and supply the `IMPLEMENTS` directive to that call.
3040

3141
## Conclusion
3242

33-
F´ provides for various implementations for certain packages needed by the framework. See `cmake/API` and `Os` for API descriptions and Os implementations.
43+
F´ provides for various implementations for certain packages needed by the framework.
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# F´ and CMake Platforms
22

33
Users can create platform-specific build files for the purposes of tailoring fprime
4-
for given platform targets. Any CMake toolchain file should work, but it will require a platform file created here to add target-specific configuration using the name "${CMAKE_SYSTEM_NAME}.cmake".
4+
for given platform targets. Any CMake toolchain file should work, but it will require a platform file created here to add target-specific configuration using the name "${FPRIME_PLATFORM}.cmake".
55

6-
At minimum, this file can be blank, but more commonly there are included paths for "StandardTypes.hpp" to support.
7-
Build flags and other includes can be added in to support different compile-time options. In addition, these files can define CMake option flags specific to the build.
6+
Platforms should register a configuration module using `register_fprime_config` that sets the `AUTOCODER_INPUTS`, `HEADERS` and
7+
`CHOOSES_IMPLEMENTATIONS` directives.
88

9-
In order to create a new platform from scratch, the user can copy "platform.cmake.template" and fill it out to generate the new platform file. It will guide the user through the setup of this piece.
10-
11-
To understand the platform template: [Platform Template File](https://github.com/nasa/fprime/blob/docs/auto-documentation/docs/UsersGuide/api/cmake/platform/platform-template.md)
12-
To use the template: [fprime Platform Template](https://github.com/nasa/fprime/blob/devel/cmake/platform/platform.cmake.template)
9+
`AUTOCODER_INPUTS`: must include one .fpp file defining the platform's [platform types](../../reference/numerical-types.md#platform-configured-types)
10+
`HEADERS`: lists the `PlatformTypes.h` header defining `PlatformPointerCastType`
11+
`CHOOSES_IMPLEMENTATIONS`: lists all implementations chosen for the current platform. See: [CMake Implementations](./cmake-implementations.md).

docs/user-manual/build-system/cmake-targets.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ and have it available to the build system.
88

99
Targets are applied both at the global scope and per-module scope. Thus each target can provide a set of build targets (one per registered module) and a global build target. For example, a counting target might provide a `count` global target to count all files, and a `<MODULE>_count` to count the files of a given module.
1010

11-
For projects generating GNU make files, these targets can be executed with the `make <target>` and
12-
`make <MODULE>_<target>` commands. i.e. `make Svc_CmdDispatcher_coverage`.
13-
1411
## Built-In Targets
1512

1613
The CMake system supplies several targets that are useful for all projects and thus are included

0 commit comments

Comments
 (0)