rules/c/cmake/expansion.js
Developer reference: this page includes exported implementation details. BUILD authors should prefer the User API reference.
cmakeProjectSpecs()
cmakeProjectSpecs()
Undocumented.
crossTargetDependencies()
crossTargetDependencies(named, ninjaGraph)
Undocumented.
topoSortTargets()
topoSortTargets(named, crossDeps)
Undocumented.
buildTargetDeps()
buildTargetDeps(targetName, named, crossDeps, builtByName)
Undocumented.
cmakeProjectExpansion()
cmakeProjectExpansion(opts = {})
Discover and build every real CMake target (add_library/add_executable) a CMakeLists.txt declares, as one keyed expand(). Use cmakeLibraryDep() to consume a discovered target as a raw ccLibrary()/ccBinary() deps entry — see this module's own docstring. — workflow one of BUILD/PACKAGE/TEST; TEST's facet is always "unit" (a single ctest run), mirroring rules/rust's own TEST facet shape for uniformity, even though CMake only ever has the one kind.
| Parameter | Type | Description |
|---|---|---|
| [opts] | object | Same shape as cmakeProjectSpec()'s opts. |
Returns: object {get(cmakeTargetName, workflow, facet?), all(workflow, facet?)}
cmakeProject()
cmakeProject(opts = {})
Public entry point for a graph-native CMake project — see cmakeProjectExpansion() for the returned {get, all} shape. for compiler edges, for inputs that do not use a standard header suffix. configure and replay. CMake arguments define how the project uses them.
| Parameter | Type | Description |
|---|---|---|
| [opts] | object | |
| [opts.path] | string | Workspace-relative CMakeLists.txt directory. Defaults to the calling BUILD.js's own directory ("."). |
| [opts.buildDir] | string | Build directory; defaults to build/<path>. |
| [opts.srcs] | string[] | Source glob CMake configure/replay depends on. |
| [opts.dirs] | string[] | Extra directories (e.g. vendored includes) to mount. |
| [opts.extraGlobs=[]] | string[] | Extra project-relative files to mount |
| [opts.deps=[]] | Array | Artifact handles to mount for CMake |
| [opts.cmakeArgs] | string[] | Extra cmake -S -B arguments. |
| [opts.toolchain] | object | gccGraphToolchain() result, or the workspace default. zig isn't supported yet — see graph_replay.js's own docstring. |
| [opts.unsafeSystemPaths=false] | boolean | Bypass Bootlin's toolchain-wrapper unsafe-path guard (which rejects -I/-isystem/-L flags under /usr/include or /usr/lib) so this project's compile/link steps can use host system packages (e.g. libwebkit2gtk-4.1). Same sysroot and hardening flags as normal, just without that one guard. |
Returns: object {get(cmakeTargetName, workflow, facet?), all(workflow, facet?)}.
cmakeLibraryDep()
cmakeLibraryDep(project, name, opts = {})
Adapt a discovered CMake target for use as a raw ccLibrary()/ccBinary() deps entry. CMake's own per-target include paths aren't structurally discoverable today (see this module's own docstring) and expand().get() is resolved too late for ccTask()'s synchronous include-flag construction anyway, so includeDirs must be supplied by the caller.
| Parameter | Type | Description |
|---|---|---|
| project | object | A cmakeProject()/cmakeProjectExpansion() result. |
| name | string | CMake target name (as passed to add_library/add_executable). |
| [opts] | object | |
| [opts.includeDirs=[]] | string[] | Include dirs downstream ccLibrary()/ccBinary() targets need, e.g. the CMake project's own public header directory. |
| [opts.linkopts=[]] | string[] | Link flags downstream targets need to resolve this target's own shared-library dependencies, e.g. pkg-config-derived -L/-l flags for a .so linked against host system packages. CMake's own per-target link flags aren't structurally discoverable any more than its include paths are (see includeDirs above) — supplied by the caller for the same reason. |
| [opts.shared=false] | boolean | Declare that this CMake target is a shared library (add_library(... SHARED ...)), so its artifact travels as transitiveSharedLibs rather than transitiveArchives — the same bucket ccLibrary({shared: true}) uses. Caller-supplied for the same reason as includeDirs and linkopts: the target's own CMake type is known only after the configure task has run, while this function must report the bucket synchronously at BUILD.js declare time. |
Returns: object {[BUILD], archive, transitiveArchives, transitiveSharedLibs, transitiveIncludeDirs, transitiveLinkopts} — usable directly as a ccLibrary()/ccBinary() deps entry.