如何构建过程之后编译cmake的其他源文件 [英] How to compile additional source files in cmake after the build process

查看:193
本文介绍了如何构建过程之后编译cmake的其他源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cmake的窗户一个项目,包含一个名为database.proc一个PRO * C源文件,我的目标是产生从.PROC文件中的C源文件,并将其添加到项目中沿着其他链接源文件,我试图添加自定义命令来实现这个没有成功。

I have a project in cmake for windows which contains a Pro*C source file called database.proc, my goal is to generate a C source file from the .proc file and add it to the project to be linked along the other source files, I've tried to add a custom command to achieve this without success

add_custom_command(TARGET myproj OUTPUT PRE_LINK
    COMMAND ${PROC} iname=${PROJECT_SOURCE_DIR}/connection.proc SQLCHECK=SYNTAX
        MODE=ANSI IRECLEN=255 ORECLEN=255
        ONAME=${PROJECT_SOURCE_DIR}/connection.c
    COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS}
            ${PROJECT_SOURCE_DIR}/connection.c )

有没有一些方法来做到这一点?

Is there some way to do this?

推荐答案

我不熟悉与Pro * C,但它看起来像你的两个不同版本的 add_custom_command

I'm not familiar with Pro*C, but it looks like you're mixing together the two different versions of add_custom_command.

的第一个版本 add_custom_command(OUTPUT ...)用于生成,然后加入作为另一个CMake的靶的依赖性的文件。当该目标是建立,自定义命令首先被执行以生成输出文件。

The first version add_custom_command(OUTPUT ...) is used to generate a file which is then added as a dependency of another CMake target. When that target is built, the custom command is executed first in order to generate the output file.

第二个版本 add_custom_command(TARGET ...)用于定义一个pre-构建,pre-链接或生成后命令;结合其中一个不一定创建一个文件,但执行与建筑相关的目标。

The second version add_custom_command(TARGET ...) is used to define a pre-build, pre-link or post-build command; one which does not necessarily create a file, but which executes in conjunction with building the associated target.

如果你只有一个目标依赖于PRO * C的输出,那么第一个版本可能是你最好的选择:

If you only have one target which depends on the output of Pro*C, then the first version is probably your best bet:

add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/connection.c
    COMMAND ${PROC} iname=${PROJECT_SOURCE_DIR}/connection.proc SQLCHECK=SYNTAX
        MODE=ANSI IRECLEN=255 ORECLEN=255
        ONAME=${PROJECT_SOURCE_DIR}/connection.c)
add_executable(myproj ${PROJECT_SOURCE_DIR}/connection.c <other sources>)

这篇关于如何构建过程之后编译cmake的其他源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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