cmake安装目标中的编译时通配符 [英] Compile-time wildcards in cmake install targets

查看:462
本文介绍了cmake安装目标中的编译时通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是cmake的新手,感到非常沮丧。我试图在运行构建而不是生成生成时评估文件路径中使用通配符。

I'm new to cmake and I'm finding it very frustrating. I am trying to use wildcards in file paths that are evaluated when the build runs, not when the build is generated.

我创建了一个使用SWIG生成Java的生成一些C ++代码的包装器。我可以编写命令来生成本机代码,对其进行编译,并生成有效的共享库,甚至可以使用INSTALL命令正确安装该共享库。我不知道该怎么做,是编写一个INSTALL命令,该命令可以将SWIG生成的所有* .java文件复制到同一安装位置。

I have created a build that uses SWIG to generate Java wrappers for some C++ code. I can write the commands to generate the native code, compile it, and produce a working shared library, and even use the INSTALL command to install that shared library correctly. What I can't figure out how to do is to write an INSTALL command that can copy all *.java files generated by SWIG into that same install location.

该cmake的FILE GLOB命令在执行cmake时(而不是在实际运行该构建时)进行glob。当然,执行cmake时,SWIG尚未运行,并且Java文件尚不存在。

It seems that cmake's FILE GLOB command does the globbing when cmake is executed, and not when the build actually runs. Of course, when cmake is executed, SWIG hasn't run yet, and the Java files don't exist.

是否可以执行我想要的操作?我是在做错事吗?似乎这是Makefiles需要做的基本部分,我真的很惊讶没有找到一种简单的方法。

Is there a way to do what I want? Am I going about things wrong? It seems like this is such a fundamental part of what Makefiles need to do, I'm really surprised not to find an easy way to do it.

推荐答案

假定Java包装器位于当前的二进制目录中,则可以在安装后使用以下 install 命令复制Java文件:

Assuming that the Java wrappers are located in the current binary directory, you can use the following install command to copy the Java files upon install:

install(
    CODE "file( GLOB _GeneratedJavaSources \"${CMAKE_CURRENT_BINARY_DIR}/*.java\" )"
    CODE "file( INSTALL \${_GeneratedJavaSources} DESTINATION \"$ENV{HOME}\" )"
)

install 命令的 CODE 形式用于执行两个运行安装目标时的CMake命令。第一个将所有生成的Java文件收集在一个辅助变量中。第二个使用 file 命令的 INSTALL 形式复制文件。

The CODE form of the install command is used to execute two CMake commands upon running the install target. The first one collects all generated Java files in a helper variable. The second one uses the INSTALL form of the file command to copy the files.

这篇关于cmake安装目标中的编译时通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆