缓存变量的自定义CMake属性?
CMake文档描述了一种为(除其他外)缓存变量创建和自定义属性的方法。但是我不能让它工作。假设我有一个最小的例子:缓存变量的自定义CMake属性?,cmake,Cmake,CMake文档描述了一种为(除其他外)缓存变量创建和自定义属性的方法。但是我不能让它工作。假设我有一个最小的例子: 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 "helpstrin
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")
尝试配置时会出现错误:
$ 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".
这项功能到底应该如何工作?似乎CMake实现只是硬代码哪些缓存属性是可写的。从:
bool cmSetPropertyCommand::HandleCacheMode()
{
如果(此->属性名称==“高级”){
...
}else if(this->PropertyName==“TYPE”){
...
}else if(此->属性名称!=“帮助字符串”&&
此->属性名称!=“字符串”&&
此->属性名称!=“值”){
std::ostringstream e;
您可以设置缓存条目,而不是您自己的。完成-我们将看到这是如何发展的。
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;
}
...
}