MantisBT - CMake
View Issue Details
0012340CMakeCMakepublic2011-07-14 16:562012-01-02 15:56
Russ Tayor 
David Cole 
highminoralways
closedno change required 
PCWindows7
CMake 2.8.4 
 
0012340: Setting CMAKE_INSTALL_PREFIX does not behave as expected
When I set CMAKE_INSTALL_PREFIX in a CMakeLists.txt file as follows:

#-----------------------------------------------------------------------------
# Put this in /usr/local unless overridden. The default on Windows is
# in Program Files, but that breaks on Windows 7 because you have to be
# admin to write there.

set(CMAKE_INSTALL_PREFIX /usr/local/)

the behavior is not as expected. First, that value for the prefix does not show up in the GUI. Second, the value that is set in CMakeLists.txt file is the one that is actually used (so the one shown in cmake-gui is not used). Thus, there is no way to see that it has been changed or to override it.

This is not what happens with other variables in CMake.
Add the above into your CMakeLists.txt file for your favorite project.
This also happens on MacOSX under CMake 2.8.2.
No tags attached.
Issue History
2011-07-14 16:56Russ TayorNew Issue
2011-07-14 17:10David ColeAssigned To => David Cole
2011-07-14 17:10David ColeStatusnew => assigned
2011-07-14 17:23David ColeNote Added: 0027037
2011-07-16 19:34David ColeNote Added: 0027050
2011-07-16 19:34David ColeStatusassigned => resolved
2011-07-16 19:34David ColeResolutionopen => no change required
2012-01-02 15:56David ColeNote Added: 0028105
2012-01-02 15:56David ColeStatusresolved => closed

Notes
(0027037)
David Cole   
2011-07-14 17:23   
You must be relatively new to CMake...

CMAKE_INSTALL_PREFIX is a cache variable. The value you see in the gui is the cache value. When you write:

  set(CMAKE_INSTALL_PREFIX /usr/local/)

in a CMakeLists file, you are providing a local variable value that overrides the cache value for the remainder of the CMakeLists file. However, the overridden value does NOT show up in the gui. That's just the way that cache variables work in CMake.

So, learn to expect that. :-)

When you say "This is not what happens with other variables in CMake." I'm curious what you mean...? Because that is exactly what happens with all cache variables in CMake.

The values set in the CMakeLists files override the cached values, assuming that the programmer who writes the CMakeLists knows what he's doing.

CMAKE_INSTALL_PREFIX is "special" in this respect: CMake chooses a reasonable platform-specific default value for you very early in the configuration process, so there is no way for a project to define its own default value for the cache variable in a CMakeLists file without doing something fancy. If you want to do such a thing, I recommend using your own variable named <YOUR_PROJECT>_INSTALL_PREFIX and then doing:

  set(CMAKE_INSTALL_PREFIX "${xxxx_INSTALL_PREFIX}" CACHE INTERNAL "")

Making CMAKE_INSTALL_PREFIX an INTERNAL CACHE variable has a nice side-effect of hiding it from the gui, so users do not get confused.

This has all been discussed a very lot on the CMake users mailing list. Search the list archives for more information about CMAKE_INSTALL_PREFIX...
(0027050)
David Cole   
2011-07-16 19:34   
Please feel free to discuss further on the CMake users mailing list, or to re-open this issue if you need more information.
(0028105)
David Cole   
2012-01-02 15:56   
Closing resolved issues that have not been updated in more than 4 months.