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. For a target inServices/it also writes the Visual Studiolaunch.vs.json(seeot_service_debug_launch).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.
Debug launch (Visual Studio F5)
ot_service_debug_launch(<Target> ARGS <arg> ...)Declares the arguments Visual Studio passes to the service loader (after the service DLL path) when the service is launched with F5.
@NAME@tokens are emitted as${env.NAME}and resolved by Visual Studio at debug time. Most services do not need this; see Debugging services in Visual Studio.ot_bin_debug_launch(<Target> [PATH <path>] [ARGS <arg> ...])Generates a Visual Studio
launch.vs.jsonso an executable target can be debugged with F5 (the executable counterpart ofot_service_debug_launch, which targets DLL services). Call it from the binary’s ownCMakeLists.txtafterot_finalize_bin- it is an explicit per-target call, never automatic, so the launch config is generated only where it is requested.PATHis the debug-time DLL search PATH in Visual Studio${env.VAR}syntax; pass it as a bracket argument[[...]]so${env.VAR}and single backslashes are taken literally (they are JSON-escaped internally).PATHdefaults to the inherited${env.PATH}andARGSdefaults to none. Mainly used for anot_initialize_bin_pythontarget, which is built/MDand must therefore debug against the release OT DLLs (${env.OT_ALL_DLLR}) plus release python - never the/MDddebug DLLs, which would CRT- /_ITERATOR_DEBUG_LEVEL-mismatch and crash.ot_tool_bin_debug_launch(<Target> [ARGSD <arg> ...] [ARGSR <arg> ...] [PATHD <path>] [PATHR <path>])Generates the
launch.vs.jsonfor a tool executable, with separate arguments andPATHfor Debug and Release.@NAME@tokens work as inot_service_debug_launch.PATHDandPATHRdefault to the inheritedPATH. Call it afterot_finalize_bin.ot_tool_debug_launch(<Target> [ARGSD <arg> ...] [ARGSR <arg> ...] [PATHD <path>] [PATHR <path>])Like
ot_tool_bin_debug_launch, but for a DLL outsideServices/that runs inopen_twin.exe(for exampleOToolkit). The DLL path is passed as first argument.PATHDandPATHRdefault toOT_ALL_DLLDorOT_ALL_DLLRplus the inheritedPATH. Call it afterot_finalize_lib.
All four launch functions are Visual Studio only and do nothing with other compilers.
Each one writes the whole launch.vs.json, so a project uses only one of them. Examples:
Debugging in Visual Studio.
Qt
ot_bin_use_release_qt(<Target>)Makes the Debug configuration link the release Qt libraries. For targets that run the release runtime in Debug (
ot_initialize_bin_python). Call it afterot_finalize_bin, when the Qt targets exist. Visual Studio only.
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. A new dependency normally needs no change here: a third party library is added
through its environment variables, an OpenTwin library through a matching variable name
(see Dependency tokens).