How to do it

The project needs to unpack the Eigen archive and set the include directories for the target accordingly:

  1. Let us first declare a C++11 project:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-01 LANGUAGES CXX)set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)
  1. We add a custom target to our build system. The custom target will extract the archive inside the build directory:
add_custom_target(unpack-eigen  ALL  COMMAND    ${CMAKE_COMMAND} -E tar xzf ${CMAKE_CURRENT_SOURCE_DIR}/eigen-eigen-5a0156e40feb.tar.gz  COMMAND    ${CMAKE_COMMAND} -E rename eigen-eigen-5a0156e40feb eigen-3.3.4  WORKING_DIRECTORY    ${CMAKE_CURRENT_BINARY_DIR}  COMMENT "Unpacking Eigen3 in ${CMAKE_CURRENT_BINARY_DIR}/eigen-3.3.4" ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.