C and C++ Code Deployment - Documentation

This section describes how to use code deployment to control the organization of generated C and C++ code in CATIA Software Producer. It helps understand which deployment options are available, when to use them, and how to adapt the generated file layout to your project conventions.

In many cases, the built-in deployments are sufficient and can be used directly. When those built-in configurations do not match the expected directory structure, naming rules, or generated build resources, you can also define your own code deployment to fit your needs.

This page discusses:

What Is Code Deployment?

Code deployment controls how your generated C/C++ code is organized:

  • Where files go: Public headers in include/, internal headers in internal/, sources in src/
  • How files are named: Based on UML element names with configurable patterns and extensions
  • Build integration: Automatic CMakeLists.txt or Makefile generation

Configure Your Code Deployment and Generate Code

In the Software Producer Configuration Diagram, select a built-in deployment or create a custom one.

Select a Deployment Configuration

Built-in Deployment Description
Flat All files in single directory, no subdirectory structure (default)
FlatQualified Flat structure with qualified (package-prefixed) file names
Hierarchical Organized include/, internal/, and src/ layout following the package hierarchy
CMake (planned, not yet implemented) Hierarchical layout with a generated CMakeLists.txt template
Makefile (planned, not yet implemented) Hierarchical layout with a generated Makefile

For the detailed configuration of each built-in deployment, refer to the built-in deployments reference document.

Note:

Note: The CMake and Makefile built-in deployments are not yet available. Until they are delivered, use the Hierarchical deployment and attach a custom build file via a Text Template if needed.

Note:

Tip: To apply a deployment to a generation configuration, drag the deployment element from the diagram (or from the containment tree) onto the target generation configuration.

Creating a Custom Deployment

To create your own deployment configuration:

  1. Open the Software Producer Configuration Diagram.
  2. From the diagram palette, expand the Code Deployment category and drag C and C++ Code Deployment onto the diagram.
  3. Give the new deployment a meaningful name and edit its properties to match your conventions:
    • Public, internal, and source directories
    • File extensions for C and C++ headers and sources
    • File path and file name patterns (advanced)
  4. To add a build file or any other companion file (such as a CMakeLists.txt, Makefile, or README):
    1. Drag a Text Template from the palette onto the diagram to create a new template element.
    2. Drag that Text Template onto your C and C++ Code Deployment to attach it as an additional resource of the deployment.
  5. To choose the output filename of an attached resource, select it on the diagram, open its Specification window, and edit the File Path property (for example, CMakeLists.txt, or <lib.dir>README.md to place the file in the library directory; the path uses the <variable> syntax of the Path Pattern Properties).
  6. The Scope property says how many times the resource is generated: Project (once for the whole generation, the default), Library (once per <<ModelLibrary>>) or Package (once per package that owns generated code, inside a library or not). A Library or Package resource needs a discriminating variable in its File Path (<lib.dir>CMakeLists.txt, <package.lib.path>/CMakeLists.txt), otherwise every render lands on the same file and the generator reports ESP_RES_001.
  7. Edit the Body of the Text Template to define the content of the generated file. Templates support variable substitution and file iteration macros (see Template Variables).
  8. To use the new deployment in a generation configuration, drag and drop the C and C++ Code Deployment element onto the target generation configuration on the diagram. This sets it as the deployment used by that configuration.

Example: Custom Embedded Deployment

A deployment named EmbeddedDeployment configured with:

  • Public area: api
  • Internal area: private
  • Source area: source
  • C header extension: .h
  • C source extension: .c
  • One attached Text Template with file path Makefile

Generate Code

Run code generation as usual. As a result, files are organized according to your deployment configuration.

Understanding File Placement

Public Versus Internal Headers

The file placement is determined by UML visibility:

UML Visibility Header Location Include Path
public <area.public>/package/path/ "package/path/ClassName.hpp"
private, protected, package <area.internal>/package/path/ "package/path/ClassName.hpp"

Source Files

All implementation files (.cpp, .c) go to the source area regardless of visibility: Default location: src/package/path/ClassName.cpp

ModelLibrary Context

The library root is identified by applying the standard UML <<ModelLibrary>> stereotype to a package. Unlike the deployment elements created from the palette, <<ModelLibrary>> is a native UML stereotype that you apply directly to an existing package: in the Containment Tree, right-click the target package, choose Stereotype…, and select ModelLibrary. The chosen package then becomes the stable reference point used by the deployment to compute public, internal, and source paths.

Example structure:

<<ModelLibrary>>
MyLibrary
├── PublicAPI (package)
│   └── PublicClass (public visibility)
└── Internal (package)
    └── InternalClass (private visibility)

Paths are relative to the <<ModelLibrary>> root:

MyLibrary/                  ← ModelLibrary root
├── include/               ← publicArea (default)
│   └── API/
│       └── PublicClass.hpp
├── internal/              ← internalArea (default)
│   └── Internal/
│       └── InternalHelper.hpp
└── src/                   ← sourceArea (default)
    ├── API/
    │   └── PublicClass.cpp
    └── Internal/
        └── InternalHelper.cpp

Library-Relative Variables

The .lib. variables (<package.lib.path>, <package.lib.qname>, <element.lib.qname> in patterns, ${package_lib_path} in templates) are relative to the enclosing <<ModelLibrary>>, the library itself excluded. Two companion variables carry the library name only when there is one: <lib.dir> is MyLib/ inside a library and empty outside, <lib.prefix> is MyLib_ inside a library and empty outside. Composing them gives the library-qualified form, without an orphan separator when the model has no library at all.

For the model below, with the Hierarchical deployment (<area.public>/<lib.dir><package.lib.path>/<file.name> and <lib.prefix><element.lib.qname>):

Model
├── MyLib  <<ModelLibrary>>
│   ├── Direct              class directly in the library
│   └── Sub
│       └── Deep            class in a sub-package of the library
└── Plain
    └── Loose               class outside any library
Element <package.lib.path> <lib.dir> Header file <lib.prefix><element.lib.qname>
MyLib::Sub::Deep Sub MyLib/ include/MyLib/Sub/Deep.hpp MyLib_Sub_Deep
MyLib::Direct (empty) MyLib/ include/MyLib/Direct.hpp MyLib_Direct
Plain::Loose Plain (no library: full path) (empty) include/Plain/Loose.hpp Plain_Loose

A pattern written without the prefix, such as <area.source>/<package.lib.path>/<file.name>, gives the pure relative form: src/Sub/Deep.cpp. The root package of the model is never a library, even when it carries the <<ModelLibrary>> stereotype.

Deployment Configuration Properties

The following properties are available on a C and C++ Code Deployment element.

For the formal property definition and full tagged-value reference, refer to the C and C++ Code deployment profile definition document.

Directory Properties

Property Type Default Description
publicArea String include Directory for public headers
internalArea String internal Directory for nonpublic (internal) headers
sourceArea String src Directory for all implementation files

File Extension Properties

Property Type Default Description
cppHeaderExt String .hpp Extension for C++ header files
cppSourceExt String .cpp Extension for C++ source files
cHeaderExt String .h Extension for C header files
cSourceExt String .c Extension for C source files

Path Pattern Properties

Path patterns use the <variable> syntax (CATIA Magic convention):

Property Type Default Description
publicHeaderPath String <area.public>/<lib.dir><package.lib.path>/<file.name> Path pattern for public headers
internalHeaderPath String <area.internal>/<lib.dir><package.lib.path>/<file.name> Path pattern for internal headers
sourcePath String <area.source>/<lib.dir><package.lib.path>/<file.name> Path pattern for source files

Template Variables

Templates (<<TextTemplate>> body) support automatic variable substitution using the ${variable_name} syntax. Variables are available in both file header templates and resource templates; some are context-specific.

Top-Level Variables

These variables are available in all <<TextTemplate>> contexts (file headers and resource templates):

Variable Description Available In Example Value
${lib_name} Name of the current ModelLibrary All MyLibrary
${lib_dir} ${lib_name}/ inside a ModelLibrary, empty for the project scope All MyLibrary/
${lib_prefix} ${lib_name}_ inside a ModelLibrary, empty for the project scope All MyLibrary_
${area_public} Public header directory from deployment All include
${area_internal} Internal header directory from deployment All internal
${area_source} Source files directory from deployment All src
${year} Current year All 2026
${generation_date} Date of code generation All 2026-02-11T09:30:00Z
${generator_version} Software Producer version All 2026.1.0
${comment_banner} Configurable banner string (length from bannerLength) All ****...****
${configuration_name} Name of the generation configuration All MyConfig
${project_name} Name of the current project All VehicleProject
${file_name} Generated file name File Header MyClass.hpp
${package_name} Package owning the element (in a file header) or the package of the resource scope (in a resource: the root model, the library or the package, see Scope Macros) All, ##PACKAGES Controls
${package_path} Full package path All, ##PACKAGES Root/Sub/Controls
${package_lib_path} Package path relative to the ModelLibrary, the library excluded All, ##PACKAGES Continue/Nesting
${element_qname} Fully qualified element name File Header Root_Sub_MyClass
${element_relname} Chain of non-package owners including the element, _-joined boundary File Header Button_Toggle
${parent_relname} Chain of non-package owners excluding the element, _-joined File Header Button
${element_id} UUID of source UML element File Header _19_0_2_abc123
Note:

Available In: All = available in both file header and resource templates. File Header = in the fileHeaderTemplate context, where the element is the UML element the file is generated from. ##PACKAGES = inside that macro, and everywhere in a Package-scoped resource (see Scope Macros).

File Variables (Inside Macros)

When iterating file collections with macros, these variables are available within ##MACRO_NAME { ... ##} blocks:

Variable Description Example Value
${file_path} Full relative path from library root src/API/PublicClass.cpp
${file_name} Filename with extension PublicClass.cpp
${file_basename} Filename without extension PublicClass
${rel_path} Path relative to area directory API/PublicClass.cpp

File Collection Macros

Resource templates provide macros for iterating over generated files:

Macro Description
##ALL_SOURCES { ... ##} Iterate all .cpp or .c implementation files
##ALL_SOURCE_DIRS { ... ##} Iterate the distinct directories that contain source files
##PUBLIC_HEADERS { ... ##} Iterate headers in public area
##INTERNAL_HEADERS { ... ##} Iterate headers in internal area
##ALL_HEADERS { ... ##} Iterate all headers (public + internal)

Macro syntax: ##MACRO_NAME { content ##}

Inside ##ALL_SOURCE_DIRS, the file variables describe each directory rather than a file: ${file_path} (and ${rel_path}) hold the directory path, and ${file_name} holds the leaf directory name. This is convenient for build systems that consume directories, for example CMake’s aux_source_directory or target_include_directories.

Scope Macros

A resource template can also iterate over the model structure instead of the generated files:

Macro Available in Description
##LIBRARIES { ... ##} Project scope Iterates over the registered <<ModelLibrary>> packages (the root model is not one of them); ${lib_name}, ${lib_dir} and ${lib_prefix} are reassigned per iteration, and the collection and scope macros inside the block are restricted to that library
##PACKAGES { ... ##} All scopes Iterates over the packages inside the current scope that own generated code, at any depth; sets ${package_name}, ${package_path} and ${package_lib_path} per iteration
##USED_PACKAGES { ... ##} Library and Package scope Iterates over the packages the current scope uses outside itself, from the modeled UML Usage relationships; sets ${used_package_name}, ${used_package_path} and ${used_package_lib_path} (see Declaring what a package uses)

The scope of a resource designates a unit — the whole generation for Project, one <<ModelLibrary>> for Library, one package for Package — and the macros describe that unit the same way at every scope: ##ALL_SOURCES and the other collection macros list its files, ##PACKAGES the packages inside it, ##USED_PACKAGES what it uses outside itself. ${package_name}, ${package_path} and ${package_lib_path} are set everywhere in the template and designate the unit’s package: the root model in a Project resource, the library in a Library resource, the package in a Package resource. Inside ##LIBRARIES they keep designating the resource’s own unit; the iterated library is ${lib_name}.

Escape Character

Use $$ to produce a literal $ character in template output. This is useful when generating files that contain their own ${...} syntax (for example, CMake or Makefile variables):

$${CMAKE_CURRENT_LIST_DIR}   →   renders as: ${CMAKE_CURRENT_LIST_DIR}

Example CMakeLists.txt Template

# Generated build file for ${lib_name}
add_library(${lib_name})

target_sources(${lib_name} PRIVATE
##ALL_SOURCES {
    ${file_path}
##}
)

target_include_directories(${lib_name}
    PUBLIC ${area_public}
    PRIVATE ${area_internal}
)

Generated output (for library MyLibrary with 2 source files):

# Generated build file for MyLibrary
add_library(MyLibrary)

target_sources(MyLibrary PRIVATE
    src/API/PublicClass.cpp
    src/Internal/Helper.cpp
)

target_include_directories(MyLibrary
    PUBLIC include
    PRIVATE internal
)

Writing a File Header Template

Every generated C/C++ file starts with a file header (a comment block at the top of the file). The content of that header is defined by the File Header Template property of the C and C++ Code Deployment, which points to a Text Template element. By providing your own Text Template, you can customize the header to include your project name, copyright notice, license terms, traceability information, or any other text required by your coding standards.

Accessing default file header

How to Define a File Header Template

  1. From the diagram palette, drag a Text Template onto the Software Producer Configuration Diagram to create the template element.
  2. Open its Specification window and edit the Body property to enter your header text, using the variables and macros described below.
  3. On your C and C++ Code Deployment element, set the File Header Template property to point to the Text Template you just created.

The same Text Template can be referenced by several deployments, so a shared header can be reused across multiple configurations.

Note:

Note: Text Template is the same element type used to define the body of additional resources (see Creating a Custom Deployment). The variables and macros described below — ${...} substitution, the $$ escape, the ##COMMENT { ... ##} and ##ORIGINS { ... ##} macros, and the @@ line prefix — are equally available when you author a Text Template attached as an additional resource (for example, a custom CMakeLists.txt or Makefile). The only difference is the set of context-specific variables and collection macros available, as summarized in Template Variables.

Default File Header Template

If you do not set fileHeaderTemplate, the following template is used:

@@/* Generated on ${generation_date} */

##COMMENT {
${comment_banner}
@file ${file_name}

Automatically generated by Software Producer Engineer
UML Classes Code Generator @version v${generator_version}
##ORIGINS {
@generated_from ${element_id}
##}
${comment_banner}
##}

This template demonstrates every construct available in a file header. The sections below explain each one so you can adapt the template to your needs.

Variables

Variables are written as ${variable_name} and are replaced at generation time. In a file header you can use any of the top-level variables (for example, ${lib_name}, ${year}, ${project_name}, ${generation_date}, ${generator_version}, ${comment_banner}) and the file-header-only variables (${file_name}, ${package_path}, ${package_lib_path}, ${element_qname}, ${element_id}).

See Top-Level Variables for the complete list and example values.

To produce a literal $ in the generated header (for example, when emitting a $Id$ keyword for a version control system), escape it with $$:

$$Id: ${file_name} $$

The ##COMMENT { ... ##} Macro

The ##COMMENT { ... ##} macro wraps its content in a comment block whose syntax follows the doxygenCommentStyle property of the deployment. This lets the same template produce Javadoc-style (/** ... */), Qt-style (/*! ... */), triple-slash (/// ...), or exclamation (//! ...) comment blocks without rewriting the template.

Anything outside ##COMMENT { ... ##} is emitted as-is. This is useful for lines that are not comments, such as license preambles already containing their own delimiters, or for lines that should be excluded from change detection (see the @@ prefix below).

Example — minimal copyright header in Javadoc style:

##COMMENT {
Copyright (c) ${year} ACME Corp. All rights reserved.
@file ${file_name}
##}

The ##ORIGINS { ... ##} Macro

The ##ORIGINS { ... ##} macro iterates over the UML source elements that contributed to the generated file. Inside the block, ${element_id} and ${element_qname} are reassigned for each origin, so the same line is repeated once per source element.

This is the recommended way to emit traceability links between generated code and the originating model elements.

Example — list every source element on its own line:

##COMMENT {
@file ${file_name}
##ORIGINS {
@generated_from ${element_qname} (${element_id})
##}
##}

The @@ Line Prefix

A line that starts with @@ is excluded from file comparison when the generator decides whether to overwrite an existing file. This is intended for lines that change at every generation (such as a generation timestamp) and would otherwise force the file to be rewritten on every run, defeating change detection.

Use @@ for the volatile parts of your header (date, build number, generator version) and keep stable information (copyright, file name, origins) on regular lines so meaningful changes are still detected.

Example:

@@/* Generated on ${generation_date} */
@@/* Generator version ${generator_version} */

##COMMENT {
Copyright (c) ${year} ACME Corp.
@file ${file_name}
##}

A Custom File Header Example

The following template combines a license preamble, a Doxygen-formatted comment block, and traceability origins, while keeping the generation date out of file comparisons:

@@/* Generated on ${generation_date} */
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright (c) ${year} ACME Corp. */

##COMMENT {
${comment_banner}
@file ${file_name}
@brief Part of library ${lib_name} in project ${project_name}.

This file is automatically generated. Do not edit by hand.
##ORIGINS {
@generated_from ${element_qname} (${element_id})
##}
${comment_banner}
##}

Declaring what a package uses

A package-scope or library-scope build file can list the packages the current package or library depends on. The dependency is the one you model: a UML Usage relationship (no other kind of dependency is read) from the package, or from any element it owns, to the used package or to one of its elements. Nothing is deduced from the generated #include lines, on purpose: a use that is not modeled is then missing from the build file and fails at build time, which is exactly where the model gap should show.

Inside a Package-scoped or Library-scoped <<Resource>> template:

##USED_PACKAGES{
target_link_libraries(${package_name} ${used_package_name})
##}

Each iteration exposes ${used_package_name}, ${used_package_path} and ${used_package_lib_path}. A package that uses nothing renders an empty block, and the block renders nothing in a Project resource: nothing is used outside the whole generation.

What is listed follows the scope:

  • In a Package resource: the packages used by the package’s own elements. Its sub-packages are units of their own and list their own usages.
  • In a Library resource: the packages used by every package of the library, the library’s own packages excluded — they are not dependencies of the library.
  • In both: a Usage drawn from a package to a package covers everything the client package contains, so the packages below it inherit it. A Usage drawn on Root::Classes toward Root::Libraries is listed by the build file of every package with generated code under Classes, even though Classes itself, owning no code, has no build file. A Usage between a class and another element is not inherited: it belongs to the package whose files need it.

Limitations

The following features are not yet supported:

Feature Variables Description
##DEPENDENCIES macro ${dep_name}, ${dep_path} Planned macro for iterating library dependencies in build files; not yet available in the current delivery

When this macro is made available, the ##DEPENDENCIES block iterates over library dependencies and expose ${dep_name} (library name) and ${dep_path} (library path) for each dependency.

Troubleshooting

Files Not Appearing in Expected Location

Check these items: 1. Is the library root package marked with the <<ModelLibrary>> stereotype? (Right-click the package in the Containment Tree > Stereotype… > select ModelLibrary.) 2. Is a valid C and C++ Code Deployment selected in the configuration diagram? (Or leave empty for the default flat deployment.) 3. Has the deployment been associated with the generation configuration? (Drag and drop the deployment onto the generation configuration on the diagram.) 4. Are UML visibilities correctly set on classes?

Build File Not Generated

Verify: 1. The Text Template for the build file is attached to the deployment as an additional resource (drag it onto the deployment after creating it on the diagram). 2. The attached resource has a valid File Path (set in its Specification window) and a non-empty Body. 3. Template syntax is valid (check $$ escaping for literal $ characters).

Wrong File Extensions

Check the extension properties on your deployment: - C++ header / source extensions (defaults: .hpp / .cpp) - C header / source extensions (defaults: .h / .c)

For Advanced Users: Underlying Stereotypes

The palette elements described above are backed by UML stereotypes from the SoftwareProducerCodeDeployment profile:

Palette element / property label Underlying stereotype
C and C++ Code Deployment <<CFamilyCodeDeployment>>
Text Template <<TextTemplate>>
Additional resource (created when a Text Template is dropped on a deployment) <<Resource>>

For the complete tagged-value reference and stereotype model, see the C and C++ Code deployment profile definition document.