Software Developement Tools Introduction to software building

SED & friends Outline

1. an example 2. what is software building? 3. tools 4. about CMake

SED & friends – Introduction to software building 2 1 an example

SED & friends – Introduction to software building 3 - non-portability: works only on a systems, with mpicc shortcut and MPI libraries and headers installed in standard directories - every build, we compile all files

- 0 level: hit the following line: mpicc -Wall -o heat par heat par.c heat.c mat utils.c -lm

- 0.1 level: a script (bash, csh, Zsh, ...) • drawbacks:

Example

• we want to build the parallel program solving heat equation:

SED & friends – Introduction to software building 4 - non-portability: works only on a Unix systems, with mpicc shortcut and MPI libraries and headers installed in standard directories - every build, we compile all files

- 0.1 level: write a script (bash, csh, Zsh, ...) • drawbacks:

Example

• we want to build the parallel program solving heat equation: - 0 level: hit the following line: mpicc -Wall -o heat par heat par.c heat.c mat utils.c -lm

SED & friends – Introduction to software building 4 - non-portability: works only on a Unix systems, with mpicc shortcut and MPI libraries and headers installed in standard directories - every build, we compile all files

• drawbacks:

Example

• we want to build the parallel program solving heat equation: - 0 level: hit the following line: mpicc -Wall -o heat par heat par.c heat.c mat utils.c -lm

- 0.1 level: write a script (bash, csh, Zsh, ...)

SED & friends – Introduction to software building 4 - non-portability: works only on a Unix systems, with mpicc shortcut and MPI libraries and headers installed in standard directories - every build, we compile all files

Example

• we want to build the parallel program solving heat equation: - 0 level: hit the following line: mpicc -Wall -o heat par heat par.c heat.c mat utils.c -lm

- 0.1 level: write a script (bash, csh, Zsh, ...) • drawbacks:

SED & friends – Introduction to software building 4 - every build, we compile all files

Example

• we want to build the parallel program solving heat equation: - 0 level: hit the following line: mpicc -Wall -o heat par heat par.c heat.c mat utils.c -lm

- 0.1 level: write a script (bash, csh, Zsh, ...) • drawbacks: - non-portability: works only on a Unix systems, with mpicc shortcut and MPI libraries and headers installed in standard directories

SED & friends – Introduction to software building 4 Example

• we want to build the parallel program solving heat equation: - 0 level: hit the following line: mpicc -Wall -o heat par heat par.c heat.c mat utils.c -lm

- 0.1 level: write a script (bash, csh, Zsh, ...) • drawbacks: - non-portability: works only on a Unix systems, with mpicc shortcut and MPI libraries and headers installed in standard directories - every build, we compile all files

SED & friends – Introduction to software building 4 - /usr/include/mpi is hardcoded _¨ - use auto configuration tricks: pkg-config - How to build for non unix OSes ?

• drawbacks:

Example

• 0.5 level: write a Makefile MPICC = mpicc CFLAGS = -Wall -O3 INCLUDE = -I. -I/usr/include/mpi HFILES = heat.h CFILES_PAR = heat.c heat_par.c mat_utils.c LIB_PAR =-lm EXEC_PAR= heat_par

.SUFFIXES: .c .o

${EXEC_PAR}: ${CFILES_PAR:.c=.o} ${MPICC} -o ${EXEC_PAR} ${CFILES_PAR:.c=.o} .c.o: ${CC} ${CFLAGS} ${INCLUDE} -c $*.c -o $*.o

SED & friends – Introduction to software building 5 - /usr/include/mpi is hardcoded _¨ - use auto configuration tricks: pkg-config - How to build for non unix OSes ?

Example

• 0.5 level: write a Makefile MPICC = mpicc CFLAGS = -Wall -O3 INCLUDE = -I. -I/usr/include/mpi HFILES = heat.h CFILES_PAR = heat.c heat_par.c mat_utils.c LIB_PAR =-lm EXEC_PAR= heat_par

.SUFFIXES: .c .o

${EXEC_PAR}: ${CFILES_PAR:.c=.o} ${MPICC} -o ${EXEC_PAR} ${CFILES_PAR:.c=.o} .c.o: ${CC} ${CFLAGS} ${INCLUDE} -c $*.c -o $*.o • drawbacks:

SED & friends – Introduction to software building 5 - use auto configuration tricks: pkg-config - How to build for non unix OSes ?

Example

• 0.5 level: write a Makefile MPICC = mpicc CFLAGS = -Wall -O3 INCLUDE = -I. -I/usr/include/mpi HFILES = heat.h CFILES_PAR = heat.c heat_par.c mat_utils.c LIB_PAR =-lm EXEC_PAR= heat_par

.SUFFIXES: .c .o

${EXEC_PAR}: ${CFILES_PAR:.c=.o} ${MPICC} -o ${EXEC_PAR} ${CFILES_PAR:.c=.o} .c.o: ${CC} ${CFLAGS} ${INCLUDE} -c $*.c -o $*.o • drawbacks: - /usr/include/mpi is hardcoded _¨

SED & friends – Introduction to software building 5 - How to build for non unix OSes ?

Example

• 0.5 level: write a Makefile MPICC = mpicc CFLAGS = -Wall -O3 INCLUDE = -I. -I/usr/include/mpi HFILES = heat.h CFILES_PAR = heat.c heat_par.c mat_utils.c LIB_PAR =-lm EXEC_PAR= heat_par

.SUFFIXES: .c .o

${EXEC_PAR}: ${CFILES_PAR:.c=.o} ${MPICC} -o ${EXEC_PAR} ${CFILES_PAR:.c=.o} .c.o: ${CC} ${CFLAGS} ${INCLUDE} -c $*.c -o $*.o • drawbacks: - /usr/include/mpi is hardcoded _¨ - use auto configuration tricks: pkg-config

SED & friends – Introduction to software building 5 Example

• 0.5 level: write a Makefile MPICC = mpicc CFLAGS = -Wall -O3 INCLUDE = -I. -I/usr/include/mpi HFILES = heat.h CFILES_PAR = heat.c heat_par.c mat_utils.c LIB_PAR =-lm EXEC_PAR= heat_par

.SUFFIXES: .c .o

${EXEC_PAR}: ${CFILES_PAR:.c=.o} ${MPICC} -o ${EXEC_PAR} ${CFILES_PAR:.c=.o} .c.o: ${CC} ${CFLAGS} ${INCLUDE} -c $*.c -o $*.o • drawbacks: - /usr/include/mpi is hardcoded _¨ - use auto configuration tricks: pkg-config - How to build for non unix OSes ?

SED & friends – Introduction to software building 5 Example of CMakeLists.txt cmake_minimum_required (VERSION 2.8) project (Heat) find_package(MPI) if(MPI_FOUND) include_directories(${MPI_INCLUDE_PATH}) endif(MPI_FOUND) set(HEAT_PAR_SOURCES heat_par.c heat.c mat_utils.c) add_executable(patcHeatPar ${HEAT_PAR_SOURCES} mat_utils.h heat.h) target_link_libraries(patcHeatPar ${MPI_LIBRARIES} m)

# enable testing enable_testing() add_test(patcHeatPar4 ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ./patcHeatPar 10 10 200 2 2 0)

SED & friends – Introduction to software building 6 2 what is software building?

SED & friends – Introduction to software building 7 - install program must be an easy process - possible use of binaries packages could accelerate and simplify installation

- enforce software portability - detect the building environment by auto configuration - use native tools to build the software (best integration to the OS) - add tests to check the build • user’s POV:

Why use a building tool ?

• developer’s POV:

SED & friends – Introduction to software building 8 - install program must be an easy process - possible use of binaries packages could accelerate and simplify installation

- detect the building environment by auto configuration - use native tools to build the software (best integration to the OS) - add tests to check the build • user’s POV:

Why use a building tool ?

• developer’s POV: - enforce software portability

SED & friends – Introduction to software building 8 - install program must be an easy process - possible use of binaries packages could accelerate and simplify installation

- use native tools to build the software (best integration to the OS) - add tests to check the build • user’s POV:

Why use a building tool ?

• developer’s POV: - enforce software portability - detect the building environment by auto configuration

SED & friends – Introduction to software building 8 - install program must be an easy process - possible use of binaries packages could accelerate and simplify installation

- add tests to check the build • user’s POV:

Why use a building tool ?

• developer’s POV: - enforce software portability - detect the building environment by auto configuration - use native tools to build the software (best integration to the OS)

SED & friends – Introduction to software building 8 - install program must be an easy process - possible use of binaries packages could accelerate and simplify installation

• user’s POV:

Why use a building tool ?

• developer’s POV: - enforce software portability - detect the building environment by auto configuration - use native tools to build the software (best integration to the OS) - add tests to check the build

SED & friends – Introduction to software building 8 - install program must be an easy process - possible use of binaries packages could accelerate and simplify installation

Why use a building tool ?

• developer’s POV: - enforce software portability - detect the building environment by auto configuration - use native tools to build the software (best integration to the OS) - add tests to check the build • user’s POV:

SED & friends – Introduction to software building 8 - possible use of binaries packages could accelerate and simplify installation

Why use a building tool ?

• developer’s POV: - enforce software portability - detect the building environment by auto configuration - use native tools to build the software (best integration to the OS) - add tests to check the build • user’s POV: - install program must be an easy process

SED & friends – Introduction to software building 8 Why use a building tool ?

• developer’s POV: - enforce software portability - detect the building environment by auto configuration - use native tools to build the software (best integration to the OS) - add tests to check the build • user’s POV: - install program must be an easy process - possible use of binaries packages could accelerate and simplify installation

SED & friends – Introduction to software building 8 - languages - compilers - libraries implementations - operating systems or distributions of an OS - programming tools

• an effective building tool must manage different:

• possibly embed some testing process • integrate some packaging systems

Requirements

• building is than compilation

SED & friends – Introduction to software building 9 - languages - compilers - libraries implementations - operating systems or distributions of an OS - programming tools • possibly embed some testing process • integrate some packaging systems

Requirements

• building is more than compilation • an effective building tool must manage different:

SED & friends – Introduction to software building 9 - compilers - libraries implementations - operating systems or distributions of an OS - programming tools • possibly embed some testing process • integrate some packaging systems

Requirements

• building is more than compilation • an effective building tool must manage different: - languages

SED & friends – Introduction to software building 9 - libraries implementations - operating systems or distributions of an OS - programming tools • possibly embed some testing process • integrate some packaging systems

Requirements

• building is more than compilation • an effective building tool must manage different: - languages - compilers

SED & friends – Introduction to software building 9 - operating systems or distributions of an OS - programming tools • possibly embed some testing process • integrate some packaging systems

Requirements

• building is more than compilation • an effective building tool must manage different: - languages - compilers - libraries implementations

SED & friends – Introduction to software building 9 - programming tools • possibly embed some testing process • integrate some packaging systems

Requirements

• building is more than compilation • an effective building tool must manage different: - languages - compilers - libraries implementations - operating systems or distributions of an OS

SED & friends – Introduction to software building 9 • possibly embed some testing process • integrate some packaging systems

Requirements

• building is more than compilation • an effective building tool must manage different: - languages - compilers - libraries implementations - operating systems or distributions of an OS - programming tools

SED & friends – Introduction to software building 9 • integrate some packaging systems

Requirements

• building is more than compilation • an effective building tool must manage different: - languages - compilers - libraries implementations - operating systems or distributions of an OS - programming tools • possibly embed some testing process

SED & friends – Introduction to software building 9 Requirements

• building is more than compilation • an effective building tool must manage different: - languages - compilers - libraries implementations - operating systems or distributions of an OS - programming tools • possibly embed some testing process • integrate some packaging systems

SED & friends – Introduction to software building 9 3 tools

SED & friends – Introduction to software building 10 • Maven for Java • GNU autotools: efficient and powerful; most widely used tool in free software. Limited to Unix (POSIX) environments • CMake: complete tools suite. Cross-platform (Unix, MacOS, Windows) • Scons: smart tool written in Python, also cross-platform

Tools

: basic, robust tool but no cross-platform

SED & friends – Introduction to software building 11 • GNU autotools: efficient and powerful; most widely used tool in free software. Limited to Unix (POSIX) environments • CMake: complete tools suite. Cross-platform (Unix, MacOS, Windows) • Scons: smart tool written in Python, also cross-platform

Tools

• make: basic, robust tool but no cross-platform • Maven for Java

SED & friends – Introduction to software building 11 • CMake: complete tools suite. Cross-platform (Unix, MacOS, Windows) • Scons: smart tool written in Python, also cross-platform

Tools

• make: basic, robust tool but no cross-platform • Maven for Java • GNU autotools: efficient and powerful; most widely used tool in free software. Limited to Unix (POSIX) environments

SED & friends – Introduction to software building 11 • Scons: smart tool written in Python, also cross-platform

Tools

• make: basic, robust tool but no cross-platform • Maven for Java • GNU autotools: efficient and powerful; most widely used tool in free software. Limited to Unix (POSIX) environments • CMake: complete tools suite. Cross-platform (Unix, MacOS, Windows)

SED & friends – Introduction to software building 11 Tools

• make: basic, robust tool but no cross-platform • Maven for Java • GNU autotools: efficient and powerful; most widely used tool in free software. Limited to Unix (POSIX) environments • CMake: complete tools suite. Cross-platform (Unix, MacOS, Windows) • Scons: smart tool written in Python, also cross-platform

SED & friends – Introduction to software building 11 4 about CMake

SED & friends – Introduction to software building 12 - CMake: makefiles generator - CTest: testing utility - CPack: package builder - CDash: web interface to present a summary of builds/tests

• integrated tools suite for building software

• cross-platform, and works with IDEs (Eclipse, Visual, etc.) • support for C, C++, Fortran • graphical user interface (cmake-gui) and text interface (ccmake)

CMake: features

• created in 1999 by ITK (mimic pcmake, a build tool for VTK)

SED & friends – Introduction to software building 13 - CMake: makefiles generator - CTest: testing utility - CPack: package builder - CDash: web interface to present a summary of builds/tests • cross-platform, and works with IDEs (Eclipse, Visual, etc.) • support for C, C++, Fortran • graphical user interface (cmake-gui) and text interface (ccmake)

CMake: features

• created in 1999 by ITK (mimic pcmake, a build tool for VTK) • integrated tools suite for building software

SED & friends – Introduction to software building 13 - CTest: testing utility - CPack: package builder - CDash: web interface to present a summary of builds/tests • cross-platform, and works with IDEs (Eclipse, Visual, etc.) • support for C, C++, Fortran • graphical user interface (cmake-gui) and text interface (ccmake)

CMake: features

• created in 1999 by ITK (mimic pcmake, a build tool for VTK) • integrated tools suite for building software - CMake: makefiles generator

SED & friends – Introduction to software building 13 - CPack: package builder - CDash: web interface to present a summary of builds/tests • cross-platform, and works with IDEs (Eclipse, Visual, etc.) • support for C, C++, Fortran • graphical user interface (cmake-gui) and text interface (ccmake)

CMake: features

• created in 1999 by ITK (mimic pcmake, a build tool for VTK) • integrated tools suite for building software - CMake: makefiles generator - CTest: testing utility

SED & friends – Introduction to software building 13 - CDash: web interface to present a summary of builds/tests • cross-platform, and works with IDEs (Eclipse, Visual, etc.) • support for C, C++, Fortran • graphical user interface (cmake-gui) and text interface (ccmake)

CMake: features

• created in 1999 by ITK (mimic pcmake, a build tool for VTK) • integrated tools suite for building software - CMake: makefiles generator - CTest: testing utility - CPack: package builder

SED & friends – Introduction to software building 13 • cross-platform, and works with IDEs (Eclipse, Visual, etc.) • support for C, C++, Fortran • graphical user interface (cmake-gui) and text interface (ccmake)

CMake: features

• created in 1999 by ITK (mimic pcmake, a build tool for VTK) • integrated tools suite for building software - CMake: makefiles generator - CTest: testing utility - CPack: package builder - CDash: web interface to present a summary of builds/tests

SED & friends – Introduction to software building 13 • support for C, C++, Fortran • graphical user interface (cmake-gui) and text interface (ccmake)

CMake: features

• created in 1999 by ITK (mimic pcmake, a build tool for VTK) • integrated tools suite for building software - CMake: makefiles generator - CTest: testing utility - CPack: package builder - CDash: web interface to present a summary of builds/tests • cross-platform, and works with IDEs (Eclipse, Visual, etc.)

SED & friends – Introduction to software building 13 • graphical user interface (cmake-gui) and text interface (ccmake)

CMake: features

• created in 1999 by ITK (mimic pcmake, a build tool for VTK) • integrated tools suite for building software - CMake: makefiles generator - CTest: testing utility - CPack: package builder - CDash: web interface to present a summary of builds/tests • cross-platform, and works with IDEs (Eclipse, Visual, etc.) • support for C, C++, Fortran

SED & friends – Introduction to software building 13 CMake: features

• created in 1999 by ITK (mimic pcmake, a build tool for VTK) • integrated tools suite for building software - CMake: makefiles generator - CTest: testing utility - CPack: package builder - CDash: web interface to present a summary of builds/tests • cross-platform, and works with IDEs (Eclipse, Visual, etc.) • support for C, C++, Fortran • graphical user interface (cmake-gui) and text interface (ccmake)

SED & friends – Introduction to software building 13 - compiler supports (GCC, ICC, MSVC, XCode, etc.) - file operations (copy, move, delete, ) - system inspection (headers, libraries)

• Run: mkdir build && build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles • you can tweak some options in the cache make edit cache • compiles your project with color and percentages: make • run some : make test or ctest --parallel 9 • install the software from sources: make install • create a package: make package

CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts:

SED & friends – Introduction to software building 14 - file operations (copy, move, delete, mkdir) - system inspection (headers, libraries)

• Run: mkdir build && cd build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles • you can tweak some options in the cache make edit cache • compiles your project with color and percentages: make • run some test: make test or ctest --parallel 9 • install the software from sources: make install • create a package: make package

CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts: - compiler supports (GCC, ICC, MSVC, XCode, etc.)

SED & friends – Introduction to software building 14 - system inspection (headers, libraries)

• Run: mkdir build && cd build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles • you can tweak some options in the cache make edit cache • compiles your project with color and percentages: make • run some test: make test or ctest --parallel 9 • install the software from sources: make install • create a package: make package

CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts: - compiler supports (GCC, ICC, MSVC, XCode, etc.) - file operations (copy, move, delete, mkdir)

SED & friends – Introduction to software building 14 • Run: mkdir build && cd build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles • you can tweak some options in the cache make edit cache • compiles your project with color and percentages: make • run some test: make test or ctest --parallel 9 • install the software from sources: make install • create a package: make package

CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts: - compiler supports (GCC, ICC, MSVC, XCode, etc.) - file operations (copy, move, delete, mkdir) - system inspection (headers, libraries)

SED & friends – Introduction to software building 14 • you can tweak some options in the cache make edit cache • compiles your project with color and percentages: make • run some test: make test or ctest --parallel 9 • install the software from sources: make install • create a package: make package

CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts: - compiler supports (GCC, ICC, MSVC, XCode, etc.) - file operations (copy, move, delete, mkdir) - system inspection (headers, libraries)

• Run: mkdir build && cd build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles

SED & friends – Introduction to software building 14 • compiles your project with color and percentages: make • run some test: make test or ctest --parallel 9 • install the software from sources: make install • create a package: make package

CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts: - compiler supports (GCC, ICC, MSVC, XCode, etc.) - file operations (copy, move, delete, mkdir) - system inspection (headers, libraries)

• Run: mkdir build && cd build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles • you can tweak some options in the cache make edit cache

SED & friends – Introduction to software building 14 • run some test: make test or ctest --parallel 9 • install the software from sources: make install • create a package: make package

CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts: - compiler supports (GCC, ICC, MSVC, XCode, etc.) - file operations (copy, move, delete, mkdir) - system inspection (headers, libraries)

• Run: mkdir build && cd build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles • you can tweak some options in the cache make edit cache • compiles your project with color and percentages: make

SED & friends – Introduction to software building 14 • install the software from sources: make install • create a package: make package

CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts: - compiler supports (GCC, ICC, MSVC, XCode, etc.) - file operations (copy, move, delete, mkdir) - system inspection (headers, libraries)

• Run: mkdir build && cd build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles • you can tweak some options in the cache make edit cache • compiles your project with color and percentages: make • run some test: make test or ctest --parallel 9

SED & friends – Introduction to software building 14 • create a package: make package

CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts: - compiler supports (GCC, ICC, MSVC, XCode, etc.) - file operations (copy, move, delete, mkdir) - system inspection (headers, libraries)

• Run: mkdir build && cd build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles • you can tweak some options in the cache make edit cache • compiles your project with color and percentages: make • run some test: make test or ctest --parallel 9 • install the software from sources: make install

SED & friends – Introduction to software building 14 CMake: philosophy

• developer writes one or several CMakeLists.txt files in a language which abstracts: - compiler supports (GCC, ICC, MSVC, XCode, etc.) - file operations (copy, move, delete, mkdir) - system inspection (headers, libraries)

• Run: mkdir build && cd build && cmake .. CMake processes all subdirectory and their CMakeLists.txt and generates Makefiles • you can tweak some options in the cache make edit cache • compiles your project with color and percentages: make • run some test: make test or ctest --parallel 9 • install the software from sources: make install • create a package: make package

SED & friends – Introduction to software building 14 • it can define variables: set(var value); message(STATUS ${var}) • CMake has control statements: foreach, if, while, function • support some data structures: list, string • support for functions! beware of scope of variables relative to directory • support modularity trough CMakeModules files • system inspection: find library, find program, find package, • case insensitive, except for constant argument of commands MESSAGE(STATUS"peekaboo")

A few words about the syntax

• CMake is a ’scripting language’; test it with cmake -P script.cmake

SED & friends – Introduction to software building 15 • CMake has control statements: foreach, if, while, function • support some data structures: list, string • support for functions! beware of scope of variables relative to directory • support modularity trough CMakeModules files • system inspection: find library, find program, find package, • case insensitive, except for constant argument of commands MESSAGE(STATUS"peekaboo")

A few words about the syntax

• CMake is a ’scripting language’; test it with cmake -P script.cmake • it can define variables: set(var value); message(STATUS ${var})

SED & friends – Introduction to software building 15 • support some data structures: list, string • support for functions! beware of scope of variables relative to directory • support modularity trough CMakeModules files • system inspection: find library, find program, find package, • case insensitive, except for constant argument of commands MESSAGE(STATUS"peekaboo")

A few words about the syntax

• CMake is a ’scripting language’; test it with cmake -P script.cmake • it can define variables: set(var value); message(STATUS ${var}) • CMake has control statements: foreach, if, while, function

SED & friends – Introduction to software building 15 • support for functions! beware of scope of variables relative to directory • support modularity trough CMakeModules files • system inspection: find library, find program, find package, • case insensitive, except for constant argument of commands MESSAGE(STATUS"peekaboo")

A few words about the syntax

• CMake is a ’scripting language’; test it with cmake -P script.cmake • it can define variables: set(var value); message(STATUS ${var}) • CMake has control statements: foreach, if, while, function • support some data structures: list, string

SED & friends – Introduction to software building 15 • support modularity trough CMakeModules files • system inspection: find library, find program, find package, • case insensitive, except for constant argument of commands MESSAGE(STATUS"peekaboo")

A few words about the syntax

• CMake is a ’scripting language’; test it with cmake -P script.cmake • it can define variables: set(var value); message(STATUS ${var}) • CMake has control statements: foreach, if, while, function • support some data structures: list, string • support for functions! beware of scope of variables relative to directory

SED & friends – Introduction to software building 15 • system inspection: find library, find program, find package, • case insensitive, except for constant argument of commands MESSAGE(STATUS"peekaboo")

A few words about the syntax

• CMake is a ’scripting language’; test it with cmake -P script.cmake • it can define variables: set(var value); message(STATUS ${var}) • CMake has control statements: foreach, if, while, function • support some data structures: list, string • support for functions! beware of scope of variables relative to directory • support modularity trough CMakeModules files

SED & friends – Introduction to software building 15 • case insensitive, except for constant argument of commands MESSAGE(STATUS"peekaboo")

A few words about the syntax

• CMake is a ’scripting language’; test it with cmake -P script.cmake • it can define variables: set(var value); message(STATUS ${var}) • CMake has control statements: foreach, if, while, function • support some data structures: list, string • support for functions! beware of scope of variables relative to directory • support modularity trough CMakeModules files • system inspection: find library, find program, find package,

SED & friends – Introduction to software building 15 A few words about the syntax

• CMake is a ’scripting language’; test it with cmake -P script.cmake • it can define variables: set(var value); message(STATUS ${var}) • CMake has control statements: foreach, if, while, function • support some data structures: list, string • support for functions! beware of scope of variables relative to directory • support modularity trough CMakeModules files • system inspection: find library, find program, find package, • case insensitive, except for constant argument of commands MESSAGE(STATUS"peekaboo")

SED & friends – Introduction to software building 15 • write the following somme.cmake cmake_minimum_required(VERSION 2.8) set(somme 0) set(n $ENV{N}) foreach(i RANGE 1 ${n}) math( somme"${somme}+${i}*${i}") endforeach() message(STATUS ${somme})

• run CMake: env N=10 cmake -P somme.cmake -- 385

Bonus: doing maths with CMake :-)

• we want to compute

10 X (10 + 1) · (2 · 10 + 1) · 10 i2 = = 385 6 i=1

SED & friends – Introduction to software building 16 • run CMake: env N=10 cmake -P somme.cmake -- 385

Bonus: doing maths with CMake :-)

• we want to compute

10 X (10 + 1) · (2 · 10 + 1) · 10 i2 = = 385 6 i=1 • write the following somme.cmake cmake_minimum_required(VERSION 2.8) set(somme 0) set(n $ENV{N}) foreach(i RANGE 1 ${n}) math(EXPR somme"${somme}+${i}*${i}") endforeach() message(STATUS ${somme})

SED & friends – Introduction to software building 16 Bonus: doing maths with CMake :-)

• we want to compute

10 X (10 + 1) · (2 · 10 + 1) · 10 i2 = = 385 6 i=1 • write the following somme.cmake cmake_minimum_required(VERSION 2.8) set(somme 0) set(n $ENV{N}) foreach(i RANGE 1 ${n}) math(EXPR somme"${somme}+${i}*${i}") endforeach() message(STATUS ${somme})

• run CMake: env N=10 cmake -P somme.cmake -- 385

SED & friends – Introduction to software building 16