-
Notifications
You must be signed in to change notification settings - Fork 43
CMake basics
CMake is the powerful cross-platform build system used in gtk-fortran. Each directory of the project containing source code also contains a CMakeLists.txt
script. The gtk-fortran user don't need to know that script language but needs to know a few CMake options to build, test and install gtk-fortran.
- CMake documentation (latest release).
- Ken Martin, Bill Hoffm, Mastering CMake - A Cross-Platform Build System, Kitware, 2010, ISBN 978-1930934313.
- Mastering CMake (online updated version).
Atfer downloading gtk-fortran, in the root of the project you will generally type the following commands to configure, build and install the project:
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
The cmake ..
means CMake must use the main CMakeLists.txt
at the root of the gtk-fortran project.
CMake variables are set by using the syntax -D <variable>=<value>
where -D
means define.
- You can build in Debug mode using
-D CMAKE_BUILD_TYPE=debug
- To change the default install directory from
/usr/local
to/usr
, type:cmake -D CMAKE_INSTALL_DIR=/usr ..
- CMake uses
f95
, which is generally a link toward the default Fortran compiler. You can override that, for example to choose a specific gfortran version or another compiler likeifort
:
$ cmake -D CMAKE_Fortran_COMPILER:FILEPATH=$(which ifort) -D EXCLUDE_PLPLOT=true ..
Note that you must use the same compiler to compile gtk-fortran and your own programs, because the .mod
files are compiler specific.
A few CMake variables are defined in gtk-fortran:
-
NO_BUILD_HL
Set this to disable building the High Level sub-library (includes PLplot and sketcher). -
EXCLUDE_PLPLOT
Set this to disable building the PLplot integration even if PLplot is found:-D EXCLUDE_PLPLOT=true
. It is necessary if PLplot was not compiled with your Fortran compiler. -
INSTALL_EXAMPLES
Set this to install the source code of the examples into${CMAKE_INSTALL_DATAROOTDIR/gtk-fortran/examples<gtkversion>
, this would for example be useful if you were making a binary package of gtk-fortran. -
NO_BUILD_EXAMPLES
Set this to prevent compiling the example programs, also mostly useful for packagers.
- For parallel building use
make -j
ormake --jobs
. In some systems, like FreeBSD, you must give explicitly the number of jobs:make -j 4
- If some examples cause a building error, you can ignore them with:
$ make -i
- Sometimes it can help to clean out the build directory with
$ make clean
. Removing theCMakeCache.txt
file may help in case of error. And remove also any.mod
file that could lie around in the gtk-fortran subdirectories if you have compiled something without using CMake.
Note that you can also use ninja
with CMake:
$ cmake -GNinja ..
$ ninja
You can use CTest to launch and test all the examples from the build
directory (with -VV
to read all the outputs of the examples):
$ ctest -VV
Quickly testing that all examples run can be done with the following options, to launch 4 examples simultaneously and close them after 5 seconds:
$ ctest --timeout 5 -j 4 -VV
Note that in that case, the tests are considered to have all failed because they are interrupted after 5 seconds (most of the examples are using windows that should normally be closed by the user).
You can use a regex to test only the matching examples, e.g. the pixbuf examples:
$ ctest -VV -j 4 -R pixbuf
You can use the -I
option to launch a specific example, for example ctest -I 10
to launch the 10th example, or ctest -I ,,5
to launch one example over five.
Back to Home
- Installation
- My first gtk-fortran application
- Drawing an image in a PNG file (without GUI)
- A program also usable without GUI
- Using Glade3 and gtkf-sketcher (GTK 3)
- Using gtk-fortran as a fpm dependency
- Debugging with GtkInspector
- Learning from examples
- Video tutorials
- How to start my own project from a gtk-fortran example
- git basics
- CMake basics
- Alternatives to CMake
- How to migrate to GTK 4
- How to contribute to gtk-fortran
- How to hack the cfwrapper