The CMakeLists.txt is the last file we will study. To explain all the possibilities offered by CMake, a dedicated tutorial would be needed, so here, we will just provide a summary to get started.
CMake allows (among other things) generating a Makefile usable by Make. Make is a tool that allows automating the compilation of C/C++ projects.
Here is an example of a Makefile written by hand:
We can define variables (for example LEX_INPUT = analyse.l) and then define tasks to be performed.
For example:
We have a task that will generate a file called $(YACC_OUTPUT). This task depends on the file $(YACC_INPUT). If this file has been modified in two runs of make, then the task will be launched. The task consists of two lines of commands (just below: mkdir and bison).
All of this represents a dependency graph with the first task as the root:
This task generates the file $(GCC_OUTPUT). This task depends on the files $(LEX_OUTPUT), $(YACC_OUTPUT), and $(OTHER_OUTPUT).
To summarize, we can represent this makefile as follows:
For a project with a few files, it is possible to write the makefile by hand, but for a project like Arcane, it is necessary to use a third-party tool like CMake.
CMake, in turn, will use CMakeLists.txt files to generate makefiles. CMakeLists.txt contains the necessary information to build this makefile.
Here is the CMakeLists.txt provided by arcane_template:
Let's start:
This first line requests the presence of CMake version 3.16 or higher. This ensures that CMake can recognize all the commands we give it.
We give the name of the project and the language it is written in (CXX = C++).
Our project needs Arcane installed (see the next section to tell CMake where Arcane is installed).
We also give the different files that will compose our executable.
We ask CMake to generate the file SayHello_axl.h. We provide the position of the file SayHello.axl as an argument (without the .axl extension). Here, SayHello.axl is in the root of our project, so we just need to put SayHello.
We add the Arcane libraries for our project.
We include all the source files.
We copy the .config into the build directory.