Function portal_setup_compile_configs

Generates a single implementation file providing definitions for application configuration constants declared across all dependent Portal modules.

This function creates a C++ source file that defines compile-time constants for application metadata (display name, settings file, icon file). These definitions satisfy the extern const declarations that each Portal module creates via portal_setup_config_pch in their respective config PCHs. This allows a single implementation to serve all dependent modules.

Synopsis

portal_setup_compile_configs(<target_name>
                              <settings_file>
                              <icon_file>)

Arguments

<target_name>

Name of the executable target to add the configuration definitions to.

<settings_file>

Filename of the settings file (e.g., “settings.json”). Becomes the definition for the portal::PORTAL_SETTINGS_FILE_NAME constant declared in each module’s config PCH.

<icon_file>

Filename of the icon file (e.g., “icon.png”). Becomes the definition for the portal::PORTAL_ICON_FILE_NAME constant declared in each module’s config PCH.

Behavior

The function performs the following operations:

  1. Template Generation: Creates a C++ source file template containing definitions for PORTAL_SETTINGS_FILE_NAME, and PORTAL_ICON_FILE_NAME as constexpr std::string_view in the portal namespace.

  2. CMake Configuration: Writes the template to config_impl.inc in the build directory, then uses configure_file() to substitute @VARIABLE@ placeholders with the provided values, producing config_impl.cpp.

  3. Source Integration: Adds the generated config_impl.cpp to the target’s private sources, providing a single set of definitions that satisfy the declarations from all dependent Portal modules.

Multi-Module Declaration Pattern

Each Portal module (core, application, engine, etc.) that has a config file calls portal_setup_config_pch during its build, which generates declarations for these constants in the module’s config PCH:

// In portal-application/config.h (also generated by portal_setup_config_pch)
namespace portal {
    extern constexpr std::string_view PORTAL_SETTINGS_FILE_NAME;
}

// In portal-engine/config.h (also generated by portal_setup_config_pch)
namespace portal {
    extern constexpr std::string_view PORTAL_ICON_FILE_NAME;
}

The application then calls portal_setup_compile_configs once to provide the single implementation that all modules will link against:

// In build/config_impl.cpp (generated by portal_setup_compile_configs)
namespace portal {
    constexpr std::string_view PORTAL_SETTINGS_FILE_NAME = "settings.json";
    constexpr std::string_view PORTAL_ICON_FILE_NAME = "icon.png";
}

Example Usage

Typically called internally by portal_add_game:

# Each Portal module has already called portal_setup_config_pch during their build
# Application calls this once to provide the definitions
portal_setup_compile_configs(my-game "settings.json" "icon.png")

Notes

  • This is an internal function typically called by portal_add_game

  • Provides a single implementation for declarations across all dependent Portal modules

See Also