This is how we can use the set_compiler_flag function in our CMakeLists.txt:
- In the preamble, we define the minimum CMake version, project name, and supported languages (in this case, C and C++):
cmake_minimum_required(VERSION 3.5 FATAL_ERROR) project(recipe-03 LANGUAGES C CXX)
- Then, we include set_compiler_flag.cmake, in this case explicitly:
include(set_compiler_flag.cmake)
- Then, we try a list of C flags:
set_compiler_flag( working_compile_flag C REQUIRED "-foo" # this should fail "-wrong" # this should fail "-wrong" # this should fail "-Wall" # this should work with GNU "-warn all" # this should work with Intel "-Minform=inform" # this should work with PGI "-nope" # this should fail )message(STATUS "working C compile ...