And Its Friends CPack, CTest And CDash Eric NOULARD - Eric.noulard .

Transcription

CMake tutorialand its friends CPack, CTest and CDashEric NOULARD - , 8th 2012This presentation is 3.0/us/CMake tutorialN1 / 118

Thanks to. . .Kitware for making a really nice set of tools and making themopen-sourcethe CMake mailing list for its friendliness and its more thanvaluable source of informationCMake developers for their tolerance when I break the dashboardor mess-up with the git workflow,CPack users for their patience when things don’t work as theyshouldexpectAlan, Alex, Bill, Brad, Clint, David, Eike, Julien, Mathieu, Michael& Michael, and many more. . .My son Louis for the nice CPack 3D logo done with Blender.and.Toulibre for hosting this presention in Toulouse, France.CMake tutorialN2 / 118

OutlinesCMake tool setsCMakeCMake is a cross-platform build systems generator which makesit easier to build software in a unified manner on a broad setof platforms:, Windows, MacOS, AIX, IRIX,, iOS · · ·CMake has friends softwares that may be used on their own ortogether:CMake: build system generatorCPack: package generatorCTest: systematic test driverCDash: a dashboard collectorCMake tutorialN3 / 118

OutlinesOutline of Part I: CMake1Basic CMake usage2Discovering environment specificitiesHandling platform specificitiesWorking with external packages3More CMake scriptingCustom commandsGenerated files4Advanced CMake usageCross-compiling with CMakeExport your projectCMake tutorialN4 / 118

OutlinesOutline of Part II: CPack5CPack: Packaging made easy6CPack with CMake7Various package generatorsCMake tutorialN5 / 118

OutlinesOutline of Part III: CTest and CDash8Systematic Testing9CTest submission to CDash10ReferencesCMake tutorialN6 / 118

OutlinesBuild what?Software build systemA software build system is the usage of a [set of] tool[s] forbuilding software applications.Why do we need that?

OutlinesBuild what?Software build systemA software build system is the usage of a [set of] tool[s] forbuilding software applications.Why do we need that?because most softwares consist in several parts that need somebuilding to put them together,

OutlinesBuild what?Software build systemA software build system is the usage of a [set of] tool[s] forbuilding software applications.Why do we need that?because most softwares consist in several parts that need somebuilding to put them together,because softwares are written in various languages that mayshare the same building process,

OutlinesBuild what?Software build systemA software build system is the usage of a [set of] tool[s] forbuilding software applications.Why do we need that?because most softwares consist in several parts that need somebuilding to put them together,because softwares are written in various languages that mayshare the same building process,because we want to build the same software for variouscomputers (PC, Macintosh, Workstation, mobile phones and other PDA,embbeded computers) and systems (Windows, Linux, *BSD, other Unices(many), Android, etc. . . )CMake tutorialN7 / 118

OutlinesProgramming languagesCompiled vs interpreted or what?Building an application requires the use of some programminglanguage: Python, Java, C , Fortran, C, Go, Tcl/Tk, Ruby,Perl, OCaml,. . .?byte-compile?interpreterPerlinterpretsC ramminglanguagesPythonexecutesRunningprogramCMake tutorialN8 / 118

OutlinesProgramming languagesCompiled vs interpreted or what?Building an application requires the use of some programminglanguage: Python, Java, C , Fortran, C, Go, Tcl/Tk, Ruby,Perl, OCaml,. . .?byte-compile?interpreterPerlinterpretsC ramminglanguagesPythonexecutesRunningprogramCMake tutorialN8 / 118

OutlinesBuild systems: several choicesAlternativesCMake is not the only build system [generator]:(portable) hand-written Makefiles, depends on make tool.Apache ant http://ant.apache.org/, dedicated to Java(almost).Portable IDE: Eclipse, Code::Blocks, Geany, NetBeans, . . .GNU Autotools: Autoconf, Automake, Libtool. Producemakefiles. Needs bourne shell (and M4 macro processor). seee.g. http://www.gnu.org/software/autoconf/SCons: http://www.scons.org only depends on python.Extensible with python.CMake tutorialN9 / 118

OutlinesComparisons and [success] storiesDisclaimerThis presentation is biased. I mean totally.I am a big CMake fan, I’m contributing to CMake, thus I’m notimpartial at all. But I will be ready to discuss why CMake isthe greatest build system out there :-)Go and forge your own opinion:Bare list: http://en.wikipedia.org/wiki/List of buildautomation softwareA uildToolsKDE success story (2006): “Why the KDE project switched toCMake – and how” http://lwn.net/Articles/188693/CMake tutorialN10 / 118

OutlinesCMake/Auto[conf make] on ge comparison of CMake to automake and autoconfshowing the percentage of developers commits that modify asource file of the respective language.CMake tutorialN11 / 118

OutlinesCMake/Auto[conf make] on Google Trendhttp://www.google.com/trendsScale is based on the average worldwide traffic of cmake in allyears.CMake tutorialN12 / 118

Basic CMake usageOutline1Basic CMake usage2Discovering environment specificitiesHandling platform specificitiesWorking with external packages3More CMake scriptingCustom commandsGenerated files4Advanced CMake usageCross-compiling with CMakeExport your projectCMake tutorialN13 / 118

Basic CMake usageA build system generatorCMake is a generator: it generates native build systems files(Makefile, IDE project files, . . . ),CMake scripting language (declarative) is used to describe thebuild,The developer edit CMakeLists.txt, invoke CMake but shouldnever edit the generated files,CMake may be (automatically) re-invoked by the build system,CMake tutorialN14 / 118

Basic CMake usageThe CMake workflowWhen do things take place?CMake is a generator so it does not compile (i.e. build)the sources, the underlying build tool (make, XCode,Code::Blocks. . . ) does.CMake tutorialN15 / 118

Basic CMake usageThe CMake workflow1CMake time: CMake is running & processing CMakeLists.txtWhen do things take place?CMake is a generator so it does not compile (i.e. build)the sources, the underlying build tool (make, XCode,Code::Blocks. . . ) does.CMake tutorialN15 / 118

Basic CMake usageThe CMake workflow1CMake time: CMake is running & processing CMakeLists.txt2Build time: the build tool runs and invokes (at least) the compilerWhen do things take place?CMake is a generator so it does not compile (i.e. build)the sources, the underlying build tool (make, XCode,Code::Blocks. . . ) does.CMake tutorialN15 / 118

Basic CMake usageThe CMake workflow1CMake time: CMake is running & processing CMakeLists.txt2Build time: the build tool runs and invokes (at least) the compiler3Install time: the compiled binaries are installedi.e. from build area to an install location.When do things take place?CMake is a generator so it does not compile (i.e. build)the sources, the underlying build tool (make, XCode,Code::Blocks. . . ) does.CMake tutorialN15 / 118

Basic CMake usageThe CMake workflow1CMake time: CMake is running & processing CMakeLists.txt2Build time: the build tool runs and invokes (at least) the compiler3Install time: the compiled binaries are installedi.e. from build area to an install location.4CPack time: CPack is running for building packageWhen do things take place?CMake is a generator so it does not compile (i.e. build)the sources, the underlying build tool (make, XCode,Code::Blocks. . . ) does.CMake tutorialN15 / 118

Basic CMake usageThe CMake workflow1CMake time: CMake is running & processing CMakeLists.txt2Build time: the build tool runs and invokes (at least) the compiler3Install time: the compiled binaries are installedi.e. from build area to an install location.4CPack time: CPack is running for building package5Package Install time: the package (from previous step) is installedWhen do things take place?CMake is a generator so it does not compile (i.e. build)the sources, the underlying build tool (make, XCode,Code::Blocks. . . ) does.CMake tutorialN15 / 118

Basic CMake usageThe CMake workflow (pictured)CMakeLists.txtSource filesCMake tutorialN16 / 118

Basic CMake usageThe CMake workflow (pictured)CMakeLists.txtProject file(s),Makefiles, . . .Source filesGeneratedSources filesCMake timeCMake tutorialN16 / 118

Basic CMake usageThe CMake workflow (pictured)CMakeLists.txtProject file(s),Makefiles, . . .Object filesSource filesGeneratedSources filesCMake timeBuild timeCMake tutorialN16 / 118

Basic CMake usageThe CMake workflow (pictured)CMakeLists.txtProject file(s),Makefiles, . . .Object filesInstalledfilesSource filesGeneratedSources filesCMake timeBuild timeInstall timeCMake tutorialN16 / 118

Basic CMake usageThe CMake workflow (pictured)CMakeLists.txtProject file(s),Makefiles, . . .Object filesInstalledfilesSource filesGeneratedSources filesBinarypackageCMake timeSourcepackageBuild timeInstall timeCPack timeCMake tutorialN16 / 118

Basic CMake usageThe CMake workflow (pictured)CMakeLists.txtProject file(s),Makefiles, . . .Object filesInstalledfilesSource filesGeneratedSources filesBinarypackageCMake timeSourcepackageBuild timeInstall timeCPack timeInstalledpackagePackage Install timeCMake tutorialN16 / 118

Basic CMake usageBuilding an executable123456Listing 1: Building a simple programcmake minimum required (VERSION 2 . 8 )# T h i s p r o j e c t use C s o u r c e codeproject ( TotallyFree C)# build executable using s p e c i f i e d# l i s t of source f i l e sadd executable ( A c r o l i b r e a c r o l i b r e . c )CMake scripting language is [mostly] declarative. It hascommands which are documented from within CMake: cmake --help-command-list wc -l96 cmake --help-command add executable.add executableAdd an executable to the project using the specified source files.CMake tutorialN17 / 118

Basic CMake usageBuiltin documentation1234CMake builtin doc for ’project’ command cmake --help-command projectcmake version 2.8.7.20120121-g751713-dirtyprojectSet a name for the entire project.5project( projectname [languageName1 languageName2 . ] )67Sets the name of the project. Additionally this sets the variables projectName BINARY DIR and projectName SOURCE DIR to therespective values.891011Optionally you can specify which languages your project supports.Example languages are CXX (i.e. C ), C, Fortran, etc. By default Cand CXX are enabled. E.g. if you do not have a C compiler, you candisable the check for it by explicitly listing the languages you wantto support, e.g. C. By using the special language "NONE" all checksfor any language can be disabled.121314151617CMake tutorialN18 / 118

Basic CMake usageGenerating & buildingBuilding with CMake is easy:123456789101112131415CMake Unix Makefile ls totally-freeacrolibre.c CMakeLists.txt mkdir build cd build cmake ./totally-free-- The C compiler identification is GNU 4.6.2-- Check for working C compiler: /usr/bin/gcc-- Check for working C compiler: /usr/bin/gcc -- works. makeScanning dependencies of target Acrolibre[100%] Building C object CMakeFiles/Acrolibre.dir/acrolibre.c.oLinking C executable Acrolibre[100%] Built target Acrolibre ./Acrolibre toulibreSource tree vs Build treeEven the most simple project should never mix-up sources withgenerated files. CMake supports out-of-source build.CMake tutorialN19 / 118

Basic CMake usageAlways build out-of-sourceOut-of-source is betterPeople are lazy (me too) and they think that because buildingin source is possible and authorizes less typing they can getaway with it. In-source build is a BAD choice.Out-of-source build is always better because:CMake tutorialN20 / 118

Basic CMake usageAlways build out-of-sourceOut-of-source is betterPeople are lazy (me too) and they think that because buildingin source is possible and authorizes less typing they can getaway with it. In-source build is a BAD choice.Out-of-source build is always better because:1Generated files are separate from manually edited ones(thus you don’t have to clutter you favorite VCS ignore files).CMake tutorialN20 / 118

Basic CMake usageAlways build out-of-sourceOut-of-source is betterPeople are lazy (me too) and they think that because buildingin source is possible and authorizes less typing they can getaway with it. In-source build is a BAD choice.Out-of-source build is always better because:1Generated files are separate from manually edited ones(thus you don’t have to clutter you favorite VCS ignore files).2You can have several build trees for the same source treeCMake tutorialN20 / 118

Basic CMake usageAlways build out-of-sourceOut-of-source is betterPeople are lazy (me too) and they think that because buildingin source is possible and authorizes less typing they can getaway with it. In-source build is a BAD choice.Out-of-source build is always better because:1Generated files are separate from manually edited ones(thus you don’t have to clutter you favorite VCS ignore files).2You can have several build trees for the same source tree3This way it’s always safe to completely delete the build tree inorder to do a clean buildCMake tutorialN20 / 118

Basic CMake usageBuilding program autonomous libraryWe now have the following set of files in our source tree:acrolibre.c, the main C programacrodict.h, the Acrodict library headeracrodict.c, the Acrodict library sourceCMakeLists.txt, the soon to be updated CMake entry fileCMake tutorialN21 / 118

Basic CMake usageBuilding program autonomous libraryConditional buildWe want to keep a version of our program that can be compiledand run without the new Acrodict library and the new versionwhich uses the library.We now have the following set of files in our source tree:acrolibre.c, the main C programacrodict.h, the Acrodict library headeracrodict.c, the Acrodict library sourceCMakeLists.txt, the soon to be updated CMake entry fileCMake tutorialN21 / 118

The main program source1234567891011121314151617181920212223#i n c l u d e s t d l i b . h #i n c l u d e s t d i o . h #i n c l u d e s t r i n g s . h #i f d e f USE ACRODICT#i n c l u d e "acrodict.h"#e n d i fi n t main ( i n t argc , c h a r a r g v [ ] ) {c o n s t c h a r name ;#i f d e f USE ACRODICTc o n s t a c r o I t e m t item ;#e n d i fi f ( argc 2) {f p r i n t f ( s t d e r r , "%s: you need oneargument\n" , a r g v [ 0 ] ) ;f p r i n t f ( s t d e r r , "%s name \n" , a r g v[0]) ;e x i t ( EXIT FAILURE ) ;}name a r g v [ 1 ] ;#i f n d e f USE ACRODICTi f ( s t r c a s e c m p ( name , "toulibre" ) 0) {p r i n t f ( "Toulibre is a french24252627282930313233343536373839organization promoting FLOSS.\n" ) ;}#e l s eitem a c r o d i c t g e t ( name ) ;i f (NULL! item ) {p r i n t f ( "%s: %s\n" , item name , item description ) ;} e l s e i f ( item a c r o d i c t g e t a p p r o x (name ) ) {p r i n t f ( " %s is unknown may be youmean :\n" , name ) ;p r i n t f ( "%s: %s\n" , item name , item description ) ;}#e n d i felse {p r i n t f ( "Sorry , I don’t know: %s \n" , name ) ;r e t u r n EXIT FAILURE ;}r e t u r n EXIT SUCCESS ;}CMake tutorialN22 / 118

The library source12345678910123456789#i f n d e f ACRODICT H#d e f i n e ACRODICT Htypedef s t r u c t acroItem {c h a r name ;char d e s c r i p t i o n ;} acroItem t ;const acroItem t a c r o d i c t g e t ( c o n s t c h a r name ) ;#e n d i f#i n c l u d e s t d l i b . h #i n c l u d e s t r i n g . h #i n c l u d e "acrodict.h"s t a t i c const acroItem t acrodict [ ] {{"Toulibre" , "Toulibre is a frenchorganization promoting FLOSS" } ,{"GNU" , "GNU is Not Unix" } ,{"GPL" , "GNU general Public License"},{"BSD" , "Berkeley SoftwareDistribution" } ,{"CULTe" , "Club des Utilisateurs deLogiciels libres et de gnu/linux de Toulouse et desenvirons" } ,101112131415161718192021222324252627282930{"Lea" , "Lea -Linux: Linux entre ami(e)s" } ,{"RMLL" , "Rencontres Mondiales duLogiciel Libre" } ,{"FLOSS" , "Free Libre Open SourceSoftware" } ,{"" , "" } } ;const acroItem t a c r o d i c t g e t ( c o n s t c h a r name ) {i n t c u r r e n t 0;i n t found 0;w h i l e ( ( s t r l e n ( a c r o d i c t [ c u r r e n t ] . name) 0) && ! found ) {i f ( s t r c a s e c m p ( name , a c r o d i c t [c u r r e n t ] . name ) 0) {found 1;} else {c u r r e n t ;}}i f ( found ) {r e t u r n &( a c r o d i c t [ c u r r e n t ] ) ;} else {r e t u r n NULL ;}}CMake tutorialN23 / 118

Basic CMake usageBuilding a library IListing 2: Building a simple program shared library123456789cmake minimum required (VERSION 2 . 8 )p r o j e c t ( TotallyFree C)add executable ( Acrolibre a c r o l i b r e . c )s e t ( LIBSRC a c r o d i c t . c a c r o d i c t . h )a d d l i b r a r y ( a c r o d i c t {LIBSRC } )add executable ( A c r o d i c t l i b r e a c r o l i b r e . c )t a r g e t l i n k l i b r a r i e s ( Acrodictlibre acrodict )set target properties ( AcrodictlibrePROPERTIES COMPILE FLAGS "-DUSE ACRODICT" )

Basic CMake usageBuilding a library IIAnd it builds.All in all CMake generates appropriate Unix makefiles whichbuild all this smoothly.12345678910111213CMake Unix Makefile make[ 33%] Building C object CMakeFiles/acrodict.dir/acrodict.c.oLinking C shared library libacrodict.so[ 33%] Built target acrodict[ 66%] Building C object CMakeFiles/Acrodictlibre.dir/acrolibre.c.oLinking C executable Acrodictlibre[ 66%] Built target Acrodictlibre[100%] Building C object CMakeFiles/Acrolibre.dir/acrolibre.c.oLinking C executable Acrolibre[100%] Built target Acrolibre ls -FAcrodictlibre* CMakeCache.txt cmake install.cmake MakefileAcrolibre*CMakeFiles/libacrodict.so*CMake tutorialN25 / 118

Basic CMake usageBuilding a library IIIAnd it works.We get the two different variants of our program, with varyingcapabilities.123456Generated Makefiles hasseveral builtin targets besidesthe expected ones: ./Acrolibre toulibreToulibre is a french organization promoting FLOSS. ./Acrolibre FLOSSSorry, I don’t know: FLOSS ./Acrodictlibre FLOSSFLOSS: Free Libre Open Source Software make helpThe following are some of the valid targetsfor this Makefile:. all (the default if no target is provided). clean. depend. Acrodictlibre. Acrolibre. acrodict.one per target (library orexecutable)clean, allmore to come . . .

Basic CMake usageUser controlled build optionUser controlled optionMay be our users don’t want the acronym dictionnary support.We can use CMake OPTION command.Listing 3: User controlled build option123456789101112131415cmake minimum required (VERSION 2 . 8 )# T h i s p r o j e c t use C s o u r c e codep r o j e c t ( TotallyFree C)# B u i l d o p t i o n w i t h d e f a u l t v a l u e t o ONo p t i o n (WITH ACRODICT "Include acronym dictionary support" ON)s e t ( BUILD SHARED LIBS t r u e )# build executable using s p e c i f i e d l i s t of source f i l e sadd executable ( Acrolibre a c r o l i b r e . c )i f (WITH ACRODICT)s e t ( LIBSRC a c r o d i c t . h a c r o d i c t . c )a d d l i b r a r y ( a c r o d i c t {LIBSRC } )add executable ( A c r o d i c t l i b r e a c r o l i b r e . c )t a r g e t l i n k l i b r a r i e s ( Acrodictlibre acrodict )s e t t a r g e t p r o p e r t i e s ( A c r o d i c t l i b r e PROPERTIES COMPILE FLAGS "-DUSE ACRODICT" )e n d i f (WITH ACRODICT)CMake tutorialN27 / 118

Basic CMake usageToo much keyboard, time to click? ICMake comes with severals toolsA matter of choice / taste:a command line: cmakea curse-based TUI: ccmakea QT-based GUI: cmake-guiCall conventionAll tools expect to be called with a single argument which maybe interpreted in 2 different ways.path to the source tree, e.g.: cmake /path/to/sourcepath to an existing build tree, e.g.: cmake-gui .CMake tutorialN28 / 118

Basic CMake usageToo much keyboard, time to click? IIccmake : the curse-based TUI (demo)Here we can choose to toggle the WITH ACRONYM OPTION.CMake tutorialN29 / 118

Basic CMake usageToo much keyboard, time to click? IIIcmake-gui : the QT-based GUI (demo)Again, we can choose to toggle the WITH ACRONYM OPTION.CMake tutorialN30 / 118

Basic CMake usageRemember CMake is a build generator?The number of active generators depends on the platform we arerunning on Unix, Apple, Windows:12345678910111213141516Borland MakefilesMSYS MakefilesMinGW MakefilesNMake MakefilesNMake Makefiles JOMUnix MakefilesVisual Studio 10Visual Studio 10 IA64Visual Studio 10 Win64Visual Studio 11Visual Studio 11 Win64Visual Studio 6Visual Studio 7Visual Studio 7 .NET 2003Visual Studio 8 2005Visual Studio 8 2005 Win64171819202122232425262728293031Visual Studio 9 2008Visual Studio 9 2008 IA64Visual Studio 9 2008 Win64Watcom WMakeCodeBlocks - MinGW MakefilesCodeBlocks - NMake MakefilesCodeBlocks - Unix MakefilesEclipse CDT4 - MinGW MakefilesEclipse CDT4 - NMake MakefilesEclipse CDT4 - Unix MakefilesKDevelop3KDevelop3 - Unix MakefilesXCodeNinja (in development)http://martine.github.com/ninja/CMake tutorialN31 / 118

Basic CMake usageEqually simple on other platformsIt is as easy for a windows build, however names for executablesand libraries are computed in a platform specific way.12345678910111213141516171819CMake MinGW Makefile ls totally-freeacrodict.h acrodict.c acrolibre.c CMakeLists.txt mkdir build-win32 cd build-win32. makeScanning dependencies of target acrodict[ 33%] Building C object CMakeFiles/acrodict.dir/acrodict.c.objLinking C shared library libacrodict.dllCreating library file: libacrodict.dll.a[ 33%] Built target acrodictScanning dependencies of target Acrodictlibre[ 66%] Building C object g C executable Acrodictlibre.exe[ 66%] Built target AcrodictlibreScanning dependencies of target Acrolibre[100%] Building C object CMakeFiles/Acrolibre.dir/acrolibre.c.objLinking C executable Acrolibre.exe[100%] Built target AcrolibreCMake tutorialN32 / 118

Basic CMake usageInstalling thingsInstallSeveral parts or the software may need to be installed, this iscontrolled by the CMake install command.Remember cmake --help-command install!!Listing 4: install command examples1234567891011.add executable ( Acrolibre a c r o l i b r e . c )i n s t a l l (TARGETS A c r o l i b r e DESTINATION b i n )i f (WITH ACRODICT).i n s t a l l (TARGETS A c r o d i c t l i b r e a c r o d i c tRUNTIME DESTINATION b i nLIBRARY DESTINATION l i bARCHIVE DESTINATION l i b / s t a t i c )i n s t a l l ( FILES a c r o d i c t . h DESTINATION i n c l u d e )e n d i f (WITH ACRODICT)CMake tutorialN33 / 118

Basic CMake usageControlling installation destinationUse relative DESTINATIONOne should always use relative installation DESTINATIONunless you really want to use absolute path like /etc.Then depending when you install:CMake tutorialN34 / 118

Basic CMake usageControlling installation destinationUse relative DESTINATIONOne should always use relative installation DESTINATIONunless you really want to use absolute path like /etc.Then depending when you install:At CMake-time set CMAKE INSTALL PREFIX value cmake --help-variable CMAKE INSTALL PREFIXCMake tutorialN34 / 118

Basic CMake usageControlling installation destinationUse relative DESTINATIONOne should always use relative installation DESTINATIONunless you really want to use absolute path like /etc.Then depending when you install:At CMake-time set CMAKE INSTALL PREFIX value cmake --help-variable CMAKE INSTALL PREFIXAt Install-time use DESTDIR mechanism (Unix Makefiles) make DESTDIR /tmp/testinstall installCMake tutorialN34 / 118

Basic CMake usageControlling installation destinationUse relative DESTINATIONOne should always use relative installation DESTINATIONunless you really want to use absolute path like /etc.Then depending when you install:At CMake-time set CMAKE INSTALL PREFIX value cmake --help-variable CMAKE INSTALL PREFIXAt Install-time use DESTDIR mechanism (Unix Makefiles) make DESTDIR /tmp/testinstall installAt CPack-time, CPack what? . . . be patient.At Package-install-time, we will see that laterCMake tutorialN34 / 118

Basic CMake usageThe CMake workflow (pictured)CMakeLists.txtProject file(s),Makefiles, . . .Object filesInstalledfilesSource filesGeneratedSources filesBinarypackageCMake timeSourcepackageBuild timeInstall timeCPack timeInstalledpackagePackage Install timeCMake tutorialN35 / 118

Basic CMake usageUsing CMake variablesCMake variablesThey are used by the user to simplify its CMakeLists.txt,but CMake uses many ( 170 ) of them to control/change its[default] behavior. Try: cmake --help-variables-list.Inside a CMake scriptset (CMAKE INSTALL PREFIX /home/eric/testinstall) cmake --help-command setOn the command line/TUI/GUIRemember that (beside options) each CMake tool takes a singleargument (source tree or existing build tree) cmake -DCMAKE INSTALL PREFIX /home/eric/testinstall .CMake tutorialN36 / 118

Basic CMake usageThe install targetInstall targetThe install target of the underlying build tool (in our casemake) appears in the generated build system as soon as someinstall command are used in the CMakeLists.txt.123456789101112 make DESTDIR /tmp/testinstall install[ 33%] Built target acrodict[ 66%] Built target Acrodictlibre[100%] Built target AcrolibreInstall the project.-- Install configuration: ""-- Installing: /tmp/testinstall/bin/Acrolibre-- Installing: /tmp/testinstall/bin/Acrodictlibre-- Removed runtime path from "/tmp/testinstall/bin/Acrodictlibre"-- Installing: /tmp/testinstall/lib/libacrodict.so-- Installing: /tmp/testinstall/include/acrodict.h CMake tutorialN37 / 118

Basic CMake usagePackage the whole thingCPackCPack is a CMake friend application (detailed later) whichmay be used to easily package your software.Listing 5: add CPack support123456789101112.e n d i f (WITH ACRODICT).# Near t h e end o f t h e CMakeLists . t x t# Chose y o u r CPack g e n e r a t o rs e t (CPACK GENERATOR "TGZ" )# Setup package v e r s i o ns e t (CPACK PACKAGE VERSION MAJOR 0 )s e t ( CPACK PACKAGE VERSION MINOR 1 )s e t ( CPACK PACKAGE VERSION PATCH 0 )# ’ c a l l ’ CPacki n c l u d e ( CPack ) make package[ 33%] Built target acrodict[ 66%] Built target Acrodictlibre[100%] Built target AcrolibreRun CPack packaging tool.CPack: Create package using TGZCPack: Install projectsCPack: - Run preinstall target for: TotallyFreeCPack: - Install project: TotallyFreeCPack: Create packageCPack: - package: build-tree /.TotallyFree-0.1.0-Linux.tar.gz generated. tar ztvf TotallyFree-0.1.0-Linux.tar.gz. TotallyFree-0.1.0-Linux/include/acrodict.h. TotallyFree-0.1.0-Linux/bin/Acrolibre. TotallyFree-0.1.0-Linux/bin/Acrodictlibre. TotallyFree-0.1.0-Linux/lib/libacrodict.soCMake tutorialN38 / 118

Basic CMake usageCPack the packaging friendCPack is a standalone generatorAs we will see later on, CPack is standalone application, whichas CMake is a generator. cpack -G ZIPCPack: Create package using ZIPCPack: Install projectsCPack: - Run preinstall target for: TotallyFreeCPack: - Install project: TotallyFreeCPack: Create packageCPack: - package: build-tree /.TotallyFree-0.1.0-Linux.zip generated. unzip -t TotallyFree-0.1.0-Linux.zipArchive: TotallyFree-0.1.0-Linux.ziptesting: To./include/acrodict.hOKtesting: To./bin/AcrolibreOKtesting: To./bin/AcrodictlibreOKtesting: To./lib/libacrodict.soOKNo errors detected in compresseddata of TotallyFree-0.1.0-Linux.zip.N cpack -G RPMCPack: Create package using RPMCPack: Install projectsCPack: - Run preinstall target for: TotallyFreeCPack: - Install project: TotallyFreeCPack: Create packageCPackRPM: Will use GENERATED spec file: build-tree /.CPack Packages/Linux/RPM/SPECS/totallyfree.specCPack: - package: build-tree /.TotallyFree-0.1.0-Linux.rpm generated. rpm -qpl ude/acrodict.h/usr/lib/usr/lib/libacrodict.soCMake tutorial39 / 118

Basic CMake usageDidn’t you mentioned testing? ICTestCTest is a CMake friend application (detailed later) which maybe used to easily test your software.Listing 6: add CTest support123456789101112.e n d i f (WITH ACRODICT).enable testing ( )a d d t e s t ( t o u l i b r e b u i l t i nA c r o l i b r e "toulibre" )a d d t e s t ( t o u l i b r e d i c tA c r o d i c t l i b r e "toulibre" )a d d t e s t ( FLOSS d i c tA c r o d i c t l i b r e "FLOSS" )a d d t e s t ( FLOSS f a i lA c r o l i b r e "FLOSS" ) make testRunning tests.Test project buildtree-prefix /buildStart 1: toulibre-builtin1/4 Test #1: toulibre-builtin .PassedStart 2: toulibre-dict2/4 Test #2: toulibre-dict.PassedStart 3: FLOSS-dict3/4 Test #3: FLOSS-dict .PassedStart 4: FLOSS-fail4/4 Test #4: FLOSS-fail .***Failed0.00 sec0.00 sec0.00 sec0.00 sec75% tests passed, 1 tests failed out of 4Total Test time (real) 0.01 secThe following tests FAILED:4 - FLOSS-fail (Failed)CMake tutorialN40 / 118

Basic CMake usageDidn’t you mentioned testing? IITailor success ruleCTest uses the return code in order to get success/failure status,but one can tailor the success/fail rule.Listing 7: add CTest support12345678910111213141516.e n d i f (WITH ACRODICT).enable testing ( )a d d t e s t ( t o u l i b r e b u i l t i nA c r o l i b r e "toulibre" )a d d t e s t ( t o u l i b r e d i c tA c r o d i c t l i b r e "toulibre" )a d d t e s t ( FLOSS d i c tA c r o d i c t l i b r e "FLOSS" )a d d t e s t ( FLOSS f a i lA c r o l i b r e "FLOSS" )s e t t e s t s p r o p e r t i e s ( FLOSS f a i lPROPERTIESPASS REGULAR EXPRESSION"Sorry , I don ’t know :.* FLOSS" ) make testRunn

A software build system is the usage of a [set of] tool[s] for building software applications. Why do we need that? because most softwares consist in several parts that need some building to put them together, because softwares are written in various languages that may share the same building process, because we want to build the same software .