How to do it

With the following steps, we will manage to cross-compile an OpenMP-parallelized Windows executable:

  1. Create a directory holding example.cpp and CMakeLists.txt, which we listed previously.
  2. We will use the same toolchain.cmake as in the previous recipe:
# the name of the target operating systemset(CMAKE_SYSTEM_NAME Windows)# which compilers to useset(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)# adjust the default behaviour of the find commands:# search headers and libraries in the target environmentset(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)# search programs in the host environmentset(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  1. Adjust the CMAKE_CXX_COMPILER to the corresponding compiler (path). ...

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.