cmake:用于为目标安装任意文件依赖项的包配置

cmake: package config for installing arbitrary file dependencies for a target

我正在为不是由 cmake 创建的预先存在的 .dll 创建一个 cmake 包配置文件(一个 Foo-config.cmake)。

烦人的是.dll依赖于一些数据文件。

当用户在他自己的 cmake 项目中使用我的包时,我希望 INSTALL 目标将 .dll 数据文件安装到他指定的安装位置.我不希望他必须编写额外的 install() 规则才能做到这一点。

  1. 直接在我的 Foo-config.cmake 中编写 install() 规则是好的做法吗?或者有没有更好的方法来做到这一点,也许 set_target_properties()?我只是找不到合适的 属性 来将任意文件依赖项关联到目标。
  2. 在另一个世界中,这个 .dll 尚不存在,我必须使用 cmake 自己创建它,我是否需要创建自定义 Foo-config.cmake,或者 cmake 中是否有一些东西可以自动生成给我实现同样的功能吗?

FWIW .dll 是一个内部遗留库,通常由 Visual Studio 构建并以 .zip 文件上传到我们的内部工件。我希望我们从手动从 artifactory 中提取 .zip 文件并手动将文件集成到 Visual Studio 项目中迁移。

Is it good practice to write the install() rules directly in my Foo-config.cmake?

没有

从我系统上的 480 *-config.cmake 和 *Config.cmake 文件 none 调用 install().

Or is there a better way to do this, maybe with set_target_properties()?

没有

In an alternate universe where this .dll didn't already exist and I had to create it myself using cmake, would I need to create a custom Foo-config.cmake

没有。这与您是否创建 .dll 无关。如果 .dll 存在,则无需创建 Foo-config.cmake。您可以选择(或让用户)使用 find_package.

is there something in cmake that can automatically generate it for me

没有


如果您不打算支持 find_package 功能 - VERSION OPTIONAL_COMPONENTS PATHS HINTS CONFIGS 等 - 那么只需选择 include()find_package 只是 include() 加上一些额外的选项。

如果你想在你的 find_package 中包含 install(),那么只要用一个变量保护它,比如 if (FOO_DO_INSTALL) install(....) endif().

后来我发现有几种不同的方法可以做到这一点: