dds in a CMake Project¶
dds’s primary goals is to inter-operate with other build systems
cleanly. Because of CMakes ubiquity,
dds includes built-in support for
emitting files that can be imported into CMake.
Before reading this page, be sure to read the Generating a libman Index
section of the Building and Using dds in Another Build System page, which will discuss how to use the
dds build-deps subcommand.
This page presents an involved and detailed process for importing dependencies, but there’s also an easy mode for a one-line solution. See: How Do I Use dds in a CMake Project?.
Generating a CMake Import File¶
build-deps accepts an
--lmi-path argument, but also accepts a
--cmake=<path> argument that serves a similar purpose: It will write a CMake
<path> that can be
include()’d into a CMake project:
$ dds build-deps "neo-sqlite3^0.2.0" --cmake=deps.cmake
This will write a file
./deps.cmake that we can
include() from a CMake
project, which will then expose the
neo-sqlite3 package as a set of imported
Using the CMake Import File¶
Once we have generated the CMake import file using
dds build-deps, we can
simply import it in our
dds, CMake wants us to explicitly declare how our build targets
use other libraries. When we
include() the generated CMake file, it will
IMPORTED targets that can be linked against.
dds (and in libman), a library is identified by a combination of
namespace and name, joined together with a slash
/ character. This
qualified name of a library is decided by the original package author, and
should be documented. In the case of
neo-sqlite3, the only library is
When the generated import file imports a library, it creates a qualified name
using a double-colon “
::” instead of a slash. As such, our
is imported in CMake as
neo::sqlite3. We can link against it as we would
with any other target:
add_executable(my-application app.cpp) target_link_libraries(my-application PRIVATE neo::sqlite3)
Easy Mode: PMM Support¶
PMM is the package package manager, and can be used to control and access
package managers from within CMake scripts. This includes controlling
With PMM, we can automate all of the previous steps into a single line.
For a complete rundown on using PMM to get dependencies via
dds, refer to
the How Do I Use dds in a CMake Project? page.
Using PMM removes the requirement that we write a separate dependencies file,
and we no longer need to invoke
dds build-deps externally, as it is all
handled by PMM.