Allow customization and improve default behavior for output path in CMake integration
The SFG CMake module currently always places generated files at ${CMAKE_BINARY_DIR}/sfg_sources/gen/${TARGET_NAME}
.
For each target, ${CMAKE_BINARY_DIR}/sfg_sources
is added to its include path, and headers can be included by #include "gen/<target-name>/*.hpp"
.
This is rather inflexible and should be adjusted.
Default Output and Include Path
I propose to alter the default output path to ${CMAKE_CURRENT_BINARY_DIR}/_gen/${TARGET_NAME}
, to place generated files next to their target's build dir instead of in the global CMake build tree root. Also, ${CMAKE_CURRENT_BINARY_DIR}/_gen/${TARGET_NAME}
should be added to the include path of ${TARGET_NAME}
, such that generated files can be included like this: #include "<gen-header>.hpp"
, without the target name in the path. This has the advantage that handwritten files can be added to multiple targets, and be linked to a different generated file depending on the target without having to adjust the #include
s.
Maybe, for distinguishment, we can prepend a gen
to the include path, i.e. write files to ${CMAKE_CURRENT_BINARY_DIR}/_gen/${TARGET_NAME}/gen
and include them via #include "gen/<file>.hpp"
.
Backward Compatibility
This change would break all projects already using pystencils-sfg, so maybe we should add a flag to optionally enable it as long as sfg
is in pre-release state, and deprecate the old behavior. The old behavior can then be removed with the release of version 0.1.
Permit Custom Output Directories
It should be possible to override the output directory via an argument to pystencilssfg_generate_target_sources
. If the user specifies an output directory this way, they are responsible for adding it to the target's include path.
This option allows users to separate public from private generated headers, potentially share generated files among multiple targets, and simply adjust the output path according to their preferences.