[CMake] Change variable default

Tim Gallagher tim.gallagher at gatech.edu
Thu Apr 28 12:49:34 EDT 2011


To put it in context, our cmake file looks like:

<define project/language/etc>
<find required libraries>
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
   if(NOT CMAKE_Fortran_FLAGS_RELEASE)
      set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -xhost" CACHE STRING "" FORCE)
   endif()
  set(CMAKE_Fortran_FLAGS_DEBUG
      "${CMAKE_Fortran_FLAGS_DEBUG} -check noarg_temp_created -C -traceback" CA\
CHE STRING "" FORCE)
endif()
<setup options for the project>
<define executable>

The other way you can try it, if it's not empty, is to do

if(${CMAKE_Fortran_FLAGS_RELEASE} STREQUAL ${CMAKE_Fortran_FLAGS_RELEASE_INIT})

As far as I know, CMAKE_*_FLAGS_*_INIT are the default values that it gets set to when cmake starts up. So if you check against that, you will see if the user has modified it.

Tim

----- Original Message -----
From: "Ilja Golshtein" <ilejncs at narod.ru>
To: gtg085x at mail.gatech.edu
Cc: cmake at cmake.org
Sent: Thursday, April 28, 2011 12:42:40 PM
Subject: Re: [CMake] Change variable default

Tim,

thank you.

Compiler and environment specific things become defined during "project" command execution.
It is too late to check if it is set afterwards because it actually IS SET.

I assume you are lucky and default value for CMAKE_Fortran_FLAGS_RELEASE is
empty, isn't it?

So the tricky point is to place customization code in proper place.

In my case 
==
set(CMAKE_CXX_FLAGS_DEBUG  "-g -wall"
  CACHE
  STRING "" 
  )
==
works perfectly if put at the top of CMakeLists.txt


28.04.2011, 19:23, "Tim Gallagher" <tim.gallagher at gatech.edu>:
> We do this:
>
> if(NOT CMAKE_Fortran_FLAGS_RELEASE)
>    set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -xhost" CACHE STRING "" FORCE)
> endif()
>
> In other words, if the flags haven't been set yet (initial start up), set them to what we want. If they have been set (either changed by the user, or specified on the cmake/ccmake line with -D), leave them alone.
>
> Tim
>
> ----- Original Message -----
> From: "Ilja Golshtein" <ilejncs at narod.ru>;
> To: cmake at cmake.org
> Sent: Thursday, April 28, 2011 9:03:43 AM
> Subject: [CMake] Change variable default
>
> Hello!
>
> There are some CMAKE variables with default values. For example CMAKE_CXX_FLAGS_DEBUG default value is '-g'.
> How is it possible to make it '-g -Wall'?
>
> What I don't want to have: User choice overwritten.
>
> What I want to have: Modified a variable cmake-time default. It must be possible to change the variable via cmake -D or ccmake GUI.
>
> Thanks.
>
> --
> Best regards,
> Ilja Golshtein.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

-- 
Best regards,
Ilja Golshtein.


More information about the CMake mailing list