使用Cmake与Qt Creator [英] Using Cmake with Qt Creator

查看:251
本文介绍了使用Cmake与Qt Creator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一起使用 Qt creator Cmake (请不要问我的动机,接受这个作为给定。)



我成功设置Qt创建者使用cmakeCmake:参见文档,我如何做



我成功创建了 hello world 项目,但我无法在项目中创建文件,
只将现有文件添加到项目树,然后将其添加到cmake列表。
Qt创建者的标准操作添加新...不起作用,我找不到原因。



有没有人使用Qt creator和Cmake在一起?组合是否可能?



注意:我使用的是Qt creator v2.4.1。

解决方案

p>您可以在CMakeLists.txt中使用glob表达式添加文件,如下所示:

 文件(GLOB SRC。* .cpp )
add_executable(your_exe_name $ {SRC})

Cmake会选择您的新cpp文件









这个解决方案可能有用,但如评论中所述 - 这不是一个好的做法。每次有人添加新的源文件和提交更改,您需要重新运行cmake以构建所有源。通常我只是触摸 CMakeLists.txt 文件之一,如果我的构建被破坏,我从存储库池中最近的更改。之后, make 将自动运行 cmake ,我不需要手动运行。尽管我认为,CMakeLists.txt中的显式源列表是一件好事,他们称为事情CMake 列表原因。


I would like to use Qt creator and Cmake together (please, don't ask me about my motivation, accept this as a given.)

I successfully set up Qt creator to use cmake "Cmake": see this, this and this documents regarding how I did that.

I successfully create hello world project, but I can't create files in project, only add existing files to project tree and after that adding it to cmake list. Standard operation of Qt creator "Add New..." doesn't work and I can't find why.

Is there anybody who uses Qt creator and "Cmake" together? Is the combination actually possible?

Note: I'm using Qt creator v2.4.1.

解决方案

You can add files using glob expression in your CMakeLists.txt, like this:

file(GLOB SRC . *.cpp)
add_executable (your_exe_name ${SRC})

Cmake will pick your new cpp files next time you run it and QtCreator will show them in the project browser.

Update

This solution may be useful but as noted in comments - this is not a good practice. Every time somebody add new source file and commit changes, you need to rerun cmake to build all the sources. Usually I just touch one of the CMakeLists.txt files if my build is broken after I pool recent changes from repository. After that make will run cmake automatically and I didn't need to run it by hands. Despite of that I think that explicit source lists in CMakeLists.txt is a good thing, they called thing CMake Lists for a reason.

这篇关于使用Cmake与Qt Creator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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