Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
CMake Cookbook

You're reading from   CMake Cookbook Building, testing, and packaging modular software with modern CMake

Arrow left icon
Product type Paperback
Published in Sep 2018
Publisher Packt
ISBN-13 9781788470711
Length 606 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Radovan Bast Radovan Bast
Author Profile Icon Radovan Bast
Radovan Bast
Roberto Di Remigio Roberto Di Remigio
Author Profile Icon Roberto Di Remigio
Roberto Di Remigio
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Setting up Your System FREE CHAPTER 2. From a Simple Executable to Libraries 3. Detecting the Environment 4. Detecting External Libraries and Programs 5. Creating and Running Tests 6. Configure-time and Build-time Operations 7. Generating Source Code 8. Structuring Projects 9. The Superbuild Pattern 10. Mixed-language Projects 11. Writing an Installer 12. Packaging Projects 13. Building Documentation 14. Alternative Generators and Cross-compilation 15. Testing Dashboards 16. Porting a Project to CMake 17. Other Books You May Enjoy

Porting install targets

We can now configure, compile, link, and test the code, but we are missing the install target, which we will add in this section.

This is the Autotools approach to building and installing code:

$ ./configure --prefix=/some/install/path
$ make
$ make install

And this is the CMake way:

$ mkdir -p build
$ cd build
$ cmake -D CMAKE_INSTALL_PREFIX=/some/install/path ..
$ cmake --build .
$ cmake --build . --target install

To add an install target, we add the following snippet in src/CMakeLists.txt:

install(
TARGETS
vim
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR}
)

In this example, we only install the executable. The Vim project installs a large number of files along with the binary (symbolic links and documentation files). To keep this section digestible, we don't install all other files in this example migration. For your own project, you should verify...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image