Dune offers a simplified build system, where all flags are added to all targets and all libraries are linked to all targets. You can enable the feature
by calling :ref:`dune_enable_all_packages` in the top-level :code:`CMakeLists.txt` file of your project, before you add any subdirectories.
This will modify all targets in the directory of the :code:`CMakeLists.txt`, where you put this, and also in all
subdirectories. The compile flags for all found external packages are added to those targets and the target is
linked against all found external libraries.
To use this while using custom external packages, you have to register your flags to the mechansim.
Also, some special care has to be given, if your module does build one or more library which targets within the module do link against.
Carefully read the followinf documentation in those cases:
* :ref:`dune_enable_all_packages`
* :ref:`dune_register_package_flags`
* :ref:`dune_library_add_sources`
.. _compiler:
How do I change my compiler and compiler flags?
===============================================
In general, there are multiple ways to do this:
* Setting the CMake variables :ref:`CMAKE_C_COMPILER` and :ref:`CMAKE_CXX_COMPILER` resp. from the opts file
* Setting those variables within the project with the :code:`set` command
* Setting the environment variables :code:`CC`, :code:`CXX` etc.
The first option is the recommended way. Whenever you change your compiler, you should delete all build
directories. For some CMake versions, there is a known CMake bug, that requires you to give an absolute path
to your compiler, but Dune will issue a warning, if you violate that.
You can modify your default compiler flags by setting the variables
:ref:`CMAKE_C_FLAGS` and :ref:`CMAKE_CXX_FLAGS` in your opts file.
.. _symlink:
How should I handle ini and grid files in an out-of-source-build setup?
Such files are under version control, but they are needed in the build directory.
There are some CMake functions targetting this issue:
* :ref:`dune_symlink_to_source_tree`
* :ref:`dune_symlink_to_source_files`
* :ref:`dune_add_copy_command`
* :ref:`dune_add_copy_dependency`
* :ref:`dune_add_copy_target`
The simplest way to solve the problem is to set the variable :ref:`DUNE_SYMLINK_TO_SOURCE_TREE` to your opts file.
This will execute :ref:`dune_symlink_to_source_tree` in your top-level :code:`CMakeLists.txt`. This will add a symlink
:code:`src_dir` to all subdirectories of the build directory, which points to the corresponding directory of the source
tree. This will only work on platforms that support symlinking.
.. _ides:
How do I use CMake with IDEs?
=============================
As already said, CMake is merely a build system generator with multiple backends (called a generator). Using IDEs requires
a different generator. Check :code:`cmake --help` for a list of generators. You can then add the :code:`-G` to the :code:`CMAKE_FLAGS` in your opts file.
Note that the generator name has to match character by character, including case and spaces.
.. _cxxflags:
I usually modify my CXXFLAGS upon calling make. How can I do this in CMake?