This file is the how-to for the in-progress module split described in
architecture.md. Do not invent a second pattern (extra
globs in the root CMakeLists, a hand-rolled *_API header, or edits under
external/).
fling_add_module() lives in CMake/FlingModule.cmake.
Until FlingEngine/CMakeLists.txt add_subdirectorys each module, the engine is
still one static library and new folders are picked up by the monolith glob.
Do not add a fling_add_module target that compiles the same sources as
FlingEngine — that double-builds. Use this recipe once modules are separate
targets (or when you are the change that splits them).
A module is:
- A folder under
FlingEngine/withinc/(public headers) andsrc/(sources). - A
CMakeLists.txtthat callsfling_add_module. add_subdirectory(...)inFlingEngine/CMakeLists.txtafter that module's dependencies exist.MODULE_APIon types that cross the DLL boundary.target_link_libraries(Consumer PRIVATE Fling::ModuleName)on anything that should see that module's headers.
You do not list .cpp files by hand. You do not edit the old engine-wide glob.
In-game HUD / widgets. Publicly needs Core and Gameplay (types, Transform).
Privately needs Graphics and ImGui to draw. A physics-only tool would not link
Fling::UI and would not see UISystem.h.
FlingEngine/UI/
CMakeLists.txt
inc/UISystem.h
src/UISystem.cpp
Keep #include "UISystem.h" (flat names). Isolation comes from include paths
via target_link_libraries, not from renaming headers to UI/UISystem.h.
fling_add_module(UI
PUBLIC_DEPS Core Gameplay
PRIVATE_DEPS Graphics
PRIVATE_LIBS ImGui
)| Argument | Meaning |
|---|---|
PUBLIC_DEPS |
Fling modules whose headers consumers of UI may also include |
PRIVATE_DEPS |
Fling modules UI uses internally; not pushed onto UI's consumers' include path |
PUBLIC_LIBS / PRIVATE_LIBS |
Third-party CMake targets (glfw, ImGui, Vulkan::Vulkan, …) |
STATIC |
Optional. Default is a shared library |
CMake generates UIAPI.h (macro UI_API) into the UI build dir and puts that
dir on UI's public include path. Do not check UIAPI.h into git.
In FlingEngine/CMakeLists.txt, add UI after Core, Gameplay, and Graphics.
A dependency cycle is a configure error.
add_subdirectory(Core)
add_subdirectory(Resources)
add_subdirectory(Gameplay)
add_subdirectory(Graphics)
add_subdirectory(UI)If Sandbox or Engine should use UI, link the alias — do not include_directories
the UI folder:
target_link_libraries(SandboxEditor PRIVATE Fling::UI)#pragma once
#include "UIAPI.h"
#include "FlingTypes.h"
namespace Fling
{
class UI_API UISystem
{
public:
void Init();
void Draw(float deltaTime);
};
}#include "UISystem.h"
namespace Fling
{
void UISystem::Init() {}
void UISystem::Draw(float deltaTime) { (void)deltaTime; }
}- Mark classes/functions that are defined in this module's
.cppand called from another module withUI_API. - Header-only templates stay unmarked.
- Do not use
FLING_LIB_EXPORT/FLING_LIB_IMPORTon engine types; those are only for the generated*API.hheaders.
#include "UISystem.h"
Fling::UISystem hud;
hud.Init();If a target does not link Fling::UI, #include "UISystem.h" must fail to
compile. That is the isolation test.
- Folder is
FlingEngine/<Name>/{inc,src}plusCMakeLists.txt. -
fling_add_module(<Name> ...)only; no extraadd_library/ globs. -
add_subdirectory(<Name>)after every module inPUBLIC_DEPS/PRIVATE_DEPS. - Public headers include
<Name>API.hand use<NAME>_APIon exported types. - Consumers
target_link_libraries(... Fling::<Name>). No newinclude_directories()for engine headers. - Gameplay still does not include Graphics headers. Editor stays a leaf
(Engine/Graphics do not include Editor). See
architecture.md. - Nothing under
external/is modified.