33
Systèmes de construction logicielle Introduction à cmake F. Langrognet F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 1 / 33

Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Systèmes de construction logicielleIntroduction à cmake

F. Langrognet

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 1 / 33

Page 2: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 2 / 33

Page 3: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 3 / 33

Page 4: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Objectifs des systèmes de construction logicielle

DéfinitionLes systèmes de construction logicielle (build systems ou encore moteurde production) sont des logiciels dont l’objectif principal estd’automatiser, directement ou indirectement, le processus decompilation d’un code source voire la distribution des produits logiciels.

Wikipedia :Un moteur de production est un logiciel dont la fonction principaleconsiste à automatiser l’ensemble des actions (préprocessing,compilation, éditions des liens, etc.) contribuant, à partir de donnéessources, à la production d’un ensemble logiciel opérationnel.

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 4 / 33

Page 5: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Compilation, éditions de liens

Processus

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 5 / 33

Page 6: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Pourquoi utiliser un systeme de constructionlogicielle ?

Quelques motivations...

Pouvoir compiler, construire l’exécutable dans des contextes différents(OS, compilateurs, ...)

Ne recompiler que le strict minimum

Disposer d’outils complémentaires : création de packages (linux ouMac), ou d’installateurs pour windows

Liens avec les IDELes principaux IDE intègrent certains de ces outils :

KDevelop

Eclipse CDT

Visual Studio

Code : :Blocks

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 6 / 33

Page 7: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 7 / 33

Page 8: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 8 / 33

Page 9: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

cmakecmake

Logiciel de construction logicielle

multilangage

multi-OS

licence libre

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 9 / 33

Page 10: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

cmake - Principe général

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 10 / 33

Page 11: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 11 / 33

Page 12: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Langage de cmake

Langage cmakecmake possède son propre langage (fichiers CMakeLists.txt) avec :

variables

listes

conditions : IF

boucles : FOREACH

Syntaxe# Ceci est un commentairecommand(argument1 argument2 ... argumentN)COMMAND(argument1 argument2 ... argumentN)

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 12 / 33

Page 13: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Utilisation de cmake

cmake par défautUne fois les fichiers CMakeLists.txt créés, il suffit de lancer cmake :$ cmake .

Par défaut, un Makefile sera crééIl suffit ensuite de taper les commandes suivantes pour construire et installerle projet :$ make$make install

cmake : générateur de configuration pour IDESyntaxe :$ cmake . -G <generator>

Exemples :$ cmake . -G "KDevelop3"$ cmake . -G "CodeBlocks"

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 13 / 33

Page 14: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 14 / 33

Page 15: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

makefile - makeLe couple makefile, make

Les Makefiles sont des fichiers utilisés par le programme make pour exécuterun ensemble d’actions, comme la compilation d’un projet, l’archivage dedocument, la mise à jour de site, . . .

Exemple de makefile

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 15 / 33

Page 16: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Comment créer des makefiles ?

A la main

Avec les autotools (1990)

Avec des "nouveaux" générateurs

I imakeI qmakeI nmakeI cmake (1999)

autotools

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 16 / 33

Page 17: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 17 / 33

Page 18: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 18 / 33

Page 19: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Exemple 1 : Construction d’un simple exécutable

Arborescence du projet

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 19 / 33

Page 20: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Exemple 1

CMakeLists.txt

Construction$ cmake .$ makeCréation de l’exécutable projet_population

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 20 / 33

Page 21: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Exemple 2 : Construction d’un simple exécutable avecune arborescence

Arborescence du projet

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 21 / 33

Page 22: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Exemple 2CMakeLists.txt

Construction$ cmake .$ make

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 22 / 33

Page 23: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Exemple 3 : automatiser l’installation

CMakeLists.txt

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 23 / 33

Page 24: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Exemple 3 (suite)

Construction - InstallationConstruction et installation de l’exécutable projet_population dans lesous-répertoire bin

$ cmake .$ make$make install

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 24 / 33

Page 25: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 25 / 33

Page 26: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Construction d’une bibliothèque et d’un exécutable

Arborescence du projet

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 26 / 33

Page 27: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Bibliothèque et exécutableCMakeLists.txt

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 27 / 33

Page 28: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Bibliothèque et exécutable (suite)

Construction - InstallationConstruction et installation de la bibliothèque libMyLib.so dans lesous-répertoire lib

Construction et installation de l’exécutable projet_population dans lesous-répertoire bin

$ cmake .$ make$make install

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 28 / 33

Page 29: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

PLAN

1 Objectifs des systèmes de construction logicielle

2 cmakeIntroductionLangage cmake et utilisationmakefile, make, cmake

3 Exemples avec cmakeConstruction d’un exécutableConstruction d’une bibliothèqueCréation de packages

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 29 / 33

Page 30: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Construction de packages avec cpack

cpackMoteur de création de paquets RPM, DEB, installateur Windows, . . .Peut s’utiliser

de façon autonome (fichier CPackConfig.cmake)

intégré à cmake (dans un CMakeLists.txt)

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 30 / 33

Page 31: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Création de package deb ave cpackCMakeLists.txt

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 31 / 33

Page 32: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Création de package deb ave cpack

cpackCréation du fichier population-lib.deb (package pour debian, ubuntu)$ cmake .$ cpack

Ce package peut ensuite être installé avec$ sudo dpkg -i population-lib.deb

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 32 / 33

Page 33: Systèmes de construction logicielle Introduction à cmakelmb.univ-fcomte.fr/IMG/pdf/f_langrognet_construction... · 2016-09-21 · PLAN 1 Objectifs des systèmes de construction

Systèmes de Construction logicielle - Introduction à cmake

FIN

Merci de votre attention

F. Langrognet Systèmes de construction logicielle - cmake Septembre 2016 33 / 33