Skip to content

CMake Integration

🚧 Roadmap — WIP. The find_package(codegen), codegen_rule(), and CODEGEN_OUTPUTS helpers below are the design target for a planned cmake_integration package and are not yet shipped. The supported path today is add_custom_command driving the codegen binary; workspace analysis is unconditional (codegen always talks to the workspace daemon), so no flag or licence is needed to enable it. This page documents both the current and the planned path; track progress in the codegen changelog.

Until the package ships, drive codegen from a regular add_custom_command / add_custom_target:

CMakeLists.txt
set(CODEGEN_INPUT ${CMAKE_SOURCE_DIR}/include/color.hpp)
set(CODEGEN_OUTPUT ${CMAKE_SOURCE_DIR}/include/color.g.cpp)
add_custom_command(
OUTPUT ${CODEGEN_OUTPUT}
COMMAND codegen
-i ${CODEGEN_INPUT}
-r ${CMAKE_SOURCE_DIR}/.codegen/rules
-a ToString
DEPENDS ${CODEGEN_INPUT}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "codegen: ToString -> ${CODEGEN_OUTPUT}"
VERBATIM
)
add_custom_target(codegen_color DEPENDS ${CODEGEN_OUTPUT})
target_sources(mylib PRIVATE ${CODEGEN_OUTPUT})
add_dependencies(mylib codegen_color)

By default the engine writes outputs next to the input header, so the OUTPUT path is predictable: <input_stem>.g.cpp for cpp rules, <input_stem>.<ruleName><ext> for other languages. Override with outputDirectory and outputNameTemplate in the rule’s config.

Workspace analysis is unconditional — codegen always connects to the workspace daemon serving <root>/.codexx/daemon.sock. Run codegen from the project root so the daemon’s root matches, or pass --workspace-dir to point at a different directory.

Planned: find_package(codegen) + codegen_rule()

Section titled “Planned: find_package(codegen) + codegen_rule()”

A future package will install a CMake config module (codegenConfig.cmake) and a codegen_rule() helper that wraps the underlying add_custom_command and exposes the generated files for target_sources:

CMakeLists.txt (planned)
find_package(codegen REQUIRED)
codegen_rule(
RULE ToString
RULES_DIR ${CMAKE_SOURCE_DIR}/.codegen/rules
INPUT ${CMAKE_SOURCE_DIR}/include
OUTPUT_VAR CODEGEN_TOSTRING_OUTPUTS
)
target_sources(mylib PRIVATE ${CODEGEN_TOSTRING_OUTPUTS})

The helper will parse the rule config, derive OUTPUT paths from outputDirectory / outputNameTemplate, depend on the input headers, and chain the generated files into the target’s source list — eliminating the “forgot to regenerate” CI failure class.

This page will be updated when the package ships.

Key Takeaways
  • The find_package(codegen) / codegen_rule() flow is not yet implemented.
  • Today, drive codegen with add_custom_command calling the binary directly.
  • Default output paths are predictable from the rule config (<stem>.g.cpp for cpp, <stem>.<ruleName><ext> otherwise).
  • The packaged helper is a roadmap item, not yet shipped; this page tracks the target.