You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmake.rst 2.9KB

3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. .. highlight:: cmake
  2. Using ``dds`` in a CMake Project
  3. ################################
  4. One of ``dds``'s primary goals is to inter-operate with other build systems
  5. cleanly. Because of CMakes ubiquity, ``dds`` includes built-in support for
  6. emitting files that can be imported into CMake.
  7. .. seealso::
  8. Before reading this page, be sure to read the :ref:`build-deps.gen-libman`
  9. section of the :doc:`build-deps` page, which will discuss how to use the
  10. ``dds build-deps`` subcommand.
  11. .. seealso::
  12. This page presents an involved and detailed process for importing
  13. dependencies, but there's also an *easy mode* for a one-line solution. See:
  14. :doc:`/howto/cmake`.
  15. .. _PMM: https://github.com/vector-of-bool/PMM
  16. Generating a CMake Import File
  17. ******************************
  18. ``build-deps`` accepts an ``--lmi-path`` argument, but also accepts a
  19. ``--cmake=<path>`` argument that serves a similar purpose: It will write a CMake
  20. file to ``<path>`` that can be ``include()``'d into a CMake project:
  21. .. code-block:: bash
  22. $ dds build-deps "neo-sqlite3^0.2.0" --cmake=deps.cmake
  23. This will write a file ``./deps.cmake`` that we can ``include()`` from a CMake
  24. project, which will then expose the ``neo-sqlite3`` package as a set of imported
  25. targets.
  26. Using the CMake Import File
  27. ===========================
  28. Once we have generated the CMake import file using ``dds build-deps``, we can
  29. simply import it in our ``CMakeLists.txt``::
  30. include(deps.cmake)
  31. Like with ``dds``, CMake wants us to explicitly declare how our build targets
  32. *use* other libraries. When we ``include()`` the generated CMake file, it will
  33. generate ``IMPORTED`` targets that can be linked against.
  34. In ``dds`` (and in libman), a library is identified by a combination of
  35. *namespace* and *name*, joined together with a slash ``/`` character. This
  36. *qualified name* of a library is decided by the original package author, and
  37. should be documented. In the case of ``neo-sqlite3``, the only library is
  38. ``neo/sqlite3``.
  39. When the generated import file imports a library, it creates a qualified name
  40. using a double-colon "``::``" instead of a slash. As such, our ``neo/sqlite3``
  41. is imported in CMake as ``neo::sqlite3``. We can link against it as we would
  42. with any other target::
  43. add_executable(my-application app.cpp)
  44. target_link_libraries(my-application PRIVATE neo::sqlite3)
  45. .. _cmake.pmm:
  46. *Easy* Mode: PMM Support
  47. ************************
  48. `PMM`_ is the *package package manager*, and can be used to control and access
  49. package managers from within CMake scripts. This includes controlling ``dds``.
  50. With PMM, we can automate all of the previous steps into a single line.
  51. For a complete rundown on using PMM to get dependencies via ``dds``, refer to
  52. the :doc:`/howto/cmake` page.
  53. Using PMM removes the requirement that we write a separate dependencies file,
  54. and we no longer need to invoke ``dds build-deps`` externally, as it is all
  55. handled by PMM.