API Reference
The public functions provided by OTProject.cmake. Square brackets denote
optional arguments. <Target> is the project/target name passed to
project().
Initialize
ot_initialize_lib(<Target> <ROOT_PATH_VAR> [EXPORT_MACRO])Creates the object library
<Target>_corefromsrc/andinclude/, applies the C++20 standard, the default runtime, the Debug/Release definitions and_USRDLL, and sets the dll-export macro (defaultOPENTWIN<NAME>_EXPORTS). Use for libraries and services.ot_initialize_bin(<Target> <ROOT_PATH_VAR> [EXPORT_MACRO])Like
ot_initialize_libbut marks the target as an application. The export macro is optional. Use for executables.ot_initialize_bin_python(<Target> <ROOT_PATH_VAR> [EXPORT_MACRO])Like
ot_initialize_binbut forces the/MDruntime in every configuration and defines_RELEASEDEBUG(Debug) /NDEBUG(Release) instead of_DEBUG, so the target links the releasepython311.lib. Use only for binaries that embed CPython.
Dependencies
ot_add_dependency(<Target> <TOKEN> ...)Records dependency tokens on
<Target>_core. Resolved at finalize. See Dependency tokens. May be called multiple times; tokens accumulate.
Finalize
ot_finalize_lib(<Target>)Creates the shared library
<Target>from the core objects, exposesinclude/as aPUBLICinclude directory, applies all recorded dependencies and the requested subsystem, and enablesAUTOMOCif anyQt*token is present.ot_finalize_bin(<Target> [OUTPUT_NAME])Creates the executable
<Target>from the core objects.WIN32_EXECUTABLEis set according to the subsystem (Release GUI vs console). PassOUTPUT_NAMEto give the produced.exea different file name. Applies dependencies, subsystem andAUTOMOCas forot_finalize_lib.
Tests
ot_add_test(<Target>)If
BUILD_TESTINGis on andtests/CMakeLists.txtexists, adds thetestssubdirectory. Safe to call when no tests exist (it just logs a status message).ot_initialize_test(<TestTarget> <MainTarget>)Called inside
tests/CMakeLists.txt. Builds<TestTarget>fromtests/src/*.cppplus the compiled<MainTarget>_coreobjects, inherits the main target’s export macro, dependencies and runtime library, links the gtest library and registers the test with CTest.
Compile options and definitions
ot_add_compile_definitions(<Target> <def> ...)Adds private preprocessor definitions to the core target.
ot_add_compile_options(<Target> <opt> ...)Adds raw compile options to the core target. A bare numeric argument is treated as a warning to disable and becomes
/wd<number>.ot_disable_warnings(<Target> <id> ...)Convenience wrapper that suppresses warnings by numeric ID. Non-numeric arguments produce an author warning (use
ot_add_compile_optionsfor flags).
Subsystem
ot_set_subsystem(<Target> CONSOLE|WINDOWS)Sets the linker subsystem for the final binary (applied on finalize).
CONSOLEkeeps amain()entry point and console window;WINDOWSproduces a windowed application.ot_set_subsystem_for_config(<Target> <Config> CONSOLE|WINDOWS)Overrides the subsystem for a single configuration (
Debug,Release,RelWithDebInfoorMinSizeRel). Configuration-specific overrides take precedence overot_set_subsystem.
Runtime library
ot_set_runtime_static_release(<Target>)Links the static CRT (
/MT) in Release while keeping/MDdin Debug. For stand-alone command line tools that ship as a single self-contained executable. Never use it for libraries, services, or Python targets.
Resources and deployment
ot_add_qt_resources(<Target>)Globs
*.qrcunder the project and enablesAUTORCC.ot_add_resources(<Target>)Globs
*.rcand*.icounder the project into the target.ot_deploy_app_configuration(<Target>)Adds a post-build step copying
qt.conf(if present) next to the binary.
Internal helpers
Functions prefixed with _ot_ (for example _ot_initialize_target,
_ot_apply_dep_to_core, _ot_apply_dep_to_final, _ot_get_ot_root_envvar)
are implementation details of the meta system. Do not call them from a project
CMakeLists.txt. Extend them only when adding a new dependency token or
environment-variable mapping that the public API cannot express.