CMake Integration
The source file generator should integrate seamlessly with the CMake build system. The user should be able to call a code generation script and add its output files to a target in a transparent and intuitive way with minimal syntactic overhead. The code generator should be configurable through CMake, such that project-global settings can be specified in a single place. Global settings should transparently control any code generation scripts in the project, be accessible from within them, and should be overridable where necessary.
Inclusion and global configuration
The source file generator should be includable to any CMake project via find_package
. It should work out-of-the-box with zero configuration.
Optional global configuration includes the specification of the default output file extensions. Default is .h/.cpp
, but some projects may use the .hpp/.cpp
convention; others generate CUDA code and will want to use .h/.cu
.
It should be possible to register a configurator Python script which will be automatically imported and run by every code generation script in the project. This configurator would handle any project-specific setup of the code generator; e.g. register default field mappings.
Source generation for CMake targets
Due to the 1:1 correspondence principle between generator scripts and their output files enforced by the code generator, integration with CMake targets becomes straightforward. The basic syntax for registering a script with the build system and adding its output to a target should resemble
pystencilssfg_generate_target_sources(
TARGET <target>
SCRIPTS <scripts>
[DEPENDS <dependencies>]
[FILE_EXTENSIONS <extensions>]
[HEADER_ONLY]
)
<target
may be a libary, an executable, etc.
Here, each script is executed and its generated sources (kernels_a.hpp
, kernels_a.cpp
, ...) are added to the target.
Dependencies may be specified (for triggering rebuilds), and the global file extension setting can be overridden.
Optionally, the code generation scripts may be specified as generating only a header file.