Reputation: 8860
CMake docs describe a way to define and set custom properties for (among others) cache variables. However I cannot make it work. Lets say I have this minimal example:
cmake_minimum_required(VERSION 3.7)
project(x)
define_property(CACHED_VARIABLE PROPERTY A_PROPERTY BRIEF_DOCS "brief" FULL_DOCS "full")
set(A_VARIABLE "variable value" CACHE STRING "helpstring")
set_property(CACHE A_VARIABLE PROPERTY A_PROPERTY "property value")
Trying to configure it gives an error:
$ cmake .
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:6 (set_property):
set_property given invalid CACHE property A_PROPERTY. Settable CACHE
properties are: ADVANCED, HELPSTRING, STRINGS, TYPE, and VALUE.
-- Configuring incomplete, errors occurred!
See also "/tmp/x/CMakeFiles/CMakeOutput.log".
How exactly is this feature supposed to work?
Upvotes: 0
Views: 1098
Reputation: 65928
It seems that CMake implementation simply hardcodes which CACHE properties are writable. From the cmSetPropertyCommand.cxx:
bool cmSetPropertyCommand::HandleCacheMode()
{
if (this->PropertyName == "ADVANCED") {
...
} else if (this->PropertyName == "TYPE") {
...
} else if (this->PropertyName != "HELPSTRING" &&
this->PropertyName != "STRINGS" &&
this->PropertyName != "VALUE") {
std::ostringstream e;
e << "given invalid CACHE property " << this->PropertyName << ". "
<< "Settable CACHE properties are: "
<< "ADVANCED, HELPSTRING, STRINGS, TYPE, and VALUE.";
this->SetError(e.str());
return false;
}
...
}
I agree that such hardcode is not the one which is expected according to the description of define_property(CACHED_VARIABLE)
command flow. (What is a reason to define a property which no one can set?)
So you may fill a bug report on this topic.
Upvotes: 1