CMAKE AN INTRODUCTION



Similar documents
Introduction CMake Language Specific cases. CMake Tutorial. How to setup your C/C++ projects? Luis Díaz Más.

CMPT 373 Software Development Methods. Building Software. Nick Sumner Some materials from Shlomi Fish & Kitware

Mastering CMake. Sixth Edition. Bill Martin & Hoffman. Ken. Andy Cedilnik, David Cole, Marcus Hanwell, Julien Jomier, Brad King, Robert Maynard,

Generating Visual Studio Project Files

CMake/CTest/CDash OSCON 2009

Installing OpenVSP on Windows 7

Supported platforms & compilers Required software Where to download the packages Geant4 toolkit installation (release 9.6)

Andreas Burghart 6 October 2014 v1.0

How to Write a Simple Makefile

A Cross Platform Development Workflow for C/C++ Applications.

Building Software Systems. Multi-module C Programs. Example Multi-module C Program. Example Multi-module C Program

Why this lecture exists ITK Lecture 12: Open Source & Cross Platform Software Development

GTk+ and GTkGLExt Build Process for Windows 32- bit

Lazy OpenCV installation and use with Visual Studio

CSC230 Getting Starting in C. Tyler Bletsch

Surface and Volumetric Data Rendering and Visualisation

TNM093 Practical Data Visualization and Virtual Reality Laboratory Platform

[PRAKTISCHE ASPEKTE DER INFORMATIK SS 2014]

Introduction to Linux and Cluster Basics for the CCR General Computing Cluster

PetaLinux SDK User Guide. Application Development Guide

Setting Up a CLucene and PostgreSQL Federation

CS 2112 Lab: Version Control

A Crash Course on UNIX

OHJ-1860: Software systems seminar: Used tools and mechanisms in Open Source projects

C Programming Review & Productivity Tools

GR A universal framework for visualization applications

Documentation Installation of the PDR code

Software documentation systems

Code Estimation Tools Directions for a Services Engagement

Introduction to Python

Chapter 1: Getting Started

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Brent A. Perdue. July 15, 2009

Internet Payment Gateway

Source Code Review Using Static Analysis Tools

Code::Block manual. for CS101x course. Department of Computer Science and Engineering Indian Institute of Technology - Bombay Mumbai

RTI Monitoring Library Getting Started Guide

An Incomplete C++ Primer. University of Wyoming MA 5310

Main Bullet #1 Main Bullet #2 Main Bullet #3

Professional. SlickEdif. John Hurst IC..T...L. i 1 8 О 7» \ WILEY \ Wiley Publishing, Inc.

Version Control with Subversion

UNICORE UFTPD server UNICORE UFTPD SERVER. UNICORE Team

Eclipse.org CDT and Cygwin: A Tutorial on Installation and Functionality

OpenWBEM Getting Started Guide. Author: Dan Nuffer Last update: 12/09/04

Opencv examples on Kinect

Running the shell. Tcl/Tk demo. Tcl stuff. Starting Tcl/Tk. If-then-else

Neutron Science Visualization Software

Virtuozzo Virtualization SDK

Introduction. Created by Richard Bell 10/29/2014

CSE 374 Programming Concepts & Tools. Laura Campbell (Thanks to Hal Perkins) Winter 2014 Lecture 16 Version control and svn

Using Buildroot for real projects

Table of Contents. The RCS MINI HOWTO

Working with HPC and HTC Apps. Abhinav Thota Research Technologies Indiana University

To connect to the cluster, simply use a SSH or SFTP client to connect to:

Using EDA Databases: Milkyway & OpenAccess

A Conceptual Map of Open Source Software for Image Processing

Image Acquisition Toolbox Adaptor Kit User's Guide

Embedded Software Development

CS 103 Lab Linux and Virtual Machines

Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11

CSCE 665: Lab Basics. Virtual Machine. Guofei Gu

ESPResSo Summer School 2012

Installing FEAR on Windows, Linux, and Mac Systems

MatrixSSL Getting Started

MySQL Connector/C++ Developer Guide

OpenWalnut An Open-Source Visualization System

Version Control with Svn, Git and git-svn. Kate Hedstrom ARSC, UAF

Creating OpenGL applications that use GLUT

Software Development Tools for Embedded Systems. Hesen Zhang

Buildroot Workshop. Libre Software Meeting Thomas Petazzoni Free Electrons

Installing GD Graphics Library on Mac OS X Server 10.5.x for 64- and 32-bit CPUs

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

Overview. Lecture 1: an introduction to CUDA. Hardware view. Hardware view. hardware view software view CUDA programming

APPLICATIONS OF LINUX-BASED QT-CUDA PARALLEL ARCHITECTURE

Chapter 13 - The Preprocessor

Table of Contents. Java CGI HOWTO

BASIC SMARTFROG COMPONENTS AUTOMATED SOFTWARE INSTALLATION

CS Software Engineering for Scientific Computing. Lecture 25:Mixed Language Programming.

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

The C Programming Language course syllabus associate level

SciTools Understand Flavor for Structure 101g

Overview. Open source toolchains. Buildroot features. Development process

RTI Connext DDS. Core Libraries Getting Started Guide Addendum for Android Systems Version 5.2.0

Using Git for Project Management with µvision

Open Watcom Linux Port GUI Software Requirements Specification

Documentation and Project Organization

Leak Check Version 2.1 for Linux TM

Transcription:

CMAKE AN INTRODUCTION Graduiertenkolleg EMS Robert Jakob

GOAL Source Executable I don t You care

GOAL interface description generated.h generated.cpp foo.h foo.cpp bar.cpp fb.cpp You care Executable internet.lib internet.h pde-solver.lib, 2.0 < Version <= 2.1.3

GOAL interface description generated.h generated.cpp Win exe foo.h foo.cpp bar.cpp fb.cpp You care Linux exe Mac exe Debug Release Installer internet.lib internet.h Library pde-solver.lib, 2.0 < Version <= 2.1.3

HELP?! GOAL interface description generated.h generated.cpp Win exe foo.h foo.cpp bar.cpp fb.cpp You care Linux exe Mac exe Debug Release Installer internet.lib internet.h Library pde-solver.lib, 2.0 < Version <= 2.1.3

SOLUTIONS GNU Build system (aka Autotools)./configure && make && make install qmake Qt by Nokia s build system Scons Python-based build system cmake cross-plattform make system

WHAT IS IT? CMake is a build-process management tool Platform independent Supports various output formats Dependencies Libraries

WORKFLOW Configuration CMakeLists.txt cmake Makefile Files

WORKFLOW Configuration CMakeLists.txt cmake Project files Makefile Files

WORKFLOW Configuration CMakeLists.txt cmake Project files Makefile Files

MAKEFILES (IDEA) Makefiles execute commands depending on some conditions Makefiles consist of targets, dependencies, and commands: target: {dependency} {cmd} foo.exe: foo.c another_target compile --input=foo.c --output=foo.exe make foo.exe last_change (foo.exe) < last_change(foo.c): compile last_change (foo.exe) => last_change(foo.c): nothing

THE BASICS

EXAMPLE PROJECT #include <stdio.h> #include <string.h> #include <bzlib.h> #include "adder.h" int main(int argc, char* argv[]) { int bzerror = 0; char buffer[51]; int result; FILE *tbz2file = fopen(argv[1], "rb"); memset(&buffer,0,51); BZFILE *bz = BZ2_bzReadOpen(&bzError, tbz2file, 0, 0, 0, 0); BZ2_bzRead(&bzError, bz, buffer, 50); printf("%50s\n", buffer); result = add(buffer); printf("result: %d\n", result); fclose(tbz2file); } return 0;

EXAMPLE PROJECT #include <stdio.h> #include <string.h> #include <bzlib.h> #include "adder.h" Dependencies int main(int argc, char* argv[]) { int bzerror = 0; char buffer[51]; int result; FILE *tbz2file = fopen(argv[1], "rb"); memset(&buffer,0,51); Starting point of program BZFILE *bz = BZ2_bzReadOpen(&bzError, tbz2file, 0, 0, 0, 0); BZ2_bzRead(&bzError, bz, buffer, 50); printf("%50s\n", buffer); Program code result = add(buffer); printf("result: %d\n", result); fclose(tbz2file); } return 0;

MANUAL COMPILATION Compilation command line: gcc -g -c adder.c produces adder.o gcc -g -c main.c produces main.o Linking gcc -g adder.o main.o -lbz2 produces a.out You don t want to run all this steps manually

DEPENDENCIES Main.c depends on adder.h Change adder.h means recompilation of main.c And linking of all object files

ABOUT DIRECTORIES Good directory structure build-debug build-release CMakeLists.txt src adder.c adder.h main.c tests test.txt.bz2

CMAKELISTS.TXT project(mygitness) cmake_minimum_required(version 2.6) add_definitions(-wall) include_directories(${cmake_current_binary_dir}) set(source src/main.c src/adder.c) add_executable(cmakeexample ${SOURCE}) Script execution find_package (BZip2) include_directories(${bzip_include_dirs}) target_link_libraries (cmakeexample ${BZIP2_LIBRARIES})

CMAKELISTS.TXT project(mygitness) cmake_minimum_required(version 2.6) Preamble add_definitions(-wall) include_directories(${cmake_current_binary_dir}) set(source src/main.c src/adder.c) add_executable(cmakeexample ${SOURCE}) find_package (BZip2) include_directories(${bzip_include_dirs}) target_link_libraries (cmakeexample ${BZIP2_LIBRARIES}) Source file definitions Defining targets Libraries to link to

COMMANDS Basic syntax command(args...) Project definition project (name [CXX] [C] [JAVA]) Setting a variable set(variable 2) Using a variable ${VARIABLE}

FLOW CONTROL Conditionals if (FOO) # comments else (FOO) # comments endif (FOO) If, else, and endif need argument! (may be empty) FOO is true if it is 1,ON, YES, TRUE, Y

CONDITIONAL if(var) if(n1 IS_NEWER_THAN n2) if(not var) if(var MATCHES regex) if(var AND var) if(1 LESS 3) if(var OR var) if(foo STRLESS BAR) if(defined var) if(exists filename) if(exists dirname)

LOOPS / MESSAGES set(src adder.c main.c) message( Printing all source files: ) if(not DEFINED SRC) message (FATAL_ERROR No sources defined ) endif () foreach (file ${SRC}) message(${file}) endforeach () message( Done printing all source files ) There is also a while loop

TARGETS Defining a new target of type executable add_executable(foo.exe ${SRC}) Defining a new target of type library add_library(foo STATIC foo1.c foo2.c) add_library(foo SHARED foo1.c foo2.c) Defining an arbitrary target add_custom_target(...)

INCLUDE DIRECTORIES Add additional include directories include_directories(include_dir) Add the output build directory (e.g. generated files in Qt) include_directories(${cmake_current_binary_dir}) Can be called multiple times and appends to the include dirs.

LIBRARIES Linking to libraries is simple target_link_libraries(foo path_to_lib1 path_to_lib2) How to get the path to the library?

FINDING LIBRARIES Looking for the TCL Library find_library (TCL_LIBRARY NAMES tcl tcl84 tcl83 tcl82 tcl80 PATHS /usr/lib /usr/local/lib) if (TCL_LIBRARY) target_link_library(fooexe ${TCL_LIBRARY}) endif ()

PREDEFINED MODULES ALSA Armadillo ASPELL AVIFile BISON BLAS Boost Bullet BZip2 CABLE Coin3D CUDA Cups CURL Curses CVS CxxTest Cygwin Dart DCMTK DevIL Doxygen EXPAT FLEX FLTK2 FLTK Freetype GCCXML GDAL Gettext GIF Git GLU GLUT Gnuplot GnuTLS GTest GTK2 GTK HDF5 HSPELL HTMLHelp ImageMagick ITK Jasper Java JNI JPEG KDE3 KDE4 LAPACK LATEX LibArchive LibXml2 LibXslt Lua50 Lua51 Matlab MFC Motif MPEG2 MPEG MPI OpenAL OpenGL OpenMP OpenSceneGraph OpenSSL OpenThreads osganimation osg osgdb osg_functions osgfx osgga osgintrospection osgmanipulator osgparticle osgproducer osgshadow osgsim osgterrain osgtext osgutil osgviewer osgvolume osgwidget PackageHandleStandard Args PackageMessage Perl PerlLibs PHP4 PhysFS Pike PkgConfig PNG PostgreSQL Producer Protobuf PythonInterp PythonLibs QJSON Qt3 Qt4 Qt QuickTime RTI Ruby SDL SDL_image SDL_mixer SDL_net SDL_sound SDL_ttf SelfPackers Squish Subversion SWIG TCL Tclsh TclStub Threads TIFF UnixCommands VTK Wget Wish wxwidgets wxwindows X11 XMLRPC ZLIB

USE PREDEFINED MODULES Predefined find -modules search for the libraries and define variables # BZIP2_FOUND - system has BZip2 # BZIP2_INCLUDE_DIR - the BZip2 include directory # BZIP2_LIBRARIES - Link these to use BZip2 # BZIP2_NEED_PREFIX - this is set if the functions are prefixed with BZ2_find_package (BZip2) include_directories(${bzip_include_dirs}) target_link_libraries (cmakeexample ${BZIP2_LIBRARIES})

CMAKELISTS.TXT project(mygitness) cmake_minimum_required(version 2.6) add_definitions(-wall) include_directories(${cmake_current_binary_dir}) set(source src/main.c src/adder.c) add_executable(cmakeexample ${SOURCE}) find_package (BZip2) include_directories(${bzip_include_dirs}) target_link_libraries (cmakeexample ${BZIP2_LIBRARIES})

BUILD PROCESS. $ cd build-debug/./build-debug $ cmake../ -- The C compiler identification is GNU -- The CXX compiler identification is GNU -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Found BZip2: /usr/lib/libbz2.so -- Looking for BZ2_bzCompressInit in /usr/lib/libbz2.so -- Looking for BZ2_bzCompressInit in /usr/lib/libbz2.so - found -- Configuring done -- Generating done -- Build files have been written to: /home/jakobro/projects/cmake-example-app/build-debug./build-debug $ make Scanning dependencies of target cmakeexample [ 50%] Building C object CMakeFiles/cmakeexample.dir/src/main.c.o [100%] Building C object CMakeFiles/cmakeexample.dir/src/adder.c.o Linking C executable cmakeexample [100%] Built target cmakeexample

BUILD PROCESS./build-debug $ change../src/main.c./build-debug $ make Scanning dependencies of target cmakeexample [ 50%] Building C object CMakeFiles/cmakeexample.dir/src/main.c.o Linking C executable cmakeexample [100%] Built target cmakeexample

BUILD PROCESS When do we have to call cmake again? Normally, no call to cmake necessary Not even if we change something inside./build-debug $ change../cmakelists.txt./build-debug $ make -- Configuring done -- Generating done -- Build files have been written to: /home/jakobro/projects/cmake-example-app/build-debug [ 50%] Building C object CMakeFiles/cmakeexample.dir/src/main.c.o [100%] Building C object CMakeFiles/cmakeexample.dir/src/adder.c.o Linking C executable cmakeexample [100%] Built target cmakeexample

BUILD PROCESS cmake has an internal cache (build-debug/cmakecache.txt) If changing cached variables, makefile is not recreated! Solution:./build-debug $ make rebuild_cache Running CMake to regenerate build system... -- Configuring done -- Generating done -- Build files have been written to: build-debug

PROBLEMS If you want to see what cmake really does cmake --debug-output If you want to see the commands make runs make VERBOSE=1

ERROR SOLUTION CHAIN Error when running make Try: make clean && make make rebuild_cache Try: rm -R build-debug/ Try: mkdir build-debug && cmake../ Error when running cmake cmake --debug-output../ cmake --trace../ (This will get you lots of output)

ADVANCED STUFF

SUBCONFIGS If you have submodules and want them to have an extra config build-debug build-release CMakeLists.txt // toplevel config src adder.c adder.h main.c mymathmodule CMakeLists.txt // subconfig math.cpp

SUBCONFIGS Two possibilities: Subconfig creates its own executable/library which is used by toplevel config Only describes source and header files and toplevel adds them to its build process

TOPLEVEL CONFIGURATION set(source ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ) add_subdirectory("${project_source_dir}/mymathmodule") add_executable(fooexec ${SOURCE} ${HEADERS})

SUBCONFIG set(source ${SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/file1.cpp ${CMAKE_CURRENT_SOURCE_DIR}/file2.cpp PARENT_SCOPE ) set(headers ${HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/file1.hpp ${CMAKE_CURRENT_SOURCE_DIR}/file2.hpp PARENT_SCOPE )

DEBUG/RELEASE BUILDS Either give the cmake process a variable: cmake -DCMAKE_BUILD_TYPE=Debug cmake -DCMAKE_BUILD_TYPE=Release or specify it in the config SET(CMAKE_BUILD_TYPE Debug)

OPTIONS User-definable options building optional parts of the application using special math library Shows up in GUI option(build_special_part Build special part OFF) $ cmake -DBUILD_SPECIAL_PART=ON

CONFIGURE FILE Preprocessor definitions from cmake to Code? #ifdef BUILD_SPECIAL_PART... #endif

CONFIGURE FILE Copy file from in_file to out_file and replace all variables with their values: configure_file( {$PROJECT_SOURCE_DIR}/configure.h.in {$PROJECT_BINARY_DIR}/configure.h ) Configure.h.in: #cmakedefine BUILD_SPECIAL_PART Configure.h: #define BUILD_SPECIAL_PART or /* #define BUILD_SPECIAL_PART */ Access to values of variables @VARNAME@

BEYOND CMAKE CPack Installer creation CTest Large test framework LaTeX http://www.cmake.org/wiki/cmake_faq#how_do_i_use_cmake_to_build_latex_documents.3f

REFERENCES Martin and Hoffmann: Mastering CMake (Available in our library) CMake useful variables http://www.cmake.org/wiki/cmake_useful_variables FAQ http://www.cmake.org/wiki/cmake_faq The CMake documentation http://www.cmake.org/cmake/help/documentation.html

Questions?