编译CMake项目下的单个文件? [英] Compile a single file under CMake project?

查看:750
本文介绍了编译CMake项目下的单个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个C ++项目,它将被放在一个更大的项目上。



我已经看到在更大的项目它是从qmake生成的)我可以从linux命令行编译一个文件,只需输入特定文件的相对路径作为参数。



另一方面,我使用CMake为我自己的项目。当我修改编译单元的一些代码,我必须修改其头文件,我不得不等待很长时间来编译它的依赖项,然后是自己的源文件。但是在某些情况下,我更喜欢检查* .cc文件中的源代码是否可编译,没有错误。



有一种方法来生成Makefile从CMake的方式qmake这样做?切换到qmake不再是一个选项。

解决方案

不,CMake不提供内置支持编译单个文件。 / p>

您必须为每个目标文件添加目标,也许是通过遍历目录的所有文件的函数。


I'm developing a C++ project which is going to be enclosed on a bigger one.

I've seen that on the bigger project (is a Qt application and it's being generated from qmake) I am able to compile a single file from the linux command line, just entering the relative path to the specific file as an argument to make.

On the other hand, I'm using CMake for my own project. When I modify some code for a compilation unit and I have to modify its header file, I have to wait a long time to compile its dependencies and then its own source file. But there are some situations in which I would prefer to check whether the source code in the *.cc file is compilable without errors.

Is there a way to generate a Makefile from CMake the way qmake does this? Switching to qmake is not an option anymore.

解决方案

No, CMake does not offer built-in support to compile single files.

You have to add a target for each object file, maybe by a function iterating over all files of a directory.

这篇关于编译CMake项目下的单个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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