[CMake] Chicken and egg problem with cmake_minimum_required(...), project(...), and CMAKE_SYSTEM_NAME

Brad King brad.king at kitware.com
Fri May 1 08:47:17 EDT 2015


On 05/01/2015 06:25 AM, Alan W. Irwin wrote:
> # First call to project so that CMAKE_SYSTEM_NAME is defined
> project(plplot NONE)
> if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
>      cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
> else(CMAKE_SYSTEM_NAME STREQUAL "Linux")
>      cmake_minimum_required(VERSION 3.2.2 FATAL_ERROR)
> endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
> # "Real" call to project
> project(plplot C)

You don't need another project().  You can use enable_language(C).
Others have advised against having a different minimum, but if
you have good reasons for it then:

 cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
 project(plplot NONE)
 if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
   cmake_minimum_required(VERSION 3.2.2 FATAL_ERROR)
 endif()
 enable_language(C)

Note that this will cause policy settings to differ on Linux
versus elsewhere.

-Brad



More information about the CMake mailing list