How to do it

According to the documentation of the Eigen library, it is sufficient to set the appropriate compiler flag to enable the generation of vectorized code. Let us look at CMakeLists.txt:

  1. We declare a C++11 project:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)  project(recipe-06 LANGUAGES CXX)set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)
  1. Since we wish to use the Eigen library, we need to find its header files on the system:
find_package(Eigen3 3.3 REQUIRED CONFIG)
  1. We include the CheckCXXCompilerFlag.cmake standard module file:
include(CheckCXXCompilerFlag)
  1. We check that the -march=native compiler flag works:
check_cxx_compiler_flag("-march=native" _march_native_works)
  1. The alternative ...

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.