将文件添加到CMake但不进行编译 [英] Adding files to CMake but not compiling them

查看:715
本文介绍了将文件添加到CMake但不进行编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公司有他们自己的idl编译器,并且在构建过程中,我让CMake生成文件。我希望.idl文件位于Visual Studio项目中,但这意味着我最终会以Microsoft尝试使用midl编译idl文件(这会失败)。

My company has their own idl compiler, and I have CMake generating the files as a part of the build process. I want the .idl files to be in the visual studio project, but that means I end up with microsoft trying to compile the idl files with midl (which fails miserably).

我知道我的问题与将数据文件添加到cmake非常相似生成的项目,但主要区别在于微软确实有一个编译器,我只是不想让他们使用它。

I know my question is extremely similar to Adding data files to cmake-generated projects, but the major difference is that microsoft does have a compiler I just don't want them to use it.

-update-

这是该函数的代码示例,该代码示例将idl文件添加到解决方案中(整个代码太多,但是如果有任何声明可能有助于解答问题让我知道):

Here is a code sample from the function that adds the idl file to the solution (The entirety of the code is too much, but if there are any declarations that might help in answering the question let me know):

function foo()
    add_custom_command...
    set(HEADERS ${HEADERS} bar.idl PARENT_SCOPE)
    source_group("Source Files\\idl Files" REGULAR_EXPRESSION .*.idl)
endfunction()

然后稍后-在我打电话给foo之后-我打电话给 add_executable($ {PROJECT_NAME} $ {SOURCES} $ {HEADERS})

Then later - after I call foo - I call add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})

我注意到的一件事是nmake将按照我希望的方式进行编译,但是Visual Studio将调用添加到我不想要的midl中。

One thing I noticed is that nmake will compile how I want it to compile, but visual studio adds the call to midl that I don't want.

任何帮助将不胜感激。

-更新2-

我可以破解修复通过添加一个问题?到Visual Studio内部的midl命令行(但是我不能要求每个开发人员每次构建时都这样做),因此,如果有人知道如何从cmake向midl命令行添加参数,这也会有所帮助。

I can hack a way of 'fixing' the problem by adding a /? to the midl command line inside visual studio (but I can't ask every dev to do that each time they build), so if anyone knows how to add an argument to the midl command line from cmake that would help as well.

推荐答案

这也许也有点hack,但是我认为您可以通过将.idl文件标记为 HEADER_FILE_ONLY

It's probably also a bit of a hack, but I think you could achieve this by marking the .idl files as HEADER_FILE_ONLY:

set_source_files_properties(${HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE)

这篇关于将文件添加到CMake但不进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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