Skip to content

Commit

Permalink
update tips-and-tricks episode
Browse files Browse the repository at this point in the history
  • Loading branch information
code4yonglei committed Sep 13, 2024
1 parent fc43f49 commit 4f59934
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions content/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ In this workshop, you will learn
.. fetch-content
.. python-bindings
tips-and-tricks
additional-topics


.. toctree::

Check warning on line 56 in content/index.rst

View workflow job for this annotation

GitHub Actions / Build

toctree contains reference to nonexisting document '.. environment'

Check warning on line 56 in content/index.rst

View workflow job for this annotation

GitHub Actions / Build

toctree contains reference to nonexisting document '.. cxx-fortran'

Check warning on line 56 in content/index.rst

View workflow job for this annotation

GitHub Actions / Build

toctree contains reference to nonexisting document '.. environment'

Check warning on line 56 in content/index.rst

View workflow job for this annotation

GitHub Actions / Build

toctree contains reference to nonexisting document '.. cxx-fortran'

Check warning on line 56 in content/index.rst

View workflow job for this annotation

GitHub Actions / Build

toctree contains reference to nonexisting document '.. environment'

Check warning on line 56 in content/index.rst

View workflow job for this annotation

GitHub Actions / Build

toctree contains reference to nonexisting document '.. cxx-fortran'
Expand Down
30 changes: 30 additions & 0 deletions content/tips-and-tricks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,36 @@ You can collect related CMake-code into a file called ``my_lengthy_code.cmake``
Variables vs. targets
---------------------


In :ref:`targets` we have motivated why targets are preferable over variables.

When you portion your project into modules, then variable declaration impose an order and the risk is high that somebody will not know about the implicit order and reorder modules one day and the behavior will change.

Try to minimize the use of user-defined variables. They can point to a sub-optimal solution and a better, more state-less, declarative, solution may exist.



Functions and macros
--------------------


**Functions** and **macros** are built on top of the basic built-in commands and are either CMake- or user-defined. These prove useful to avoid repetition in your CMake scripts. The difference between a function and a macro is their **scope**:

#. Functions have their own scope: variables defined inside a function are not propagated back to the caller.
#. Macros do not have their own scope: variables from the parent scope can be modified and new variables in the parent scope can be set.

**Prefer functions over macros to minimize side-effects**.











Expand Down

0 comments on commit 4f59934

Please sign in to comment.