Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
缓存变量的自定义CMake属性?_Cmake - Fatal编程技术网

缓存变量的自定义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文档描述了一种为(除其他外)缓存变量创建和自定义属性的方法。但是我不能让它工作。假设我有一个最小的例子:

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;
  }
  ...
}