0% found this document useful (0 votes)
21 views11 pages

HPC Cmakeshort

Uploaded by

Rajul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views11 pages

HPC Cmakeshort

Uploaded by

Rajul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Building projects with CMake

Victor Eijkhout

Fall 2023

1 Eijkhout – CMake tutorial – Fall 2023


Justification

CMake is a portable build system that is becoming a de facto standard for


C++ package management.
Also usable with C and Fortran.

2 Eijkhout – CMake tutorial – Fall 2023


Table of contents

1 Help! This software uses CMake!

2 Help! I want to write CMake myself!

3 Help! I want people to use my CMake package!

3 Eijkhout – CMake tutorial – Fall 2023


Help! This software uses
CMake!

4 Eijkhout – CMake tutorial – Fall 2023


Directory structure: two options

dir dir

src src

build build

install install
In-source build: pretty common
Out-of-source build: cleaner because never touches the source tree
Some people skip the install step, and use everything from the build
directory.

5 Eijkhout – CMake tutorial – Fall 2023


What are we talking here?

You have just installed a CMake-based library.


Now you need it in your own code, or in another library.
How easy can we make that?

6 Eijkhout – CMake tutorial – Fall 2023


Finding packages with ‘pkg config’

Many packages come with a package.pc file


Add that location to PKG_CONFIG_PATH
The package can now be found by other CMake-based packages.

7 Eijkhout – CMake tutorial – Fall 2023


Help! I want to write CMake
myself!

8 Eijkhout – CMake tutorial – Fall 2023


Example: single source

Build an executable from a single source file:


cmake_minimum_required( VERSION 3.12 )
project( singleprogram VERSION 1.0 )

add_executable( program program.cxx )


install( TARGETS program DESTINATION . )

9 Eijkhout – CMake tutorial – Fall 2023


Eigen

Header-only:
cmake_minimum_required( VERSION 3.12 )
project( eigentest )

find_package( PkgConfig REQUIRED )


pkg_check_modules( EIGEN REQUIRED eigen3 )

add_executable( eigentest eigentest.cxx )


target_include_directories(
myprogram PUBLIC
${EIGEN_INCLUDE_DIRS})

10 Eijkhout – CMake tutorial – Fall 2023


Help! I want people to use
my CMake package!

11 Eijkhout – CMake tutorial – Fall 2023

You might also like