Single-file amalgamation (src-amalgamate)¶
Besides the normal CMake library target, DAWidgets ships the whole library as one header + one source file under src-amalgamate/:
| File | Contents |
|---|---|
src-amalgamate/DAWidgets.h |
Every public header, including all Q_OBJECT declarations |
src-amalgamate/DAWidgets.cpp |
Every implementation plus the uic-generated ui_*.h files and rcc-generated icon resources |
Drop the two files into your project and you have the complete library — no DAWidgets build, no install step and no find_package. The toolchain follows the reference project qwt 7 and is built on vinniefalco/Amalgamate, driven by tools/Amalgamate.ps1 / tools/Amalgamate.sh.
When to use it¶
- Single-file tools, samples or plugin hosts where pulling in a dependency and its build system is overkill;
- projects that vendor their dependencies and want a self-contained, offline-friendly copy;
- anyone who prefers reading and debugging the real library sources instead of a prebuilt binary.
It is not the right choice when several projects share one library install, when the library must be upgraded as a DLL, or when first-build time is critical — use the regular CMake install flow instead (see Build instructions).
Adding it to a CMake project¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
Key points:
DAWidgets.hmust be listed in the target sources. Otherwise AUTOMOC never processes theQ_OBJECTclasses and linking fails withundefined reference to vtable.DA_BUILT_AS_STATICmust be defined so the export macro expands to nothing. Without it, Windows expands it todllimportand the link fails.- Link only Qt Widgets and Qt Svg — the property-editing widgets render SVG icons through Qt Svg.
- Include it as
#include "DAWidgets.h"; all classes live innamespace DA, e.g.DA::DASelectComboBox.
Adding it to a qmake project (.pro)¶
1 2 3 4 5 6 7 8 9 10 11 | |
qmake runs moc automatically for files listed in HEADERS, so no hand-written moc rule is needed. With Qt 5, make sure QT += widgets svg resolves to the Qt version you actually target.
Resources¶
The .ui files and the SVG icons registered in src/resources/dawidgetsicons.qrc are baked into DAWidgets.cpp (through uic / rcc) when the amalgamation is generated. Therefore:
- you do not need to add a
.qrcfile or any image files to your project, and there is no runtime dependency on external assets; - your application code does not need to call
Q_INIT_RESOURCE; - you should still regenerate after switching Qt versions (see Limitations).
MSVC note¶
The generated DAWidgets.cpp is a single translation unit of a few hundred KB to several MB. MSVC's default COFF section limit is easily exceeded and the compiler reports:
1 | |
Add /bigobj to the target that compiles the amalgamated files (both examples above do). Keep /utf-8 too: the sources contain Chinese comments and literals, which MSVC must decode as UTF-8.
Regenerating¶
Windows (PowerShell):
1 2 3 4 5 | |
Git Bash / MSYS2:
1 2 | |
The script:
- runs Qt's
uicoversrc/*.uito produceui_*.h; - runs Qt's
rccoversrc/resources/dawidgetsicons.qrcto produceqrc_dawidgetsicons.cpp; - runs
tools/Amalgamate.exewith the templates undertools/amalgamate/to emit the two files; - strips local absolute paths and normalizes line endings / encoding.
Qt is auto-detected from a configured build*/CMakeCache.txt; -QtBin / QT_BIN is only needed when no build directory exists. See tools/Amalgamate.md for the full tool description.
Never edit the generated files by hand
Both files are generated. When adding or removing a source file, first update
tools/amalgamate/DAWidgetsAmalgamTemplatePublicHeaders.h (public headers) and
tools/amalgamate/DAWidgetsAmalgamTemplate.cpp (implementations), then rerun the script.
Manual edits are overwritten on the next generation.
Reference example¶
examples/amalgamate_demo is the minimal single-file project: it does not link DA::DAWidgets at all, only compiles the two amalgamated files, and demonstrates the Selector and Collapse families.
1 2 3 4 5 6 | |
DAWIDGETS_BUILD_AMALGAMATE_DEMO is OFF by default because the amalgamated file is one large translation unit — there is no reason to build it on every development iteration.
Limitations¶
- Tied to the Qt version used at generation time. The
uicandrccoutput is inlined, so switching Qt major versions or Qt installations means regenerating. The copies committed in this repository are generated with Qt 6 and verified to compile with Qt 6.7.3 and Qt 5.14.2. - Slower first build. The whole library compiles as one translation unit; MSVC additionally requires
/bigobj. - Not a shared library. The amalgamated files are compiled into your target and cannot be upgraded as a DLL.
- Generated, not hand-maintained. Change
src/and the amalgamation templates, then regenerate.