[CMake] cache behaviour

Ateljevich, Eli eli at water.ca.gov
Wed Jun 27 12:53:37 EDT 2012


Hello Eric,
I am a relative beginner with cmake, but I have done a lot of experimenting to try to figure out the relative precedence of things with the cache. At the very least I will bump your topic and get a real answer.

On my setup (2.6), the "-D" option seems to trump other initialization. For instance (I'm just documenting my own trail here), -D takes precedence over -C for initializing the cache regardless of whether I use set( ... FORCE) in <initial-cache>. It also seems to automatically carry a "FORCE" in the sense that it will always update the cache and install a new value even if cmake has already been run. 

Within the CMakeLists.txt (now onto your case) the -D value will prevail unless a set is made with "FORCE" in which case the variable is set and the cache is updated -- the question may be one of scope and timing. So, you seem to have done the one thing that actually will have an effect, but you just set the variable to itself so it seems like a "no-op" on value but an "op" in terms of registering a change.

Your message() statements suggest that the variables are set correctly in that location. Your woes have to either be because 1) the timing is wrong or 2) there is something bad about deliberately re-setting things ... for instance, by using FORCE you are probably setting CMAKE_Fortran_COMPILER redundantly to itself rather than seeing it is already set and leaving it alone -- and the "compiler change" warning is probably set to observe that. 

Does it work if you remove the IF statements and SET statements and just use the -D as your variable initialization? What is the motive for the IF and SET/FORCE?

Eli

-----Original Message-----
From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf Of pellegrini
Sent: Wednesday, June 27, 2012 5:53 AM
To: CMake List
Subject: [CMake] cache behaviour

Hello CMakers,

I saw this question turning around several times but I do not really 
understand why
the explanations do not suit with my problem. Sorry in advance for the 
redundancy.

Here is my 'problem':

I have a CMakeLists.txt file that starts with:

     ##########################################################
     cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)

     option(GUI "Build the GUI on top of the console programs." ON)

     if(DEFINED CMAKE_BUILD_TYPE)
         set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "" FORCE)
     else()
         set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
     endif()
     message(STATUS "Setting build type to ${CMAKE_BUILD_TYPE}")

     if(DEFINED CMAKE_Fortran_COMPILER)
         set(CMAKE_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE 
STRING "" FORCE)
     else()
         set(CMAKE_Fortran_COMPILER ifort CACHE STRING "" FORCE)
     endif()
     message(STATUS "Setting compiler to ${CMAKE_Fortran_COMPILER}")

     project(sxtalsoft Fortran RC)

     bla bla bla ...
     ##########################################################

When I run it a first time in an empty directory with

     cmake -G"NMake Makefiles" -DCMAKE_Fortran_COMPILER=ifort 
-DCMAKE_BUILD_TYPE=Release ..\..\.

I get:

-- Setting build type to Release
-- Setting compiler to ifort
-- The Fortran compiler identification is Intel
-- Check for working Fortran compiler: C:/Intel/Composer 
XE/bin/ia32/ifort.exe
-- Check for working Fortran compiler: C:/Intel/Composer 
XE/bin/ia32/ifort.exe  -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether C:/Intel/Composer XE/bin/ia32/ifort.exe supports 
Fortran 90
-- Checking whether C:/Intel/Composer XE/bin/ia32/ifort.exe supports 
Fortran 90 -- yes
-- Configuring done
-- Generating done
-- Build files have been written to: 
C:/Users/pellegrini/work/diffraction/sxtalsoft/build/ifort

If a run it a second time WITHOUT deleting the CMakeCache.txt file with

     cmake -G"NMake Makefiles" -DCMAKE_Fortran_COMPILER=ifort 
-DCMAKE_BUILD_TYPE=Debug ..\..\.

I get this time:

-- Setting build type to Debug
-- Setting compiler to ifort
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_Fortran_COMPILER= ifort

-- Setting build type to Release
-- Setting compiler to ifort
-- The Fortran compiler identification is Intel
-- Check for working Fortran compiler: C:/Intel/Composer 
XE/bin/ia32/ifort.exe
-- Check for working Fortran compiler: C:/Intel/Composer 
XE/bin/ia32/ifort.exe  -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether C:/Intel/Composer XE/bin/ia32/ifort.exe supports 
Fortran 90
-- Checking whether C:/Intel/Composer XE/bin/ia32/ifort.exe supports 
Fortran 90 -- yes
-- Configuring done
-- Generating done
-- Build files have been written to: 
C:/Users/pellegrini/work/diffraction/sxtalsoft/build/ifort

There are two things that puzzle me here. The first is: why cmake detect 
a change in the compiler
type as it did not change its value in the command line between the two 
calls ? The second is why
during the rerun the CMAKE_BUILD_TYPE is set back to Release and not to 
the value set in the command
line i.e. Debug ?

Is my implementation not correct or is this some cache behaviour that I 
still do not get ?

thanks a lot

Eric

--

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



More information about the CMake mailing list