MantisBT - CMake
View Issue Details
0014546CMakeCMakepublic2013-11-06 00:332016-06-10 14:31
Alp Toker 
Kitware Robot 
normalfeaturealways
closedmoved 
CMake 2.8.12 
 
0014546: CACHE variables persist through reruns
Hello,

We're using CMake in the LLVM/clang Open Source project and noticed that CACHE variables are getting persisted after regenerating makefiles (reference: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-October/032957.html [^])

This means that upstream SVN changes to any CACHE variable (such as the binary version number, default bug report URL etc.) don't take effect on developers systems.

The most visible result of this is that, when the project makes a new release, existing builds continue to use the old version number taken from the cache. This happens with all other CACHE variables too.
Configure a project that has the following CACHE variable in CMakeLists.txt:

set(BUG_REPORT_URL "http://llvm.org/bugstypo/" [^] CACHE STRING
  "Default URL where bug reports are to be submitted.")

Then build the project.

Then modify the URL in CMakeLists.txt, changing it from "http://llvm.org/bugstypo/" [^] to "http://llvm.org/bugs/" [^]

Then rebuild the project.

Problem: BUG_REPORT_URL is still "http://llvm.org/bugstypo/" [^]

Expected result: BUG_REPORT_URL should have been updated to "http://llvm.org/bugs/" [^]

The issue has been observed with the Makefile and Ninja generator, and presumably all other generators are affected.
I've investigated and this seems to be a bug in cmMakefile::AddCacheDefinition(), which is caching the default value for the variable even when the user hasn't overridden it on the commandline or in the CMake GUI.

I'm working on a patch that teaches CMake to differentiate between the declaration, definition and default value of a CACHE variable.

An additional benefit of this approach is that it adds a "Reset to default" option for CACHE variables in the CMake GUI.

There should otherwise be no change in behaviour other than resolving the problem as described. Specifically, if the user defines the variable explicitly, the user definition will continue persist same as before.

I'll upload the patch shortly. Please let me know if you're already aware of / working on an alternative solution to this issue.
No tags attached.
related to 0014756closed Kitware Robot RFE: Report changes to cached values 
patch wip-cmake-default-4d6b88.patch (11,899) 2013-11-11 21:38
https://public.kitware.com/Bug/file/4947/wip-cmake-default-4d6b88.patch
Issue History
2013-11-06 00:33Alp TokerNew Issue
2013-11-06 07:57Brad KingNote Added: 0034403
2013-11-06 07:57Brad KingSeverityminor => feature
2013-11-06 07:57Brad KingStatusnew => backlog
2013-11-11 21:36Alp TokerNote Added: 0034432
2013-11-11 21:38Alp TokerFile Added: wip-cmake-default-4d6b88.patch
2013-11-11 21:52Alp TokerNote Added: 0034433
2013-11-12 09:17Brad KingNote Added: 0034435
2013-11-13 17:56Alp TokerNote Added: 0034451
2014-02-14 15:34Brad KingRelationship addedrelated to 0014756
2016-06-10 14:29Kitware RobotNote Added: 0042412
2016-06-10 14:29Kitware RobotStatusbacklog => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0034403)
Brad King   
2013-11-06 07:57   
FWIW, the current behavior is by design. The project populates a value and the user can see and edit it in the cache. Distinguishing default values will be new feature. Currently projects can achieve this with:

 set(BUG_REPORT_URL "" CACHE STRING
     "Custom URL where bug reports are to be submitted.")
 if(NOT BUG_REPORT_URL)
   set(BUG_REPORT_URL http://llvm.org/bugstypo/ [^])
 endif()
(0034432)
Alp Toker   
2013-11-11 21:36   
Thanks for the info Brad.

In my time working with CMake both on the WebKit and LLVM projects this has caused some painfully subtle breakage that was difficult to track down due to the silent failure mode.

Instead of adding workarounds to the projects, I've decided to take the time to get this fixed/implemented in CMake if it works for you.

Brief description of the attached patch:

The change is essentially to put default values as a semantically significant comment, DEFAULT, handled very similarly to HELPSTRING. Upon initial default configure CMakeCache.txt contains:

//Default URL where bug reports are to be submitted.
# BUG_REPORT_URL:STRING=http://llvm.org/bugs/ [^]

If you override it:

//Default URL where bug reports are to be submitted.
# BUG_REPORT_URL:STRING=http://llvm.org/bugs/ [^]
BUG_REPORT_URL:STRING=http://clang.org/bugs/ [^]

This has the useful property of being self-documenting, even if reconfiguring using a text editor, while also passing through default values to assist the user in GUI mode.

I've also added initial support in the curses UI to *bold* non-default values, similar to how Visual Studio's property pages work.

Note that this revision of the patch isn't actually working entirely correctly -- values still get persisted sometimes due to a recent change I made. Putting it up now because the implementation is mostly done and I won't have time to work on it the next few days. No tests yet either.

(If someone has the time to finish this off before then, do feel free to pick it up where I left off)
(0034433)
Alp Toker   
2013-11-11 21:52   
(One big reason not to do the workaround at the project level is that it wouldn't apply to historic builds, and CACHE values would still get persisted, say when bisecting to find a bug with git. The proposed fix handles that case fine.)
(0034435)
Brad King   
2013-11-12 09:17   
We shouldn't change the cache format for this. You can just make the DEFAULT a cache property.
(0034451)
Alp Toker   
2013-11-13 17:56   
Brad, great. If the inline comment feature isn't desirable, using the standard handling for DEFAULT instead will make this patch simpler.
(0042412)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.