SlideShare a Scribd company logo
1 of 34
Download to read offline
CMake Tutorial


●
    1 – Introduction to CMake
●
    2 – Using CMake for the ILC Software
●
    3 – ILCInstall with CMake


               Jan Engels

                    DESY
             20th September 2007
What is CMake


●
    CMake:
    –   Generates native build environments
         ●
             UNIX/Linux -> Makefiles
         ●
             Windows -> VS Projects/Workspaces
         ●
             Apple -> Xcode
    –   Open-Source :)
    –   Cross-Platform




                          Jan Engels - Introduction to CMake   2
CMake Features
●
    CMake has a lot of nice features:
     –   Manage complex, large build environments (KDE4)
     –   Very Flexible & Extensible
          ●
              Support for Macros
          ●
              Modules for finding/configuring software (bunch of modules already available)
          ●
              Extend CMake for new platforms and languages
          ●
              Create custom targets/commands
          ●
              Run external programs
     –   Very simple, intuitive syntax
     –   Support for regular expressions (*nix style)
     –   Support for “In-Source” and “Out-of-Source” builds
     –   Cross Compiling
     –   Integrated Testing & Packaging (Ctest, CPack)


                                   Jan Engels - Introduction to CMake                     3
Build-System Generator




CMakeLists.txt                         CMake                      Native Build System




   Executables / Libraries                                        Native Build Tools




                             Jan Engels - Introduction to CMake                         4
CMake Basic Concepts
●
    CmakeLists.txt
    –   Input text files that contain the project parameters and
        describe the flow control of the build process in simple
        CMake language.
●
    CMake Modules
    –   Special cmake file written for the purpose of finding a
        certain piece of software and to set it's libraries, include
        files and definitions into appropriate variables so that
        they can be used in the build process of another
        project. (e.g. FindJava.cmake, FindZLIB.cmake,
        FindQt4.cmake)


                           Jan Engels - Introduction to CMake      5
CMake Basic Concepts
●
    The Source Tree contains:
     –   CMake input files (CmakeLists.txt)
     –   Program source files (hello.cc)
     –   Program header files (hello.h)
●
    The Binary Tree contains:
     –   Native build system files (Makefiles)
     –   Output from build process:
           ●
               Libraries
           ●
               Executables
           ●
               Any other build generated file
●
    Source and Binary trees may be:
     –   In the same directory (in-source build)
     –   In different directories (out-of-source build)



                                     Jan Engels - Introduction to CMake   6
CMake Basic Concepts
●
    CMAKE_MODULE_PATH
     –   Path to where the CMake modules are located
●
    CMAKE_INSTALL_PREFIX
     –   Where to put files when calling 'make install'
●
    CMAKE_BUILD_TYPE
     –   Type of build (Debug, Release, ...)
●
    BUILD_SHARED_LIBS
     –   Switch between shared and static libraries


●
    Variables can be changed directly in the build files (CmakeLists.txt) or through
    the command line by prefixing a variable's name with '-D':
     –   cmake -DBUILD_SHARED_LIBS=OFF
●
    GUI also available: ccmake


                                    Jan Engels - Introduction to CMake             7
CMake Cache


●
    Created in the build tree (CMakeCache.txt)
●
    Contains Entries VAR:TYPE=VALUE
●
    Populated/Updated during configuration phase
●
    Speeds up build process
●
    Can be initialized with cmake -C <file>
●
    GUI can be used to change values
●
    There should be no need to edit it manually!!



                      Jan Engels - Introduction to CMake   8
Source Tree Structure

                                                                          Dir3/CMakeLists.txt

                                       Dir1/CMakeLists.txt
                                     SUBDIRS(Dir3 Dir4)
     Project's Top-Level
       CmakeLists.txt                                                     Dir4/CMakeLists.txt

    SUBDIRS(Dir1 Dir2)
                                        Dir2/CMakeLists.txt



●
     Subdirectories added with SUBDIRS/ADD_SUBDIRECTORY
●
     Child inherits from parent (feature that is lacking in traditional Makefiles)
●
     Order of processing: Dir1;Dir3;Dir4;Dir2 (When CMake finds a SUBDIR command it
     stops processing the current file immediately and goes down the tree branch)


                                     Jan Engels - Introduction to CMake                         9
Using CMake

●
    Create a build directory (“out-of-source-build” concept)
     –   mkdir build ; cd build
●
    Configure the package for your system:
     –   cmake [options] <source_tree>
●
    Build the package:
                                                                 Similar to Auto Tools
     –   make
●
    Install it:
     –   make install
●
    The last 2 steps can be merged into one (just “make install”)



                            Jan Engels - Introduction to CMake                           10
Hello World for CMake
●
    Top-level project directory:
     –   CMakeLists.txt                    /*hello.h*/                     /*hello.cc*/
                                           #ifndef _hello_h                #include "hello.h"
     –   Sub-directory Hello:              #define _hello_h                #include <iostream>
                                                                           using namespace std;
           ●
               CMakeLists.txt              class Hello {
                                           public:                         void Hello::Print() {
           ●
               hello.h                       void Print();                   cout<<"Hello, World!”<<endl;
                                           };                              }
           ●
               hello.cc
                                           #endif
     –   Sub-directory Test:
           ●
               CMakeLists.txt                                                       Library Hello
           ●
               test.cc
                                                             /*test.cc*/
                                                             #include <iostream>
                                                             #include "hello.h"

                                                             int main() {
                                                               Hello().Print();
                                                               return 0;
                                                             }                    Test Binary


                                   Jan Engels - Introduction to CMake                                       11
Hello World for CMake
# Top-Level CmakeLists.txt

PROJECT( HELLO )

ADD_SUBDIRECTORY( Hello )
ADD_SUBDIRECTORY( Test )


                   # CmakeLists.txt in Hello dir

                   # Adds a library called Hello (libHello.a under Linux) from the source file hello.cc
                   ADD_LIBRARY( Hello hello )


                                            # CmakeLists.txt in Test dir

                                            # Make sure the compiler can find include files from our Hello library.
                                            INCLUDE_DIRECTORIES(${HELLO_SOURCE_DIR}/Hello)

                                            # Add binary called "helloWorld" that is built from the source file "test.cc".
                                            # The extension is automatically found.
                                            ADD_EXECUTABLE(helloWorld test)

                                            # Link the executable to the Hello library.
                                            TARGET_LINK_LIBRARIES(helloWorld Hello)


                                           Jan Engels - Introduction to CMake                                           12
CmakeLists.txt Files
●
    Very simple syntax:
    –   # This is a comment
    –   Commands syntax: COMMAND( arg1 arg2 ... )
    –   Lists A;B;C # semi-colon separated values
    –   Variables ${VAR}
    –   Conditional constructs
         ●
             IF() ... ELSE()/ELSEIF() ... ENDIF()
              –   Very useful: IF( APPLE ); IF( UNIX ); IF( WIN32 )
         ●
             WHILE() ... ENDWHILE()
         ●
             FOREACH() ... ENDFOREACH()
    –   Regular expressions (check CMake FAQ for details...)


                                 Jan Engels - Introduction to CMake   13
CmakeLists.txt Files
●
    INCLUDE_DIRECTORIES( “dir1” “dir2” ... )
●
    AUX_SOURCE_DIRECTORY( “source” )
●
    ADD_EXECUTABLE
●
    ADD_LIBRARY                                      Check www.cmake.org -> Documentation
●
    ADD_CUSTOM_TARGET
●
    ADD_DEPENDENCIES( target1 t2 t3 ) target1 depends on t2 and t3
●
    ADD_DEFINITIONS( “-Wall -ansi -pedantic”)
●
    TARGET_LINK_LIBRARIES( target-name lib1 lib2 ...) Individual settings for each target
●
    LINK_LIBRARIES( lib1 lib2 ...) All targets link with the same set of libs
●
    SET_TARGET_PROPERTIES( ... ) lots of properties... OUTPUT_NAME, VERSION, ....
●
    MESSAGE( STATUS|FATAL_ERROR “message” )
●
    INSTALL( FILES “f1” “f2” “f3” DESTINATION . )
     –   DESTINATION relative to ${CMAKE_INSTALL_PREFIX}


                                      Jan Engels - Introduction to CMake                    14
CmakeLists.txt Files

●
    SET( VAR value [CACHE TYPE DOCSTRING [FORCE]])
●
    LIST( APPEND|INSERT|LENGTH|GET|REMOVE_ITEM|REMOVE_AT|SORT ...)
●
    STRING( TOUPPER|TOLOWER|LENGTH|SUBSTRING|REPLACE|REGEX ...)
●
    SEPARATE_ARGUMENTS( VAR ) convert space separated string to list
●
    FILE( WRITE|READ|APPEND|GLOB|GLOB_RECURSE|REMOVE|MAKE_DIRECTORY ...)
●
    FIND_FILE
●
    FIND_LIBRARY
                                           Check www.cmake.org -> Documentation
●
    FIND_PROGRAM
●
    FIND_PACKAGE
●
    EXEC_PROGRAM( bin [work_dir] ARGS <..> [OUTPUT_VARIABLE var] [RETURN_VALUE var] )
●
    OPTION( OPTION_VAR “description string” [initial value] )




                                    Jan Engels - Introduction to CMake              15
CMake Tutorial




●
    2 – Using CMake for the ILC Software




                 Jan Engels - Introduction to CMake   16
CMake for the ILC Software
●
    IMPORTANT:
    –   CMake files for the ILC Software were designed, written and tested exclusively for out-of-
        source builds, therefore we strongly disencourage in-source builds!!
    –   A package should be installed first (with 'make install') before it can be used by other
        packages, thus we also strongly disencourage trying to pass the binary-tree from one
        package as the “installation directory” to other packages.


●
    Packages with CMake (build) support:
    –   Marlin, MarlinUtil, MarlinReco, CEDViewer, CED, LCIO, GEAR, LCCD,
        RAIDA, PandoraPFA, LCFIVertex, SiliconDigi, Eutelescope
●
    CMake modules written for external packages:
    –   CLHEP, CERNLIB, CondDBMySQL, GSL, ROOT, JAVA, AIDAJNI




                                     Jan Engels - Introduction to CMake                            17
Special variables
●
    BUILD_WITH=”CLHEP GSL”
    –   Tell package to use the libraries, include files and
        definitions from these packages
●
    <PKG>_HOME
    –   Variable for defining the home path from a pkg
         ●
             Standard CMake Find modules differ slightly from ILC
             Find modules
              –   ILC Find modules require PKG_HOME variable set
                    ●
                      Enforce version consistency (get rid of setting global
                      environment variables for defining local dependencies)
              –   Could instead be called Config<PKG>.cmake


                                Jan Engels - Introduction to CMake         18
Macros
●
    MacroLoadPackage.cmake
    –   To be able to use a package by using a
        “Find<PKG>.cmake” module or by using a
        “<PKG>Config.cmake” file
    –   Assumes the PKG_HOME variable is properly set
●
    MacroCheckDeps.cmake
    –   Uses MacroLoadPackage.cmake to check
        dependencies




                      Jan Engels - Introduction to CMake   19
Find<PKG>.cmake Modules
●
    Do the same as <PKG>Config.cmake generated
    by the cmake build
●
    Returns variables for using the package
    –   <PKG>_INCLUDE_DIRS
    –   <PKG>_LIBRARIES
    –   <PKG>_DEFINITIONS
●
    Using the MacroLoadPackage this is automatically
    done for you



                     Jan Engels - Introduction to CMake   20
BuildSetup.cmake


●
    Script for pre-caching variables/options
     –   SET( VAR “value” CACHE TYPE “description” FORCE )
●
    Easy way to change build parameters without having to pass
    the every time on the cmd line
●
    Use simple steps to build a package:
     –   mkdir build ; cd build
     –   cmake -C ../BuildSetup.cmake ..
     –   make install
●
    Still possible to override options on the cmd line



                           Jan Engels - Introduction to CMake    21
BuildSetup.cmake


●
    Can use more than one -C option:
    –   cmake -C ../BuildSetup.cmake -C ~/ILCSoft.cmake
    –   Next file overwrites values from previous file
    –   Useful for overwriting paths defined in a 'more global' file
         ●
             CMake just ignores redundant variables from global file
         ●
             ILCInstall generates a global file called ILCSoft.cmake


●
    Check /afs/desy.de/group/it/ilcsoft/v01-01/ILCSoft.cmake as
    an example



                             Jan Engels - Introduction to CMake        22
Adapting your processor to CMake
●
    Copy from $Marlin/examples/mymarlin
    –   CmakeLists.txt
         ●
             change the project name and add missing dependencies
             (default are Marlin;LCIO)
    –   mymarlinConfig.cmake.in
         ●
             rename to <MyProcessor>Config.cmake
    –   BuildSetup.cmake
         ●
             change this according to your system setup
    –   cmake_uninstall.cmake.in
         ●
             Script for generating a 'make uninstall' target
              –   No changes needed!

                              Jan Engels - Introduction to CMake   23
CmakeLists.txt template
# cmake file for building Marlin example Package

# CMake compatibility issues: don't modify this, please!
CMAKE_MINIMUM_REQUIRED( VERSION 2.4.6 )
MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY)
# allow more human readable "if then else" constructs
SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )

# User section
PROJECT( mymarlin )

# project version
SET( ${PROJECT_NAME}_MAJOR_VERSION 0 )                                            You can add here your own options,
SET( ${PROJECT_NAME}_MINOR_VERSION 1 )                                           but don't forget at the end of the file to
SET( ${PROJECT_NAME}_PATCH_LEVEL 0 )                                           display them with a MESSAGE( STATUS)
                                                                                and to also write them properly to cache!
# project options
OPTION( BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON )
OPTION( INSTALL_DOC "Set to OFF to skip build/install Documentation" ON )
# project dependencies e.g. SET( ${PROJECT_NAME}_DEPENDS "Marlin MarlinUtil LCIO GEAR CLHEP GSL" )
SET( ${PROJECT_NAME}_DEPENDS "Marlin LCIO" )
# set default cmake build type to RelWithDebInfo (None Debug Release RelWithDebInfo MinSizeRel)
IF( NOT CMAKE_BUILD_TYPE )
   SET( CMAKE_BUILD_TYPE "RelWithDebInfo" )
ENDIF()
# set default install prefix to project root directory
IF( CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" )
   SET( CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}" )
ENDIF()



                                          Jan Engels - Introduction to CMake                                          24
CmakeLists.txt template
#include directories
INCLUDE_DIRECTORIES( "${PROJECT_SOURCE_DIR}/include" )                       Include directories here
# install include files
INSTALL( DIRECTORY "${PROJECT_SOURCE_DIR}/include"
     DESTINATION . PATTERN "*~" EXCLUDE PATTERN "*CVS*" EXCLUDE )

# require proper c++
ADD_DEFINITIONS( "-Wall -ansi -pedantic" )
# add debug definitions
#IF( CMAKE_BUILD_TYPE STREQUAL "Debug" OR                                 Add your Debug definitions here!
# CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
# ADD_DEFINITIONS( "-DDEBUG" )
#ENDIF()

# get list of all source files                                      If you have more sources you
AUX_SOURCE_DIRECTORY( src library_sources )                       should add them here (see for ex.
( .... )                                                              LCFIVertex CMakeLists.txt)
# DEPENDENCIES: this code has to be placed before adding any library or
# executable so that these are linked properly against the dependencies
IF( DEFINED ${PROJECT_NAME}_DEPENDS OR DEFINED BUILD_WITH OR DEFINED LINK_WITH )
   # load macro
   IF( NOT EXISTS "${CMAKE_MODULE_PATH}/MacroCheckDeps.cmake" )
      MESSAGE( FATAL_ERROR                                                    Dependencies are
        "nSorry, could not find MacroCheckDeps.cmake...n"
        "Please set CMAKE_MODULE_PATH correctly with: "                          checked here!
        "cmake -DCMAKE_MODULE_PATH=<path_to_cmake_modules>" )
   ENDIF()
   INCLUDE( "${CMAKE_MODULE_PATH}/MacroCheckDeps.cmake" )
   CHECK_DEPS()
ENDIF()


                                     Jan Engels - Introduction to CMake                                 25
CmakeLists.txt template
# LIBRARY
ADD_LIBRARY( lib_${PROJECT_NAME} ${library_sources} )
# create symbolic lib target for calling target lib_XXX
ADD_CUSTOM_TARGET( lib DEPENDS lib_${PROJECT_NAME} )
# change lib_target properties
SET_TARGET_PROPERTIES( lib_${PROJECT_NAME} PROPERTIES
                                                                                     Library
   # create *nix style library versions + symbolic links
   VERSION ${${PROJECT_NAME}_VERSION}
   SOVERSION ${${PROJECT_NAME}_SOVERSION}
   # allow creating static and shared libs without conflicts
   CLEAN_DIRECT_OUTPUT 1
   # avoid conflicts between library and binary target names
   OUTPUT_NAME ${PROJECT_NAME} )

# install library
INSTALL( TARGETS lib_${PROJECT_NAME} DESTINATION lib PERMISSIONS
     OWNER_READ OWNER_WRITE OWNER_EXECUTE
     GROUP_READ GROUP_EXECUTE
     WORLD_READ WORLD_EXECUTE )

# create uninstall configuration file
CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/cmake_uninstall.cmake.in"
           "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake"
           IMMEDIATE @ONLY )
# create uninstall target
ADD_CUSTOM_TARGET( uninstall
 "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake" )
# create configuration file from .in file
CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in"
           "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY )
# install configuration file
INSTALL( FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION . )


                                     Jan Engels - Introduction to CMake                        26
CmakeLists.txt template
# display status message for important variables
MESSAGE( STATUS )
MESSAGE( STATUS "-------------------------------------------------------------------------------" )
MESSAGE( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )                                          Here you can display your
MESSAGE( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" )
MESSAGE( STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}" )                                               own project options
MESSAGE( STATUS "CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}" )
MESSAGE( STATUS "${PROJECT_NAME}_DEPENDS = "${${PROJECT_NAME}_DEPENDS}"" )
MESSAGE( STATUS "BUILD_WITH = "${BUILD_WITH}"" )
MESSAGE( STATUS "INSTALL_DOC = ${INSTALL_DOC}" )
MESSAGE( STATUS "Change a value with: cmake -D<Variable>=<Value>" )
MESSAGE( STATUS "-------------------------------------------------------------------------------" )
MESSAGE( STATUS )

# force some variables that could be defined in the command line to be written to cache     And here you should also add
SET( BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS}" CACHE BOOL
   "Set to OFF to build static libraries" FORCE )                                           your own project options to be
SET( CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH                                properly written to cache!
   "Where to install ${PROJECT_NAME}" FORCE )
SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
   "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE )
SET( CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" CACHE PATH
   "Path to custom CMake Modules" FORCE )
SET( INSTALL_DOC "${INSTALL_DOC}" CACHE BOOL
   "Set to OFF to skip build/install Documentation" FORCE )

# export build settings
INCLUDE( CMakeExportBuildSettings )
CMAKE_EXPORT_BUILD_SETTINGS( "${PROJECT_NAME}BuildSettings.cmake" )
# export library dependencies (keep this as the last line in the file)
EXPORT_LIBRARY_DEPENDENCIES( "${PROJECT_NAME}LibDeps.cmake" )



                                                  Jan Engels - Introduction to CMake                                       27
Loading Processors in Marlin
●
    MARLIN_DLL environment variable
     –   $ export MARLIN_DLL=”/path1/lib1.so:/path2/lib2.so:$MARLIN_DLL”
     –   $ ./Marlin steer.xml
     –   Using ILCInstall this information is already added to the generated file
         build_env.sh for the processors found in the config file
●
    Linking Marlin with other shared libraries
     –   Add to your Marlin BuildSetup.cmake
           ●
               SET( LINK_WITH "MarlinReco CEDViewer” CACHE STRING “Link Marlin with
               these optional packages" FORCE )
     –   Or pass it on the command line:
           ●
               $ cmake -C ../BuildSetup.cmake
                –   -DLINK_WITH="mymarlin PandoraPFA"
                –   -Dmymarlin_HOME="path_to_mymarlin
                –   -DPandoraPFA_HOME="path_to_pandora" ..


                                   Jan Engels - Introduction to CMake               28
Loading Processors in Marlin




●
    Linking static libraries (Only works under linux!)
    –   -DLINK_STATIC_WHOLE_LIBS="path_to_library/libMyprocessor.a"
    –   Library gets fully included into the Marlin binary
    –   For more than one library:
          ●
              -DLINK_STATIC_WHOLE_LIBS="/path1/lib1.a;/path2/lib2.a"




                                   Jan Engels - Introduction to CMake   29
CMake Tutorial




●
    3 – ILCInstall with cmake




                 Jan Engels - Introduction to CMake   30
ILCInstall
ilcsoft = ILCSoft("/data/ilcsoft")
ilcsoft.useCMake = True

# python variable for referring the ILC Home directory                    CMake variables to be
ilcPath = "/afs/desy.de/group/it/ilcsoft/"                                passed on the cmd line
                                                                           when building RAIDA
# install RAIDA v01-03
ilcsoft.install( RAIDA( "v01-03" ))
# example for setting cmake variables (“ON”/”OFF” is equivalent to 1/0)
ilcsoft.module( “RAIDA” ).envcmake[“BUILD_RAIDA_EXAMPLE”] = “ON”
ilcsoft.module( “RAIDA” ).envcmake[“RAIDA_DEBUG_VERBOSE_FACTORY”] = 1

# use ROOT at: /afs/desy.de/group/it/ilcsoft/root/5.08.00
ilcsoft.link( ROOT( ilcPath + "root/5.08.00" ))
# use CMakeModules at: /afs/desy.de/group/it/ilcsoft/CMakeModules/v01-00
ilcsoft.use( CMakeModules( ilcPath + "CMakeModules/v01-00" ))
# use CMake at: /afs/desy.de/group/it/ilcsoft/CMake/2.4.6
ilcsoft.use( CMake( ilcPath + "CMake/2.4.6" ))
# End of configuration file



                                     Jan Engels - Introduction to CMake                       31
ILCInstall
●
    After creating the file call:
    –   ilcsoft-install RAIDA.cfg (display summary)
    –   ilcsoft-install RAIDA.cfg -i (install RAIDA)

●
    ILCSoft.cmake is generated by installation script
    –   Placed in the root directory of installation
    –   Contains paths for all packages defined in cfg file
         ●
             Only the ones that are supported by the cmake modules!




                               Jan Engels - Introduction to CMake     32
ILCInstall (Dev)
●
    Under the directory “releases” you find the AFS
    reference-installation configuration files
    –   Copy one of them:
         ●
             Only install packages you want to work on
              –   ilcsoft.module("RAIDA").download.type="ccvssh"
              –   ilcsoft.module("RAIDA").download.username="engels"
         ●
             Change the package dependencies install -> link
              –   ilcsoft.link( ROOT( "/data/myILCSoftware/root/5.08.00" ))
         ●
             Set needed options
              –   ilcsoft.module(“RAIDA”).envcmake[“BUILD_RAIDA_EXAMPLE”] = 1
              –   ilcsoft.module(“RAIDA”).envcmake[“RAIDA_DEBUG_VERBOSE_FAC
                  TORY”] = 1


                                Jan Engels - Introduction to CMake         33
References
●
    http://ilcsoft.desy.de -> General Documentation -> “How to use the CMake
    building tool for the ILC Software”
●
    http://www.cmake.org
     –   Documentation
     –   FAQ
●
    Mastering CMake
     –   Ken Martin, Bill Hoffman
     –   Published by Kitware, Inc.
     –   ISBN: 1-930934-16-5
●
    This talk: http://ilcsoft.desy.de -> General Documentation



                                         Thank you!


                                Jan Engels - Introduction to CMake             34

More Related Content

What's hot

short_intro_to_CMake_(inria_REVES_team)
short_intro_to_CMake_(inria_REVES_team)short_intro_to_CMake_(inria_REVES_team)
short_intro_to_CMake_(inria_REVES_team)Jérôme Esnault
 
Gnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-semGnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-semSagun Baijal
 
An Introduction to CMake
An Introduction to CMakeAn Introduction to CMake
An Introduction to CMakeICS
 
Docker advance topic
Docker advance topicDocker advance topic
Docker advance topicKalkey
 
OpenStack Swift Command Line Reference Diablo v1.2
OpenStack Swift Command Line Reference Diablo v1.2OpenStack Swift Command Line Reference Diablo v1.2
OpenStack Swift Command Line Reference Diablo v1.2Amar Kapadia
 
101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package managementAcácio Oliveira
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Jérôme Petazzoni
 
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Edureka!
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Ahmed El-Arabawy
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn WorkshopBastian Feder
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetesTed Jung
 
RPM (Red Hat Package Manager)
RPM (Red Hat Package Manager)RPM (Red Hat Package Manager)
RPM (Red Hat Package Manager)skalaivanibutp
 
Signature verification of kernel module and kexec
Signature verification of kernel module and kexecSignature verification of kernel module and kexec
Signature verification of kernel module and kexecjoeylikernel
 
Tech talk on docker with demo
Tech talk on docker with demoTech talk on docker with demo
Tech talk on docker with demoSandeep Karnawat
 

What's hot (20)

short_intro_to_CMake_(inria_REVES_team)
short_intro_to_CMake_(inria_REVES_team)short_intro_to_CMake_(inria_REVES_team)
short_intro_to_CMake_(inria_REVES_team)
 
Gnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-semGnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-sem
 
Docker / Ansible
Docker / AnsibleDocker / Ansible
Docker / Ansible
 
An Introduction to CMake
An Introduction to CMakeAn Introduction to CMake
An Introduction to CMake
 
Unix cmc
Unix cmcUnix cmc
Unix cmc
 
NIH package manager for pkgsrc
NIH package manager for pkgsrcNIH package manager for pkgsrc
NIH package manager for pkgsrc
 
Docker advance1
Docker advance1Docker advance1
Docker advance1
 
Docker advance topic
Docker advance topicDocker advance topic
Docker advance topic
 
OpenStack Swift Command Line Reference Diablo v1.2
OpenStack Swift Command Line Reference Diablo v1.2OpenStack Swift Command Line Reference Diablo v1.2
OpenStack Swift Command Line Reference Diablo v1.2
 
101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management
 
Docker_AGH_v0.1.3
Docker_AGH_v0.1.3Docker_AGH_v0.1.3
Docker_AGH_v0.1.3
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...
 
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn Workshop
 
Docker
DockerDocker
Docker
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetes
 
RPM (Red Hat Package Manager)
RPM (Red Hat Package Manager)RPM (Red Hat Package Manager)
RPM (Red Hat Package Manager)
 
Signature verification of kernel module and kexec
Signature verification of kernel module and kexecSignature verification of kernel module and kexec
Signature verification of kernel module and kexec
 
Tech talk on docker with demo
Tech talk on docker with demoTech talk on docker with demo
Tech talk on docker with demo
 

Similar to C make tutorial

LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfThninh2
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s LifeGlobalLogic Ukraine
 
Yocto: Training in English
Yocto: Training in EnglishYocto: Training in English
Yocto: Training in EnglishOtavio Salvador
 
Red Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerRed Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerJustin Bui
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modulesdibyajyotig
 
Privilege Escalation with Metasploit
Privilege Escalation with MetasploitPrivilege Escalation with Metasploit
Privilege Escalation with Metasploitegypt
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache AntShih-Hsiang Lin
 
Autoconf&Automake
Autoconf&AutomakeAutoconf&Automake
Autoconf&Automakeniurui
 
Useful Linux and Unix commands handbook
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbookWave Digitech
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projectsMpho Mphego
 

Similar to C make tutorial (20)

CMake_Tutorial.pdf
CMake_Tutorial.pdfCMake_Tutorial.pdf
CMake_Tutorial.pdf
 
CMake best practices
CMake best practicesCMake best practices
CMake best practices
 
cmake.pdf
cmake.pdfcmake.pdf
cmake.pdf
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
Install guide
Install guideInstall guide
Install guide
 
Install guide
Install guideInstall guide
Install guide
 
Simple build tool
Simple build toolSimple build tool
Simple build tool
 
Linux unix-commands
Linux unix-commandsLinux unix-commands
Linux unix-commands
 
Docker dDessi november 2015
Docker dDessi november 2015Docker dDessi november 2015
Docker dDessi november 2015
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s Life
 
Introduction to CMake
Introduction to CMakeIntroduction to CMake
Introduction to CMake
 
Yocto: Training in English
Yocto: Training in EnglishYocto: Training in English
Yocto: Training in English
 
Red Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerRed Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift Messenger
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
Privilege Escalation with Metasploit
Privilege Escalation with MetasploitPrivilege Escalation with Metasploit
Privilege Escalation with Metasploit
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
Autoconf&Automake
Autoconf&AutomakeAutoconf&Automake
Autoconf&Automake
 
Useful Linux and Unix commands handbook
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbook
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 

Recently uploaded

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

C make tutorial

  • 1. CMake Tutorial ● 1 – Introduction to CMake ● 2 – Using CMake for the ILC Software ● 3 – ILCInstall with CMake Jan Engels DESY 20th September 2007
  • 2. What is CMake ● CMake: – Generates native build environments ● UNIX/Linux -> Makefiles ● Windows -> VS Projects/Workspaces ● Apple -> Xcode – Open-Source :) – Cross-Platform Jan Engels - Introduction to CMake 2
  • 3. CMake Features ● CMake has a lot of nice features: – Manage complex, large build environments (KDE4) – Very Flexible & Extensible ● Support for Macros ● Modules for finding/configuring software (bunch of modules already available) ● Extend CMake for new platforms and languages ● Create custom targets/commands ● Run external programs – Very simple, intuitive syntax – Support for regular expressions (*nix style) – Support for “In-Source” and “Out-of-Source” builds – Cross Compiling – Integrated Testing & Packaging (Ctest, CPack) Jan Engels - Introduction to CMake 3
  • 4. Build-System Generator CMakeLists.txt CMake Native Build System Executables / Libraries Native Build Tools Jan Engels - Introduction to CMake 4
  • 5. CMake Basic Concepts ● CmakeLists.txt – Input text files that contain the project parameters and describe the flow control of the build process in simple CMake language. ● CMake Modules – Special cmake file written for the purpose of finding a certain piece of software and to set it's libraries, include files and definitions into appropriate variables so that they can be used in the build process of another project. (e.g. FindJava.cmake, FindZLIB.cmake, FindQt4.cmake) Jan Engels - Introduction to CMake 5
  • 6. CMake Basic Concepts ● The Source Tree contains: – CMake input files (CmakeLists.txt) – Program source files (hello.cc) – Program header files (hello.h) ● The Binary Tree contains: – Native build system files (Makefiles) – Output from build process: ● Libraries ● Executables ● Any other build generated file ● Source and Binary trees may be: – In the same directory (in-source build) – In different directories (out-of-source build) Jan Engels - Introduction to CMake 6
  • 7. CMake Basic Concepts ● CMAKE_MODULE_PATH – Path to where the CMake modules are located ● CMAKE_INSTALL_PREFIX – Where to put files when calling 'make install' ● CMAKE_BUILD_TYPE – Type of build (Debug, Release, ...) ● BUILD_SHARED_LIBS – Switch between shared and static libraries ● Variables can be changed directly in the build files (CmakeLists.txt) or through the command line by prefixing a variable's name with '-D': – cmake -DBUILD_SHARED_LIBS=OFF ● GUI also available: ccmake Jan Engels - Introduction to CMake 7
  • 8. CMake Cache ● Created in the build tree (CMakeCache.txt) ● Contains Entries VAR:TYPE=VALUE ● Populated/Updated during configuration phase ● Speeds up build process ● Can be initialized with cmake -C <file> ● GUI can be used to change values ● There should be no need to edit it manually!! Jan Engels - Introduction to CMake 8
  • 9. Source Tree Structure Dir3/CMakeLists.txt Dir1/CMakeLists.txt SUBDIRS(Dir3 Dir4) Project's Top-Level CmakeLists.txt Dir4/CMakeLists.txt SUBDIRS(Dir1 Dir2) Dir2/CMakeLists.txt ● Subdirectories added with SUBDIRS/ADD_SUBDIRECTORY ● Child inherits from parent (feature that is lacking in traditional Makefiles) ● Order of processing: Dir1;Dir3;Dir4;Dir2 (When CMake finds a SUBDIR command it stops processing the current file immediately and goes down the tree branch) Jan Engels - Introduction to CMake 9
  • 10. Using CMake ● Create a build directory (“out-of-source-build” concept) – mkdir build ; cd build ● Configure the package for your system: – cmake [options] <source_tree> ● Build the package: Similar to Auto Tools – make ● Install it: – make install ● The last 2 steps can be merged into one (just “make install”) Jan Engels - Introduction to CMake 10
  • 11. Hello World for CMake ● Top-level project directory: – CMakeLists.txt /*hello.h*/ /*hello.cc*/ #ifndef _hello_h #include "hello.h" – Sub-directory Hello: #define _hello_h #include <iostream> using namespace std; ● CMakeLists.txt class Hello { public: void Hello::Print() { ● hello.h void Print(); cout<<"Hello, World!”<<endl; }; } ● hello.cc #endif – Sub-directory Test: ● CMakeLists.txt Library Hello ● test.cc /*test.cc*/ #include <iostream> #include "hello.h" int main() { Hello().Print(); return 0; } Test Binary Jan Engels - Introduction to CMake 11
  • 12. Hello World for CMake # Top-Level CmakeLists.txt PROJECT( HELLO ) ADD_SUBDIRECTORY( Hello ) ADD_SUBDIRECTORY( Test ) # CmakeLists.txt in Hello dir # Adds a library called Hello (libHello.a under Linux) from the source file hello.cc ADD_LIBRARY( Hello hello ) # CmakeLists.txt in Test dir # Make sure the compiler can find include files from our Hello library. INCLUDE_DIRECTORIES(${HELLO_SOURCE_DIR}/Hello) # Add binary called "helloWorld" that is built from the source file "test.cc". # The extension is automatically found. ADD_EXECUTABLE(helloWorld test) # Link the executable to the Hello library. TARGET_LINK_LIBRARIES(helloWorld Hello) Jan Engels - Introduction to CMake 12
  • 13. CmakeLists.txt Files ● Very simple syntax: – # This is a comment – Commands syntax: COMMAND( arg1 arg2 ... ) – Lists A;B;C # semi-colon separated values – Variables ${VAR} – Conditional constructs ● IF() ... ELSE()/ELSEIF() ... ENDIF() – Very useful: IF( APPLE ); IF( UNIX ); IF( WIN32 ) ● WHILE() ... ENDWHILE() ● FOREACH() ... ENDFOREACH() – Regular expressions (check CMake FAQ for details...) Jan Engels - Introduction to CMake 13
  • 14. CmakeLists.txt Files ● INCLUDE_DIRECTORIES( “dir1” “dir2” ... ) ● AUX_SOURCE_DIRECTORY( “source” ) ● ADD_EXECUTABLE ● ADD_LIBRARY Check www.cmake.org -> Documentation ● ADD_CUSTOM_TARGET ● ADD_DEPENDENCIES( target1 t2 t3 ) target1 depends on t2 and t3 ● ADD_DEFINITIONS( “-Wall -ansi -pedantic”) ● TARGET_LINK_LIBRARIES( target-name lib1 lib2 ...) Individual settings for each target ● LINK_LIBRARIES( lib1 lib2 ...) All targets link with the same set of libs ● SET_TARGET_PROPERTIES( ... ) lots of properties... OUTPUT_NAME, VERSION, .... ● MESSAGE( STATUS|FATAL_ERROR “message” ) ● INSTALL( FILES “f1” “f2” “f3” DESTINATION . ) – DESTINATION relative to ${CMAKE_INSTALL_PREFIX} Jan Engels - Introduction to CMake 14
  • 15. CmakeLists.txt Files ● SET( VAR value [CACHE TYPE DOCSTRING [FORCE]]) ● LIST( APPEND|INSERT|LENGTH|GET|REMOVE_ITEM|REMOVE_AT|SORT ...) ● STRING( TOUPPER|TOLOWER|LENGTH|SUBSTRING|REPLACE|REGEX ...) ● SEPARATE_ARGUMENTS( VAR ) convert space separated string to list ● FILE( WRITE|READ|APPEND|GLOB|GLOB_RECURSE|REMOVE|MAKE_DIRECTORY ...) ● FIND_FILE ● FIND_LIBRARY Check www.cmake.org -> Documentation ● FIND_PROGRAM ● FIND_PACKAGE ● EXEC_PROGRAM( bin [work_dir] ARGS <..> [OUTPUT_VARIABLE var] [RETURN_VALUE var] ) ● OPTION( OPTION_VAR “description string” [initial value] ) Jan Engels - Introduction to CMake 15
  • 16. CMake Tutorial ● 2 – Using CMake for the ILC Software Jan Engels - Introduction to CMake 16
  • 17. CMake for the ILC Software ● IMPORTANT: – CMake files for the ILC Software were designed, written and tested exclusively for out-of- source builds, therefore we strongly disencourage in-source builds!! – A package should be installed first (with 'make install') before it can be used by other packages, thus we also strongly disencourage trying to pass the binary-tree from one package as the “installation directory” to other packages. ● Packages with CMake (build) support: – Marlin, MarlinUtil, MarlinReco, CEDViewer, CED, LCIO, GEAR, LCCD, RAIDA, PandoraPFA, LCFIVertex, SiliconDigi, Eutelescope ● CMake modules written for external packages: – CLHEP, CERNLIB, CondDBMySQL, GSL, ROOT, JAVA, AIDAJNI Jan Engels - Introduction to CMake 17
  • 18. Special variables ● BUILD_WITH=”CLHEP GSL” – Tell package to use the libraries, include files and definitions from these packages ● <PKG>_HOME – Variable for defining the home path from a pkg ● Standard CMake Find modules differ slightly from ILC Find modules – ILC Find modules require PKG_HOME variable set ● Enforce version consistency (get rid of setting global environment variables for defining local dependencies) – Could instead be called Config<PKG>.cmake Jan Engels - Introduction to CMake 18
  • 19. Macros ● MacroLoadPackage.cmake – To be able to use a package by using a “Find<PKG>.cmake” module or by using a “<PKG>Config.cmake” file – Assumes the PKG_HOME variable is properly set ● MacroCheckDeps.cmake – Uses MacroLoadPackage.cmake to check dependencies Jan Engels - Introduction to CMake 19
  • 20. Find<PKG>.cmake Modules ● Do the same as <PKG>Config.cmake generated by the cmake build ● Returns variables for using the package – <PKG>_INCLUDE_DIRS – <PKG>_LIBRARIES – <PKG>_DEFINITIONS ● Using the MacroLoadPackage this is automatically done for you Jan Engels - Introduction to CMake 20
  • 21. BuildSetup.cmake ● Script for pre-caching variables/options – SET( VAR “value” CACHE TYPE “description” FORCE ) ● Easy way to change build parameters without having to pass the every time on the cmd line ● Use simple steps to build a package: – mkdir build ; cd build – cmake -C ../BuildSetup.cmake .. – make install ● Still possible to override options on the cmd line Jan Engels - Introduction to CMake 21
  • 22. BuildSetup.cmake ● Can use more than one -C option: – cmake -C ../BuildSetup.cmake -C ~/ILCSoft.cmake – Next file overwrites values from previous file – Useful for overwriting paths defined in a 'more global' file ● CMake just ignores redundant variables from global file ● ILCInstall generates a global file called ILCSoft.cmake ● Check /afs/desy.de/group/it/ilcsoft/v01-01/ILCSoft.cmake as an example Jan Engels - Introduction to CMake 22
  • 23. Adapting your processor to CMake ● Copy from $Marlin/examples/mymarlin – CmakeLists.txt ● change the project name and add missing dependencies (default are Marlin;LCIO) – mymarlinConfig.cmake.in ● rename to <MyProcessor>Config.cmake – BuildSetup.cmake ● change this according to your system setup – cmake_uninstall.cmake.in ● Script for generating a 'make uninstall' target – No changes needed! Jan Engels - Introduction to CMake 23
  • 24. CmakeLists.txt template # cmake file for building Marlin example Package # CMake compatibility issues: don't modify this, please! CMAKE_MINIMUM_REQUIRED( VERSION 2.4.6 ) MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY) # allow more human readable "if then else" constructs SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE ) # User section PROJECT( mymarlin ) # project version SET( ${PROJECT_NAME}_MAJOR_VERSION 0 ) You can add here your own options, SET( ${PROJECT_NAME}_MINOR_VERSION 1 ) but don't forget at the end of the file to SET( ${PROJECT_NAME}_PATCH_LEVEL 0 ) display them with a MESSAGE( STATUS) and to also write them properly to cache! # project options OPTION( BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON ) OPTION( INSTALL_DOC "Set to OFF to skip build/install Documentation" ON ) # project dependencies e.g. SET( ${PROJECT_NAME}_DEPENDS "Marlin MarlinUtil LCIO GEAR CLHEP GSL" ) SET( ${PROJECT_NAME}_DEPENDS "Marlin LCIO" ) # set default cmake build type to RelWithDebInfo (None Debug Release RelWithDebInfo MinSizeRel) IF( NOT CMAKE_BUILD_TYPE ) SET( CMAKE_BUILD_TYPE "RelWithDebInfo" ) ENDIF() # set default install prefix to project root directory IF( CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" ) SET( CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}" ) ENDIF() Jan Engels - Introduction to CMake 24
  • 25. CmakeLists.txt template #include directories INCLUDE_DIRECTORIES( "${PROJECT_SOURCE_DIR}/include" ) Include directories here # install include files INSTALL( DIRECTORY "${PROJECT_SOURCE_DIR}/include" DESTINATION . PATTERN "*~" EXCLUDE PATTERN "*CVS*" EXCLUDE ) # require proper c++ ADD_DEFINITIONS( "-Wall -ansi -pedantic" ) # add debug definitions #IF( CMAKE_BUILD_TYPE STREQUAL "Debug" OR Add your Debug definitions here! # CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" ) # ADD_DEFINITIONS( "-DDEBUG" ) #ENDIF() # get list of all source files If you have more sources you AUX_SOURCE_DIRECTORY( src library_sources ) should add them here (see for ex. ( .... ) LCFIVertex CMakeLists.txt) # DEPENDENCIES: this code has to be placed before adding any library or # executable so that these are linked properly against the dependencies IF( DEFINED ${PROJECT_NAME}_DEPENDS OR DEFINED BUILD_WITH OR DEFINED LINK_WITH ) # load macro IF( NOT EXISTS "${CMAKE_MODULE_PATH}/MacroCheckDeps.cmake" ) MESSAGE( FATAL_ERROR Dependencies are "nSorry, could not find MacroCheckDeps.cmake...n" "Please set CMAKE_MODULE_PATH correctly with: " checked here! "cmake -DCMAKE_MODULE_PATH=<path_to_cmake_modules>" ) ENDIF() INCLUDE( "${CMAKE_MODULE_PATH}/MacroCheckDeps.cmake" ) CHECK_DEPS() ENDIF() Jan Engels - Introduction to CMake 25
  • 26. CmakeLists.txt template # LIBRARY ADD_LIBRARY( lib_${PROJECT_NAME} ${library_sources} ) # create symbolic lib target for calling target lib_XXX ADD_CUSTOM_TARGET( lib DEPENDS lib_${PROJECT_NAME} ) # change lib_target properties SET_TARGET_PROPERTIES( lib_${PROJECT_NAME} PROPERTIES Library # create *nix style library versions + symbolic links VERSION ${${PROJECT_NAME}_VERSION} SOVERSION ${${PROJECT_NAME}_SOVERSION} # allow creating static and shared libs without conflicts CLEAN_DIRECT_OUTPUT 1 # avoid conflicts between library and binary target names OUTPUT_NAME ${PROJECT_NAME} ) # install library INSTALL( TARGETS lib_${PROJECT_NAME} DESTINATION lib PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) # create uninstall configuration file CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY ) # create uninstall target ADD_CUSTOM_TARGET( uninstall "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake" ) # create configuration file from .in file CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY ) # install configuration file INSTALL( FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION . ) Jan Engels - Introduction to CMake 26
  • 27. CmakeLists.txt template # display status message for important variables MESSAGE( STATUS ) MESSAGE( STATUS "-------------------------------------------------------------------------------" ) MESSAGE( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" ) Here you can display your MESSAGE( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" ) MESSAGE( STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}" ) own project options MESSAGE( STATUS "CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}" ) MESSAGE( STATUS "${PROJECT_NAME}_DEPENDS = "${${PROJECT_NAME}_DEPENDS}"" ) MESSAGE( STATUS "BUILD_WITH = "${BUILD_WITH}"" ) MESSAGE( STATUS "INSTALL_DOC = ${INSTALL_DOC}" ) MESSAGE( STATUS "Change a value with: cmake -D<Variable>=<Value>" ) MESSAGE( STATUS "-------------------------------------------------------------------------------" ) MESSAGE( STATUS ) # force some variables that could be defined in the command line to be written to cache And here you should also add SET( BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS}" CACHE BOOL "Set to OFF to build static libraries" FORCE ) your own project options to be SET( CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH properly written to cache! "Where to install ${PROJECT_NAME}" FORCE ) SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE ) SET( CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" CACHE PATH "Path to custom CMake Modules" FORCE ) SET( INSTALL_DOC "${INSTALL_DOC}" CACHE BOOL "Set to OFF to skip build/install Documentation" FORCE ) # export build settings INCLUDE( CMakeExportBuildSettings ) CMAKE_EXPORT_BUILD_SETTINGS( "${PROJECT_NAME}BuildSettings.cmake" ) # export library dependencies (keep this as the last line in the file) EXPORT_LIBRARY_DEPENDENCIES( "${PROJECT_NAME}LibDeps.cmake" ) Jan Engels - Introduction to CMake 27
  • 28. Loading Processors in Marlin ● MARLIN_DLL environment variable – $ export MARLIN_DLL=”/path1/lib1.so:/path2/lib2.so:$MARLIN_DLL” – $ ./Marlin steer.xml – Using ILCInstall this information is already added to the generated file build_env.sh for the processors found in the config file ● Linking Marlin with other shared libraries – Add to your Marlin BuildSetup.cmake ● SET( LINK_WITH "MarlinReco CEDViewer” CACHE STRING “Link Marlin with these optional packages" FORCE ) – Or pass it on the command line: ● $ cmake -C ../BuildSetup.cmake – -DLINK_WITH="mymarlin PandoraPFA" – -Dmymarlin_HOME="path_to_mymarlin – -DPandoraPFA_HOME="path_to_pandora" .. Jan Engels - Introduction to CMake 28
  • 29. Loading Processors in Marlin ● Linking static libraries (Only works under linux!) – -DLINK_STATIC_WHOLE_LIBS="path_to_library/libMyprocessor.a" – Library gets fully included into the Marlin binary – For more than one library: ● -DLINK_STATIC_WHOLE_LIBS="/path1/lib1.a;/path2/lib2.a" Jan Engels - Introduction to CMake 29
  • 30. CMake Tutorial ● 3 – ILCInstall with cmake Jan Engels - Introduction to CMake 30
  • 31. ILCInstall ilcsoft = ILCSoft("/data/ilcsoft") ilcsoft.useCMake = True # python variable for referring the ILC Home directory CMake variables to be ilcPath = "/afs/desy.de/group/it/ilcsoft/" passed on the cmd line when building RAIDA # install RAIDA v01-03 ilcsoft.install( RAIDA( "v01-03" )) # example for setting cmake variables (“ON”/”OFF” is equivalent to 1/0) ilcsoft.module( “RAIDA” ).envcmake[“BUILD_RAIDA_EXAMPLE”] = “ON” ilcsoft.module( “RAIDA” ).envcmake[“RAIDA_DEBUG_VERBOSE_FACTORY”] = 1 # use ROOT at: /afs/desy.de/group/it/ilcsoft/root/5.08.00 ilcsoft.link( ROOT( ilcPath + "root/5.08.00" )) # use CMakeModules at: /afs/desy.de/group/it/ilcsoft/CMakeModules/v01-00 ilcsoft.use( CMakeModules( ilcPath + "CMakeModules/v01-00" )) # use CMake at: /afs/desy.de/group/it/ilcsoft/CMake/2.4.6 ilcsoft.use( CMake( ilcPath + "CMake/2.4.6" )) # End of configuration file Jan Engels - Introduction to CMake 31
  • 32. ILCInstall ● After creating the file call: – ilcsoft-install RAIDA.cfg (display summary) – ilcsoft-install RAIDA.cfg -i (install RAIDA) ● ILCSoft.cmake is generated by installation script – Placed in the root directory of installation – Contains paths for all packages defined in cfg file ● Only the ones that are supported by the cmake modules! Jan Engels - Introduction to CMake 32
  • 33. ILCInstall (Dev) ● Under the directory “releases” you find the AFS reference-installation configuration files – Copy one of them: ● Only install packages you want to work on – ilcsoft.module("RAIDA").download.type="ccvssh" – ilcsoft.module("RAIDA").download.username="engels" ● Change the package dependencies install -> link – ilcsoft.link( ROOT( "/data/myILCSoftware/root/5.08.00" )) ● Set needed options – ilcsoft.module(“RAIDA”).envcmake[“BUILD_RAIDA_EXAMPLE”] = 1 – ilcsoft.module(“RAIDA”).envcmake[“RAIDA_DEBUG_VERBOSE_FAC TORY”] = 1 Jan Engels - Introduction to CMake 33
  • 34. References ● http://ilcsoft.desy.de -> General Documentation -> “How to use the CMake building tool for the ILC Software” ● http://www.cmake.org – Documentation – FAQ ● Mastering CMake – Ken Martin, Bill Hoffman – Published by Kitware, Inc. – ISBN: 1-930934-16-5 ● This talk: http://ilcsoft.desy.de -> General Documentation Thank you! Jan Engels - Introduction to CMake 34