【问题标题】:Custom CMake property for cache variable?缓存变量的自定义 CMake 属性?
【发布时间】:2019-06-11 10:22:59
【问题描述】:

CMake 文档描述了defineset 自定义属性(以及其他)缓存变量的方法。但是我不能让它工作。假设我有这个最小的例子:

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


【解决方案1】:

CMake 实现似乎只是硬编码哪些CACHE 属性是可写。来自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;
  }
  ...
}

我同意,根据define_property(CACHED_VARIABLE) 命令流的描述,这种硬编码不是预期的。 (定义一个没有人可以设置的属性的原因是什么?)

所以你可以填写关于这个主题的错误报告。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-03-21
  • 1970-01-01
  • 2021-03-24
  • 1970-01-01
  • 2018-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多