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

David Cole DLRdave at aol.com
Fri May 1 06:41:50 EDT 2015


I would strongly recommend NOT having different minimum versions for
Linux vs. everywhere else.

What happens when developers "everywhere else" use newer CMake features?

They CAN'T unless they conditionalize the use based on Linux or not...

Choose the highest minimum you need, and use it everywhere.

You don't want your build system to be the thing that's hard to reason
and think about in your project. You want your project people working
on project stuff, not worrying about whether their CMake changes are
going to break somewhere else.....

Just my opinion, but I would hate to work on a project with logic like
that in it.


D



On Fri, May 1, 2015 at 6:25 AM, Alan W. Irwin <irwin at beluga.phys.uvic.ca> wrote:
> 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
> __________________________
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list