How to do it

Now let us turn to the CMake side. In the CMakeLists.txt file, we need to apply the following:

  1. We first define the executable and its source file dependency:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-04 LANGUAGES CXX)add_executable(arch-dependent arch-dependent.cpp)
  1. We check for the size of the void pointer type. This is defined in the CMAKE_SIZEOF_VOID_P CMake variable and will tell us whether the CPU is 32 or 64 bits. We let the user know about the detected size with a status message and set a preprocessor definition:
if(CMAKE_SIZEOF_VOID_P EQUAL 8)  target_compile_definitions(arch-dependent PUBLIC "IS_64_BIT_ARCH")  message(STATUS "Target is 64 bits")else() target_compile_definitions(arch-dependent PUBLIC ...

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.