CMake to Qt Creator .pro file; Build specific CMake project from Qt Creator - visual-studio

Qt Creator does an excellent job with with parsing and building a CMake project. The problem is that when the CMake is too big and has sub-projects, it takes a long time to build.
CMake does have the ability to convert a CMake project to a Visual Studio solution. But since I am using Qt Creator, I'd also like to be able to convert a CMake project to a Qt Creator project.
Is there a straightforward way of accomplishing this task? I have googled, but haven't found anything.
P.S. Or, alternatively, I want the ability to just a build a specific CMake project from Qt Creator, and not the whole "solution". Visual Studio allows you to do it, Qt Creator does not. Unless it does and I don't know how.

Did some digging in Qt Creator and it turns out that it is indeed possible to set which particular CMake sub-project to build.
On the right hand-side where you see the column Welcome/Edit/Design/Projects/Help, go to Projects and select Build on the configuration that you're building:
Then on the right hand-side you'll see on the top a CMake dialog and right below it Build Steps dialog with all the CMake sub-projects loaded. By default all is checked. You can change that selection to whatever sub-project you want to. Obviously if you have a number of sub-projects that are libraries and you're modifying most of the time your executable project and running, then the choice would be the very first one, titled Current Executable:

Related

What is the benefit of building with CMake?

I am working on SFML and I am curious about the option that I can compile it myself. I found it in tutorials, but from the first line I became confused:
CMake is an open-source meta build system. Instead of building SFML, it builds what builds SFML: Visual Studio solutions ...
There is a build option in visual studio too, is there any difference between that build and CMake build?
What does it mean that it builds what builds SFML? It means library files?
Visual studio solutions? What does it mean? As far as i know, when i open a new project it is within a solution and i can add new projects to this solution (I am confused about why there must be more than one project in a solution too!).
What does it mean that CMake builds a solution? And what is it for?
There is sourcecode. People want to compile it. It is difficult and annoying to type the compile commands into a terminal.
People invent build systems, to make 1.) more easy. For example make files or what Visual Studio integrates and stores in its files, called solution.
There are projects, that are cross-platform. They could provide make files, solution files, files for Xcode, Eclipse and so on. This becomes difficult and annoying.
People invent systems, that creates build system to ease 3.). From a common set of files, several different build systems can be steered.
In your actual case: CMake creates the solution file, you can open the solution file and built SFML with that.
CMake is a wonderful tool for cross-platform development without the hassle of maintaining separate build utilities. On Windows, CMake can create a Visual Studio solution file based on its CMakeLists.txt file. On Linux, generally CMake outputs a makefile. CMake is compatible with many build tools, I recommend reading more of there documentation on their website to gain more information.
Edit: Just to be more clear. CMake literally builds what builds SFML since it creates the Visual Studio solution used to build SFML.
A build in VS for a solution is building the library itself. A CMake build generates the VS solution with which you would use to build the library.
See 1.
A VS solution is the full buildable setup containing 1 or more projects. Solutions can contain multiple projects since VS has a limitation on only 1 output per project. If you want multiple outputs (e.g. 4 dlls) each output needs it's own project.

How to compile all CPP file without building the whole project in VS2010

Is it possible that I can just compile all CPP files under a project and without linking etc. the project?
The only way I know to do this is by specify the /c switch when you compile the code. Unfortunately, this option is not available from within the Visual Studio development environment, so you'll need to build your code on the command line by calling cl.exe directly. To make things easy on yourself, use the Visual Studio Command Prompt to do so.
Not sure if it's possible to get MSBuild to do this, the documentation is unclear whether the limitation is Visual Studio itself or if it's a limitation of MSBuild. I haven't actually tried for myself.
Alternatively, you can build individual source files from within the IDE by pressing Ctrl+F7 (at least, assuming the default C++ development settings). If that fails, it's also available as the "Compile" option located in the "Build" menu.
I'm not sure whether this will do what you need, but may be worth a try: create a project for an executable (rather than a library) and include all cpp files in it. Add a main() function that just returns zero. Set the C++ optimisation option to 'optimise references' (/OPT:REF). This may just compile all the cpp files but effectively ignore them during the link stage since none of them are referenced by the application.
You don't say why you need to do this - is it because linking takes a huge amount of time?

Generating redistributable Visual Studio project with cmake

is it possible to generate Visual Studio projects that are redistributable with CMake?
The project file in question are examples/demos of our library. We don't want that our customers have to install cmake (and learn what to do with it) just to compile a few examples.
The problem with CMake generated project files is that they contain absolute paths (relativeliy easy to fix with string replacement) and references to CMake files (e.g. in prelin step. This is not easy to automatically change).
Does CMake provide an easy way to solve this problem?
Thank in advance
Yes,
you can have a cMake project, and generate Visual project on windows, XCode or makefile for other plateforms.
You use it for development, and after use install package makers like iceberg on mac, or scripts based installers on linux, or other installer creator on PC.(inno setup I think could be a solution)
Good luck

How to convert a regular win32 (VC++ vcproj) project to a Qt project?

How can I convert existing vcproj files to project files that the QT add-in to Visual Studio recognizes and treats as valid Qt projects?
Should I just bite the bullet and create new projects to replace the old ones, and then add existing code?
I am using QT 4.6 and VS 2008 with Qt Add-in 1.1.2.
Original vcproj files have NOT been generated with QMake.
Using Visual Studio 2010+ it is now possible to convert a project to a Qt Addin project, using the "Convert project to Qt Add-in project" feature of the Qt Addin.
The following steps are from the work around in bug QTVSADDINBUG-27. This was tested with Visual Studio 2010, but should work similarly with new versions:
Right click on your project in "Solution Explorer", click on "Unload Project"
Right click on your project in "Solution Explorer", click on "Edit .vcxproj"
Add line <Keyword>Qt4VSv1.0</Keyword> between the tags <PropertyGroup Label="Globals"> and </PropertyGroup>.
Right click on your project in "Solution Explorer", click on "Reload Project"
Right click on your project in "Solution Explorer", click on "Convert project to Qt Add-in project"
If you have header files in your project you are going to have to follow the instructions in this answer to trigger the generation of moc_* files in the "Generated Files" folder.
For editions of Visual Studio older than 2010 see this work around.
Here's the response from Nokia support engineer, name removed for privacy protection:
Hi,
Thanks for the suggestion. I have
passed it on to our developers who
will consider implementing it for a
future release. You can track it using
the following link:
https://bugreports.qt.io/browse/QTVSADDINBUG-27
Regards,
Support Engineer, Qt Development Frameworks, Nokia
>
Original question
We have quite a few legacy vcproj projects that we wish to add Qt to it.
Currently, we don't have an easy way to convert these legacy vcproj
files into a Qt-enabled vcproj.
What do I mean by Qt-enabled?
On a non-Qt-enabled vcproj, when I right click on the project name
under Solution Explorer, all options related to Qt are all grayed-out.
It would be really useful if Nokia adds this capability to VSTD Add-in.
Stackoverflow fellows, if you would like to see this feature implemented by Nokia, please help vote for it at the link above! =)
I use Qt VS Tools instead of Qt VS Add-in.
Instructions
In the .vcxproj file, make the following modifications:
Add <Keyword>Qt4VSv1.0</Keyword> into <Project><PropertyGroup Label="Globals"> (in accord with Benjamin's answer).
Add the following element into <Project> (the root element):
<ProjectExtensions>
<VisualStudio>
<UserProperties MocDir=".\GeneratedFiles\$(ConfigurationName)" UicDir=".\GeneratedFiles" RccDir=".\GeneratedFiles" lupdateOptions="" lupdateOnBuild="0" lreleaseOptions="" Qt5Version_x0020_x64="5.6-msvc2013_64" MocOptions="" />
</VisualStudio>
</ProjectExtensions>
Note that the value of the attribute Qt5Version_x0020_x64 should match the name of a Qt version in Qt VS Tools. You may set an arbitrary value and then fix it in Qt Project Settings in Visual Studio.
My setup
Visual Studio 2013
Qt VS Tools 2.0.0 Beta (apparently a rebranding of Qt VS Add-in)
Qt 5.6 msvc2013_64
Notes
When I follow Benjamin's answer and try to "Convert project to Qt VS Tools project", Visual Studio gets stuck.
The only Qt specific functionality I've tried with the project is exporting a .pri file.
I have reverse engineered the necessary modifications from a fresh VS project created using the template Qt GUI Application.
Converting a regular VC project to a QT project should be easier and the error message displayed by the Qt plug-in when attempting to add a Qt class to a non-QT project is exceedingly unhelpful especially when considering the actual differences between a Qt .vcprojfile and a non-Qt one are minimal. It is often the case that you have existing legacy code built into libraries and Dll's. During migration to Qt you may wish to add a Qt class to an existing module which was previously a non-Qt project. If the module has relatively few source files you may find it easier to re-create the project as a Qt project. If it has hundreds of source files or is complex in other ways it is often be easier to simply hand edit the .vcproj file. By comparing a regular .vcproj with a Qt one it is easy to see what the differences are:
A Qt project has a Keyword="Qt4VS1.0" immediately before
TargetFrameWorkVersion line near the top of the file.
At the bottom of the file you need to add the required Globals (in
particular QtVersion.Win32)
You will need to add the locations of the Qt header files to the
include paths (for all build configurations). You can do this later
via the visual studio user interface
For an exe or dll you will also need to add the Qt library locations
and library files to the linker options.
You actually only need to do 1 and 2 in a text editor and then you can reload the project in Visual Studio.
After setting up include paths and libraries you should be able to build the project as usual. Next you can add a new Qt class or convert an existing class into a Qt class. To do the latter first remove the source files for the existing class from the project otherwise the Qt add class wizard is likely to complain.
The above steps are intended for experienced users and you should always back up existing projects .vcproj files bfore hand editing. Simple mistakes here can render the file unusable.
More answer from Qt support engineer; I think the first pargraph is helpful as I didn't know that before:
i think this is a misunderstanding
really. If you have a Qt project
generated with the Add-in, then you
can change this project into a qmake
generated Qt project - and vice versa;
If you have a .vcproj that has been
generated by doing qmake -tp vc, then
you can convert this to a Qt Add-in
project.
There is no functionality to convert a
regular win32 project into a Qt
enabled project, so the suggestion
created is still valid, see:
https://bugreports.qt.io/browse/QTVSADDINBUG-27
I can see from the history of this
report that it has been closed and
re-opened again, so I assume there was
a misunderstanding regarding what you
were looking for in the first place.
If you create a .pro for you project
using qmake, then you should be able
to create a .vcproj file using 'qmake
-tp vc' on that .pro file. The qmake manual is available here:
http://doc.qt.io/qt-5/qmake-manual.html
I hope this helps.
Regards,
--
Support Engineer, Qt Development
Frameworks, Nokia

Generate Makefile from Xcode Project for port of project to other UNIX systems

(This was asked before but the answers were not conclusive)
While I love development using Xcode (3.2.1), I have the need to port some projects to other UNIX systems, and even Windows. The code is all C++ but fairly complex. I'm looking for a way to automated / semi-automated generation of equivalent Makefiles out of my Xcode projects, after getting tired to do this by manual trial-and-error.
Thanks for any hints.
Manfred
You should probably switch to CMake for all your platforms. CMake, in turn, can generate Makefile, Xcode, Visual Studio, and KDevelop projects/builds using the CMake project description. You will, at first, need to create a CMake description for your project, but then if you only update the CMake project, going from CMake to Xcode is very easy. Or you can use the Makefile generator and create a Makefile-based Xcode project. To get started using CMake, you should read the the CMake wiki, look at the CMake Manual, and -- if you like -- you can look at my C++ Application Project Template and C++ Library Project Template which use CMake (although I have tested them only with the Makefile generator and not with the Xcode generator).
If you need to go cross-platform then it's probably better to use a makefile for all platforms. Xcode supports makefile builds as "legacy projects" - you lose some functionality/flexibility when you do this, but you still get the same code browsing, source level debugging, etc.
Have you tried Pbxbuild?
Pbxbuild is used to take Xcode project files and build the code. It does this by creating GNUmakefiles, and using Make to build those.

Resources