您如何在 cmake install 脚本语句中使用file(GET_RUNTIME_DEPENDENCIES...)?我在网上找不到这种用法的例子,而且我不清楚使用 [[ ]] 嵌入式自定义脚本的文档和错误消息中的声明。
我得到的印象是,在安装时,这可用于定位您的 cmake 目标的文件依赖项,并可能将它们与您的安装操作一起带过来,使其以独立形式使用。
例如,我的应用程序依赖于 QT,并且期望如果配置正确,则该应用程序所需的 QT dll 将被复制到 bin。(我只是想确保在这种情况下我也没有误解它的功能)。它可能不会直接复制文件,但我假设提供了要复制的文件列表,然后安装将处理(全部在安装时完成)。
我天真地尝试只是抛出一些东西开始是:
set(TARGET_NAME "myapp")
# installation settings
install(TARGETS ${TARGET_NAME}
[[
file(GET_RUNTIME_DEPENDENCIES
RESOLVED_DEPENDENCIES_VAR RES
UNRESOLVED_DEPENDENCIES_VAR UNRES
CONFLICTING_DEPENDENCIES_PREFIX CONFLICTING_DEPENDENCIES
EXECUTABLES ${TARGET_NAME}
)]]
RUNTIME DESTINATION "${INSTALL_X_BIN}" COMPONENT libraries
LIBRARY DESTINATION "${INSTALL_X_LIB}" COMPONENT libraries
)
Run Code Online (Sandbox Code Playgroud)
然而,这当然给了我:
CMake Error at applications/CMakeLists.txt:117 (install):
install TARGETS given target " file(GET_RUNTIME_DEPENDENCIES
RESOLVED_DEPENDENCIES_VAR RES
UNRESOLVED_DEPENDENCIES_VAR UNRES
CONFLICTING_DEPENDENCIES_PREFIX CONFLICTING_DEPENDENCIES
EXECUTABLES ${TARGET_NAME}
)" which does not exist.
-- Configuring incomplete, errors occurred!
Run Code Online (Sandbox Code Playgroud)
我觉得这很愚蠢,就像我错过了一些非常基本的东西。
我有一个类,它既具有到内在类型的隐式转换操作符(),又能够通过用于设置存储的字符串索引操作符[]进行访问。它在 gcc 6.3 和 MSVC 的单元测试中编译和运行得很好,但是该类会在智能感知和 clang 上引起一些不明确的警告,这是不可接受的。
超级瘦身版: https://onlinegdb.com/rJ-q7svG8
#include <memory>
#include <unordered_map>
#include <string>
struct Setting
{
int data; // this in reality is a Variant of intrinsic types + std::string
std::unordered_map<std::string, std::shared_ptr<Setting>> children;
template<typename T>
operator T()
{
return data;
}
template<typename T>
Setting & operator=(T val)
{
data = val;
return *this;
}
Setting & operator[](const std::string key)
{
if(children.count(key))
return *(children[key]);
else
{
children[key] = std::shared_ptr<Setting>(new Setting());
return *(children[key]);
}
}
};
Run Code Online (Sandbox Code Playgroud)
用法:
Setting data; …
Run Code Online (Sandbox Code Playgroud)