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

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri May 1 06:25:09 EDT 2015


Hi Brad:

I am trying to conform to your strong advice that for the top-level
CMakeLists.txt file, the cmake_minimum_required(...) command should
come before the project(...) command.

However, I have just encountered a problem with that approach where
I want to specify a different minimum version for Linux compared
to other platforms.  The only way you can detect Linux that I
am aware of is with the test

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")

but it turns out for some reason that CMAKE_SYSTEM_NAME is not defined before the project
command is executed.

To break this "chicken and egg" issue, I have tried the following:

# 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)

This double call of project (with the first one enabling no languages)
appears to work without any obvious complaints, but can you forsee any
problems with this approach, i.e., is this the way you would recommend
to choose minimum versions depending on platform?

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list