Skip to content

Commit a628f3f

Browse files
committed
Document cmake-init-include
1 parent dc55b7b commit a628f3f

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

docs/reference/target-declaration.mdx

+51-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ A target specification may have optional parameters, the names and values of whi
2828
- [**build-type**](#build-type): One of Debug (the default), Release, RelWithDebInfo and MinSizeRel.
2929
- [**cargo-dependencies**](#cargo-dependencies): (Rust only) list of dependencies to include in the generated Cargo.toml file.
3030
- [**cargo-features**](#cargo-features): (Rust only) List of string names of features to include.
31-
- [**cmake-include**](#cmake-include): List of paths to cmake files to guide compilation.
31+
- [**cmake-include**](#cmake-include): List of paths to cmake files to be included in the generated CMakeLists.txt.
32+
- [**cmake-init-include**](#cmake-init-include): List of paths to cmake files to be included at the beginning of the generated CMakeLists.txt.
3233
- [**compiler**](#compiler): A string giving the name of the target language compiler to use.
3334
- [**docker**](#docker): A boolean to generate a Dockerfile.
3435
- [**external-runtime-path**](#external-runtime-path): Specify a pre-compiled external runtime library located to link to instead of the default.
@@ -57,6 +58,7 @@ c={
5758
build: <string>,
5859
build-type: <Debug, Release, RelWithDebInfo, or MinSizeRel>,
5960
cmake-include: <string or list of strings>,
61+
cmake-init-include: <string or list of strings>,
6062
compiler: <string>,
6163
compiler-flags: <string or list of strings>,
6264
docker: <true or false>,
@@ -74,6 +76,7 @@ cpp={
7476
`target Cpp {
7577
build-type: <Debug, Release, RelWithDebInfo, or MinSizeRel>,
7678
cmake-include: <string or list of strings>,
79+
cmake-init-include: <string or list of strings>,
7780
compiler: <string>,
7881
external-runtime-path: <string>,
7982
export-dependency-graph <true or false>,
@@ -289,7 +292,7 @@ target Cpp {
289292
};
290293
```
291294

292-
This will optionally append additional custom CMake instructions to the generated `CMakeLists.txt`, drawing these instructions from the specified text files (e.g, `foo.txt`). The specified files are resolved using the same file search algorithm as used for the [files](#files) target parameter. Those files will be copied into the `src-gen` directory that contains the generated sources. This is done to make the generated code more portable<span class="lf-c"> (a feature that is useful in [federated execution](../writing-reactors/distributed-execution.mdx))</span>.
295+
This will optionally include custom CMake files at the bottom of the generated `CMakeLists.txt`. The specified files are resolved using the same file search algorithm as used for the [files](#files) target parameter. Those files will be copied into the `src-gen` directory that contains the generated sources. This is done to make the generated code more portable<span class="lf-c"> (a feature that is useful in [federated execution](../writing-reactors/distributed-execution.mdx))</span>.
293296

294297
The cmake-include target property can be used, for example, to add dependencies on various packages (e.g., by using the [`find_package`](https://cmake.org/cmake/help/latest/command/find_package.html) and [`target_link_libraries`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html) commands).
295298

@@ -323,6 +326,52 @@ See [`AsyncCallback.lf`](https://github.com/lf-lang/lingua-franca/blob/master/te
323326

324327
</ShowOnly>
325328

329+
330+
<ShowOnly c cpp>
331+
## cmake-init-include
332+
333+
```lf-c
334+
target C {
335+
cmake-init-include: ["relative/path/to/foo.txt", "relative/path/to/bar.txt", ...]
336+
};
337+
```
338+
339+
```lf-cpp
340+
target Cpp {
341+
cmake-init-include: ["relative/path/to/foo.txt", "relative/path/to/bar.txt", ...]
342+
};
343+
```
344+
345+
This will optionally include custom CMake files at the beginning of the generated `CMakeLists.txt`. The specified files are resolved using the same file search algorithm as used for the [files](#files) target parameter. Those files will be copied into the `src-gen` directory that contains the generated sources. This is done to make the generated code more portable<span class="lf-c"> (a feature that is useful in [federated execution](../writing-reactors/distributed-execution.mdx))</span>.
346+
347+
The cmake-init-include target property is needed if you would like to change the toolchain file of CMake to enable cross-compilation. This has to be done before the `project()` statement found at the very beginning of a `CMakeLists.txt`
348+
349+
For example, the following CMake file sets up cross compilation targeting an Arm-based microcontroller.
350+
```cmake
351+
set(CMAKE_SYSTEM_NAME Generic)
352+
set(CMAKE_SYSTEM_PROCESSOR arm)
353+
set(TOOLCHAIN_PREFIX arm-none-eabi-)
354+
set(FLAGS
355+
"-fdata-sections -ffunction-sections \
356+
--specs=nano.specs -Wl,--gc-sections")
357+
set(CPP_FLAGS
358+
"-fno-rtti -fno-exceptions \
359+
-fno-threadsafe-statics")
360+
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS})
361+
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
362+
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS})
363+
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
364+
set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size)
365+
366+
set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf")
367+
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
368+
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf")
369+
370+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
371+
```
372+
373+
</ShowOnly>
374+
326375
## compiler
327376

328377
<ShowIfs>

0 commit comments

Comments
 (0)