是不是可以从一个CMake库生成一个Kotlin的.def文件?

huangapple go评论58阅读模式
英文:

Is it possible to generate a Kotlin .def file from a CMake library?

问题

我有一个现有的CMake项目,用于构建本地库(支持几个Linux平台以及Windows)。这个库将很快集成到一个Kotlin应用程序中,为此我需要创建一个.def文件,如此处所述

从概念上讲,我可以使用FILE和其他本地CMake工具来创建这个文件,但如果有一种“正规”的方法来做这件事,我更愿意使用那种方法!

英文:

I have an existing CMake project which is used to build a native library (supporting a few Linux platforms as well as Windows). This library will soon be integrated into a Kotlin app, for which I need to create a .def file, as stated here

Conceptually, I could create this using FILE and other native CMake tools, but if there's a "proper" way to do this, I'd prefer to use that!

答案1

得分: 1

那个文件是你必须亲自编写的吗?我无法仅从文档中阅读就能确定,但这是我的印象。如果每个.def对应于一个CMake目标,你可以通过使用add_custom_command的构建事件签名来创建一个构建事件自定义命令来运行cinterop命令。

如果你想要脚本化编写.def文件的过程,使其更自动化且对将来的重命名更具鲁棒性,

至于将目标编译选项之类的内容放在一个文件中,你可以使用$<TARGET_GENEX_EVAL:>$<TARGET_PROPERTY:>生成器表达式以及COMPILE_OPTIONS目标属性和CMAKE_CXX_FLAGS(以及类似的)变量在file(GENERATE)命令调用中。

对于编译定义,可以使用COMPILE_DEFINITIONS目标属性。

有关所有支持的目标属性的列表,请参见https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets

英文:

Is that file something you have to write yourself? I can't tell just from reading the docs, but that's the impression I'm getting. If each .def corresponds to a CMake target, you could create a build event custom command by using the build events signature of add_custom_command to run the cinterop command.

If you want to script the process of writing the .def file so it's more automatically-robust to you renaming things in the future,

As for putting things like target compile options in a file, you could use the $&lt;TARGET_GENEX_EVAL:&gt; and $&lt;TARGET_PROPERTY:&gt; generator expressions and the COMPILE_OPTIONS target property and the CMAKE_CXX_FLAGS (and similar) variables in a file(GENERATE) command call.

Simliar for compile definitions (see the COMPILE_DEFINITIONS target property).

For a list of all properties supported on targets, see https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets

huangapple
  • 本文由 发表于 2023年2月16日 07:53:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466512.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定