Lines Matching +full:cmake +full:- +full:args
1 .. _module-pw_build:
3 --------
5 --------
9 by upstream developers for its speed and flexibility. `CMake`_ and `Bazel`_
14 .. _Ninja: https://ninja-build.org/
15 .. _CMake: https://cmake.org/
30 Pigweed development, and is the most tested and feature-rich build system
34 declarations that are used by upstream Pigweed to set some architecture-agnostic
41 ------------
42 .. code-block::
53 ``default_public_deps`` build args. Additionally, they allow defaults to be
54 removed on a per-target basis using ``remove_configs`` and
76 ---------------
77 GN templates for :ref:`Python build automation <docs-python-build>` are
78 described in :ref:`module-pw_build-python`.
85 .. _module-pw_build-facade:
88 ---------
89 In their simplest form, a :ref:`facade<docs-module-structure-facades>` is a GN
99 * ``$target_name``: the public-facing ``pw_source_set``, with a ``public_dep``
104 .. code-block::
113 .. _module-pw_build-python-action:
116 ----------------
149 ``pw_python_action`` evaluates expressions in ``args``, the arguments passed to
151 CMake. Expressions may be passed as a standalone argument or as part of another
170 .. code-block::
176 .. code-block::
201 .. code-block::
203 "--database=<TARGET_FILE_IF_EXISTS(//alpha/bravo)>"
208 .. code-block::
210 "--database=/home/User/project/out/obj/alpha/bravo/bravo.elf"
213 ``--database=`` argument is omitted from the script arguments.
224 .. code-block::
230 .. code-block::
238 .. code-block::
244 args = [
245 "--database",
247 "--binary=<TARGET_FILE(//firmware/images:main)>",
253 --------------
278 .. code-block::
297 ------
329 .. code-block::
342 .. code-block::
367 .. code-block::
379 CMake / Ninja
381 Pigweed's `CMake`_ support is provided primarily for projects that have an
382 existing CMake build and wish to integrate Pigweed without switching to a new
388 .. code-block:: sh
390 …cmake -B out/cmake_host -S "$PW_ROOT" -G Ninja -DCMAKE_TOOLCHAIN_FILE=$PW_ROOT/pw_toolchain/host_c…
398 .. code-block:: sh
400 ninja -C out/cmake_host pw_run_tests.modules
402 :ref:`module-pw_watch` supports CMake, so you can also run
404 .. code-block:: sh
406 pw watch -C out/cmake_host pw_run_tests.modules
408 CMake functions
409 ---------------
410 CMake convenience functions are defined in ``pw_build/pigweed.cmake``.
412 * ``pw_auto_add_simple_module`` -- For modules with only one library,
414 * ``pw_auto_add_module_tests`` -- Create test targets for all tests in a module.
415 * ``pw_add_facade`` -- Declare a module facade.
416 * ``pw_set_backend`` -- Set the backend library to use for a facade.
417 * ``pw_add_module_library`` -- Add a library that is part of a module.
418 * ``pw_add_test`` -- Declare a test target.
420 See ``pw_build/pigweed.cmake`` for the complete documentation of these
424 standard CMake functions, such as ``add_library`` and ``target_link_libraries``.
427 --------------------
428 The CMake build uses CMake cache variables for configuring
429 :ref:`facades<docs-module-structure-facades>` and backends. Cache variables are
430 similar to GN's build args set with ``gn args``. Unlike GN, CMake does not
431 support multi-toolchain builds, so these variables have a single global value
437 persist accross CMake invocations. These variables should be set in one of the
441 target's toolchain file. The toolchain file is provided to ``cmake`` with
442 ``-DCMAKE_TOOLCHAIN_FILE=<toolchain file>``.
443 * Call ``pw_set_backend`` in the top-level ``CMakeLists.txt`` before other
444 CMake code executes.
445 * Set the backend variable at the command line with the ``-D`` option.
447 .. code-block:: sh
449 cmake -B out/cmake_host -S "$PW_ROOT" -G Ninja \
450 -DCMAKE_TOOLCHAIN_FILE=$PW_ROOT/pw_toolchain/host_clang/toolchain.cmake \
451 -Dpw_log_BACKEND=pw_log_basic
454 ``cmake-gui``.
457 ---------------
458 In CMake, the toolchain is configured by setting CMake variables, as described
459 in the `CMake documentation <https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html>`_.
460 These variables are typically set in a toolchain CMake file passed to ``cmake``
461 with the ``-D`` option (``-DCMAKE_TOOLCHAIN_FILE=path/to/file.cmake``).
466 ---------------------
467 The CMake build includes third-party libraries similarly to the GN build. A
468 ``dir_pw_third_party_<library>`` cache variable is defined for each third-party
474 Third-party dependencies are not automatically added to the build. They can be
478 Third party variables are set like any other cache global variable in CMake. It
481 * Set with the CMake ``set`` function in the toolchain file or a
482 ``CMakeLists.txt`` before other CMake code executes.
484 .. code-block:: cmake
488 * Set the variable at the command line with the ``-D`` option.
490 .. code-block:: sh
492 cmake -B out/cmake_host -S "$PW_ROOT" -G Ninja \
493 -DCMAKE_TOOLCHAIN_FILE=$PW_ROOT/pw_toolchain/host_clang/toolchain.cmake \
494 -Ddir_pw_third_party_nanopb=/path/to/nanopb
496 * Set the variable interactively with ``ccmake`` or ``cmake-gui``.
498 Use Pigweed from an existing CMake project
499 ------------------------------------------
500 To use Pigweed libraries form a CMake-based project, simply include the Pigweed
503 .. code-block:: cmake
512 .. code-block:: cmake
519 Bazel is currently very experimental, and only builds for host and ARM Cortex-M
523 file. The built-in Bazel rules ``cc_binary``, ``cc_library``, and ``cc_test``
528 [open source](https://github.com/silvergasp/bazel-embedded) toolchains. The host
532 though slightly more hermetic. The host toolchain is based around clang-11 which
537 .. code-block:: sh
544 The ARM Cortex-M Bazel toolchains are based around gcc-arm-non-eabi and are
545 entirely hermetic. You can target Cortex-M, by using the platforms command line
549 .. code-block:: sh
551 bazel build //:your_target --platforms=@pigweed//pw_build/platforms:cortex_m0
552 bazel build //:your_target --platforms=@pigweed//pw_build/platforms:cortex_m1
553 bazel build //:your_target --platforms=@pigweed//pw_build/platforms:cortex_m3
554 bazel build //:your_target --platforms=@pigweed//pw_build/platforms:cortex_m4
555 bazel build //:your_target --platforms=@pigweed//pw_build/platforms:cortex_m7
557 --platforms=@pigweed//pw_build/platforms:cortex_m4_fpu
559 --platforms=@pigweed//pw_build/platforms:cortex_m7_fpu
570 .. code-block:: python
580 .. code-block:: python
590 .. code-block:: python
611 .. code-block:: python
614 --platforms=@your_repo//build_settings:nucleo_l432kc
620 .. code-block:: python