Introduction to CMake, v. 2

Slides:



Advertisements
Similar presentations
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Advertisements

Lecture 3 Getting Started with ITK!. Goals for this lecture Learn how to use Cmake Build ITK Example programs that use ITK.
Cygwin Linux for Windows Desktop Paul Stuyvesant.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Introduction to Perl Learning Objectives: 1. To introduce the features provided by Perl 2. To learn the basic Syntax & simple Input/Output control in Perl.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
Building with MPC Charles Calkins Principal Software Engineer Object Computing, Inc.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Software Process, CMake, Dashboards, CPack Bill Hoffman Kitware, Inc.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Unclassified/FOUO Zeta White Noise Hour Presents: NeXtMidas / X-Midas Interoperability 18 Jan 2006.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Chapter Nine Advanced Shell Scripting1 System Programming Advanced Shell Scripting.
Understanding the CORBA Model. What is CORBA?  The Common Object Request Broker Architecture (CORBA) allows distributed applications to interoperate.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
CSnake C++ build automation based on CMake and Python Maarten Nieber, 2009.
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
Makefiles CISC/QCSE 810. BeamApp and Tests in C++ 5 source code files After any modification, changed source needs to be recompiled all object files need.
Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.cpp.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
Cygwin Linux for Windows Desktop Paul Stuyvesant.
Programming With C.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
FairRoot Build and Test System
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
Installing CompuCell3D from source Maciej Swat Biocomplexity Institute, Indiana University.
System Programming - LAB 1 Programming Environments.
CMake refactoring P. Hristov 19/03/2014. History I  Recursive makefiles (F.Carminati):  Problems in dependencies  Slow  "Recursive Makefiles.
Operating System What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. An operating.
Introduction to Perl Yupu Liang cbio at MSKCC
Introduction to Perl Part III By: Bridget Thomson McInnes 6 Feburary 2004.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
Multiple File Compilation and linking By Bhumik Sapara.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Build Tools 1. Building a program for a large project is usually managed by a build tool that controls the various steps involved. These steps may include:
Ravi Mathur January 8,  What does CMake NOT do? ◦ Doesn’t compile (gcc, MSVC, llvm, make) ◦ Doesn’t manage source code (XCode, Visual Studio) ◦
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Linux Administration Working with the BASH Shell.
 CSC 215 : Procedural Programming with C C Compilers.
CMake: Experience in ALICE P. Hristov 19/06/12. History I Recursive makefiles (F.Carminati): – Problems in dependencies – Slow "Recursive Makefiles.
Software development tools
CMake - Cross-Platform Make R. Douglas Barbieri Made to Order Software Corporation.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
The make utility (original presentation courtesy of Alark Joshi)
CSC 215 : Procedural Programming with C
Build and Test system for FairRoot
CIRC Winter Boot Camp 2017 Baowei Liu
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Editor, Compiler, Linker, Debugger, Makefiles
Introduction to C Programming Language
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
C Programming Lecture Series
Operation System Program 4
Introduction to Python
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Cmake Primer.
Govt. Polytechnic,Dhangar
Intro to shell scripting
Introduction to Perl Learning Objectives:
Preparation for Assignment 2
Compiler vs linker The compiler translates one .c file into a .o file
SPL – PS1 Introduction to C++.
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

Introduction to CMake, v. 2 Content: Basic CMake usage Ready to use samples Advanced CMake usage Document history: 2009 Constantine Shulyupin, http://www.makelinux.net/ 2007 Jan Engels, DESY, http://ilcsoft.desy.de/

Purposes of a build system Efficiency: Save time on recompilations Flexibility: Configure compilation parameters (optimization, logging, debug and release builds) Scalability: Manage subproject and libraries Portability: Compile for different platforms Introduction to CMake, v. 2

Introduction to CMake, v. 2 Major CMake features Generates native build environments UNIX/Linux -> Makefiles Windows -> VS Projects/Workspaces Apple -> Xcode Eclipse projects Big library of helper commands (Finders) Cross-Platform (easy to port) Introduction to CMake, v. 2

Introduction to CMake, v. 2 Build process Target projects: CMake Source file: Makefile CMakeLists.txt CMakeLists.txt CMakeLists.txt CMake Eclipse Generated internal files: KDevelop CMakeCache.txt MS Visual Studio CMakeFiles/ And other Introduction to CMake, v. 2

Introduction to CMake, v. 2 CMake source file CMakeLists.txt Input text files that contain the project parameters and describe the flow control of the build process in simple CMake language. Introduction to CMake syntax: # This is a comment command(argument1 argument2 ...argumentN) COMMAND(argument1 argument2 ...argumentN) Introduction to CMake, v. 2

Introduction to CMake, v. 2 “Hello world!” File hello.c : int main() { printf("Hello, world!\n"); } File CMakeLists.txt : add_executable(hello hello.c) Shell: $ cmake . $ make $ ./hello Hello, world! Introduction to CMake, v. 2

Introduction to CMake, v. 2 Using Libraries For C source code: ... pthread_create(&pt, NULL, routine, NULL); Add to CMakeLists.txt : target_link_libraries(pthread) Introduction to CMake, v. 2

Introduction to CMake, v. 2 Creating Libraries Initial source file: common.h common.c Target library file: libcommon.so CMakeLists.txt : add_library (common SHARED common.c) Introduction to CMake, v. 2

Woking with subdirectories Defining subproject: add_subdirectory(sub) CMake adds subdirectory to dependency. Child inherits from parent Search include files in subdirectories: include_directories(sub) Search libraries in subdirectories link_directories(sub) Introduction to CMake, v. 2

Additional useful commands project (projectname [CXX] [C] [Java]) This creates the variables projectname_BINARY_DIR and projectname_SOURCE_DIR. cmake_minimum_required (VERSION 2.6) Set the minimum required version of cmake for a project. add_definitions (-g) Arguments are passed to compiler (like CFLAGS) message (text) Prints text Introduction to CMake, v. 2

Introduction to CMake, v. 2 Most useful commands project(name C CPP JAVA) cmake_minimum_required(VERSION 2.6) add_definitions(-g) # added to CFLAGS add_library(common SHARED common.c) add_subdirectory(sub) include_directories(sub) link_directories(sub) add_executable(app app.c) target_link_libraries(app common pthread) message(text) - 10 most useful functions for 90% of projects Introduction to CMake, v. 2

Introduction to CMake, v. 2 Advanced facilities Variables and lists Variables cache Out-of-source build Finding libraries Regular expressions Flow control Reusable code: includes and macros Installers Cross-compilation Introduction to CMake, v. 2

Introduction to CMake, v. 2 Variables and Lists Variables: set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") message(CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}) cmake -D <var>:<type>=<value> # define variable and store in cache Lists set(L 1;2;3) # semi-colon is list separator list(APPEND L a b c ) message("\${L}=" ${L}) message("\"\${L}\"=" "${L}") Output: ${L}=123abc "${L}"=1;2;3;a;b;c Introduction to CMake, v. 2

Introduction to CMake, v. 2 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 Introduction to CMake, v. 2

Introduction to CMake, v. 2 Out-of-source build Out-of-source build used to separate build files from sources. Very useful for multi- platform development. Change to a build directory and give path to the sources as argument: mkdir -p ../build; cd ../build rm -f ../hello/CMakeCache.txt # cleanup after in-source build cmake ../hello make Introduction to CMake, v. 2

Introduction to CMake, v. 2 Finding libraries Special cmake file written for the purpose of finding a certain piece of software and to set its 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) More than 300 modules located in /usr/share/cmake-2.6/Modules/ E.g. some lines from /usr/share/cmake-2.6/Modules/Platform/ Linux.cmake : SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-rdynamic") SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") Introduction to CMake, v. 2

Introduction to CMake, v. 2 Regular expressions Warning: non Perl compatible set (S "abc") string (REGEX REPLACE "b.*" "BC" S ${S}) set (VER 1.2) string (REGEX MATCHALL "([0-9]+)" NUMS "${VER}") # NUMS is list Introduction to CMake, v. 2

Introduction to CMake, v. 2 Flow control Most useful: if (exp) elseif (exp2) else ([exp]) endif ([exp]) And other: foreach while Introduction to CMake, v. 2

Introduction to CMake, v. 2 Reusable code include (<file|module>) macro (<name> [arg1 [arg2 [arg3 …]]]) command1 (ARGS ...) command2 (ARGS …) endmacro (<name>) function (<name> [arg1 [arg2 [arg3 …]]]) command1 (ARGS …) command2 (ARGS ...) endfunction (<name>) Introduction to CMake, v. 2

Introduction to CMake, v. 2 Installers Could be very simple install (TARGETS hello DESTINATION /tmp) Or more complex: set(CMAKE_INSTALL_PREFIX ....) install (TARGETS targets... [EXPORT <export- name>] [[ARCHIVE|LIBRARY|RUNTIME|FRAMEW ORK|BUNDLE| PRIVATE_HEADER|PUBLIC_HEADER|RES OURCE] [DESTINATION <dir>] [PERMISSIONS permissions...] [CONFIGURATIONS [Debug|Release|...]] [COMPONENT <component>] [OPTIONAL] [NAMELINK_ONLY|NAMELINK_SKIP] ] [...]) Introduction to CMake, v. 2

Introduction to CMake, v. 2 Cross-compilation arm.cmake file: set (CMAKE_SYSTEM_NAME Linux) set ( CMAKE_C_COMPILER /opt/arm- 2009q1/bin/arm-none-linux-gnueabi-gcc) set ( CMAKE_CXX_COMPILER /opt/arm- 2009q1/bin/arm-none-linux-gnueabi-gcc) set ( CMAKE_FIND_ROOT_PATH /opt/arm- 2009q1/arm-none-linux-gnueabi/) # adjust the default behaviour of the FIND_XXX() commands: set (CMAKE_FIND_ROOT_PATH_MODE_PROGR AM NEVER) set (CMAKE_FIND_ROOT_PATH_MODE_LIBRAR Y ONLY) set (CMAKE_FIND_ROOT_PATH_MODE_INCLUD E ONLY) $ cmake - DCMAKE_TOOLCHAIN_FILE=arm.cmake Introduction to CMake, v. 2

Well known CMake usages KDE MySQL (on Windows only) Introduction to CMake, v. 2

Introduction to CMake, v. 2 Samples Sample sources for the presentation: http://www.linuxdriver.co.il/tools/CMake/ KDE: http://websvn.kde.org/trunk/KDE/kdetoys/ http://websvn.kde.org/trunk/KDE/kdelibs/ Introduction to CMake, v. 2

Introduction to CMake, v. 2 Further readings http://www.makelinux.net/reference?n=CMake http://www.cmake.org/ http://www.cmake.org/Wiki/ http://kernigh.pbworks.com/CMake Introduction to CMake, v. 2