英文:
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 $<TARGET_GENEX_EVAL:>
and $<TARGET_PROPERTY:>
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论