How can I set -j mingw option in my QtCreator's .pro project file - c++

I'm building a huge C++/Qt project for Android using QtCreator. I have scripts generating .pro files and I'd like to specify within the .pro file that I wish to have the build multi-threaded.
I know I can go to project options and add -j%NUMBER_OF_PROCESSORS% option to Make:
However, as I want to have this option set to all our projects and for every developper, I'd like to have this option be set from the .pro file.
I tried:
QMAKE_CXXFLAGS += -j%NUMBER_OF_PROCESSORS%, but this sets the option to arm-linux-androideabi-g++, whil it should be set to mingw32-make.exe
$$(MAKEFLAGS) = -j%NUMBER_OF_PROCESSORS%, no success...not sure that's the right syntax to set and environment variable from .pro file...not even sure that's doable.
$$(MAKE_COMMAND) = mingw32-make -j%NUMBER_OF_PROCESSORS%, no success
Does anyone know how to set this option from .pro file?

There is no way for the simple reason that it doesn't belong in the project file. What if a developer on your team doesn't want to use all his cores because he's doing something else and he wants a bit more CPU juice at the same time? What if someone has 2 cores less than the number you chose? What if someone has more cores than the number you chose?
In short: don't. If you want optimal cpu core usage, use something like Ninja, which does so automatically, without the need of a specific number.
Note: Ninja won't work with qmake. Try CMake if it's at all possible. Even though the scripting language is terrible, it offers a lot of possibilities and flexibility in return.

Project's build and run settings are saved in .pro.user file, AFAIK. You could modify .pro.user with your script, find a line that looks something like this:
"< value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">[EMPTY, OR SOME OTHER MAKE ARGUMENTS]< /value>"(might be slightly different depending on version and platform) and change whatever is in the place of
[EMPTY, OR SOME OTHER MAKE ARGUMENTS] with -j%NUMBER_OF_PROCESSORS%.
However, you would need to preserve most of the other settings in .pro.user file for each particular user meaning that you would need your script to be run on each host, and in a case any of the users changes make arguments in Qt Creator's build settings. Please note that i'm not saying that it is a good idea modifying .pro.user manually, but it is a way of doing what you wanted.

Actually, he best is to recommend every developer that wants to spped-up compilation to set MAKEFLAGS environment variable. It can decide to set it to -j2 or -j4 or -j%NUMBER_OF_PROCESSORS% (if it wants a fast compilation even if it overloads the computer).
This is then used by make and applies to every project compiled with QtCreator. The fact that the option is used is absolutely not visible in QtCreator (nor in the options page, nor in the log), however, you can see in Windows task manager that several instances of g++ are ran in parallel.

Related

set output path for cmake generated files

My question is the following:
Is there a way to tell CMakeFiles where to generate it's makefiles, such as cmake_install.cmake, CMakeCache.txt etc.?
More specifically, is there a way to set some commands in the CMakeFiles that specifies where to output these generated files? I have tried to search around the web to find some answers, and most people say there's no explicit way of doing this, while others say I might be able to, using custom commands. Sadly, I'm not very strong in cmake, so I couldn't figure this out.
I'm currently using the CLion IDE and there you can specifically set the output path through the settings, but for flexibility reasons I would like as much as possible to be done through the CMakeFiles such that compiling from different computers isn't that big of a hassle.
I would also like to avoid explicitly adding additional command line arguments etc.
I hope someone might have an answer for me, thanks in advance!
You can't (easily) do this and you shouldn't try to do it.
The build tree is CMake's territory. It allows you some tiny amount of customization there (for instance you can specify where the final build artifacts will be placed through the *_OUTPUT_DIRECTORY target properties), but it does not give you any direct control over where intermediate files, like object files or internal make scripts used for bookkeeping are being placed.
This is a feature. You have no idea how all the build systems supported by CMake work internally. Maybe you can move that internal file to a different location in your build process, which is based on Unix Makefiles. But maybe that will also horribly break my build process, which is using Visual Studio. The bottom line is: You shouldn't have to care about this. CMake should take care of it, and by taking some freedom away from you, it ensures that it can actually do that job on all supported build toolchains.
But this might still be an unsatisfactory answer to you. You're the developer, shouldn't you be in full control of the results produced by your build? Of course you should, which is why CMake again grants you full control over what goes into the install tree. That is, whatever ends up in the install directory when you call make install (or whatever is the equivalent of installing in your build toolchain) is again under your control.
So you do control everything that matters: The source tree, the install tree, and that tiny portion of the build tree where the final build artifacts go. The rest of the build tree is off-limits for you and for good reasons.

Pass selected file to Make target in Eclipse

At the company I'm currently working for, several IDEs are being used (they develop firmware for different embedded platforms).
All their C projects use a Makefile, so we decided to also add rules to their default Makefile to run static code analysis tools.
One of the IDEs they use is Eclipse.
Here we have added additional targets to the Make Target view, that triggers the lint target from the Makefile, for example.
Since we use multiple IDEs we can tell the tools called by the Makefile to generate specific output for the IDE being used.
For Eclipse we do this by adjusting the Build Command and adding something like IDE_ENV=eclipse to the end.
This works just fine.
Recently one of the engineers mentioned that it would be really helpful if he could run the tools, as defined in the Makefile, for a single file.
So, I updated the Makefile and it now accepts a variable SOURCE_FILE with the path of the file that needs to be checked.
In Eclipse I tried adding SOURCE_FILE=${selected_resource_loc} and just SOURCE_FILE=${resource_loc}, but these variable do not seem to work when running a Make Target.
I also tried to use $(selected_resource_loc) and $(resource_loc) directly in the Makefile, but without any luck.
Can somebody tell me how I can pass the current selected file to Make when running a target from the Make Target view?
Some Eclipse special variables can be not recognized in a build configuration. Instead of running build procedure try to use External Tools Configuration.
Similar problem was described here: Custom command for Eclipse on current file .

Good practice for implementing resource directories

I'm not sure if this is too general, so if it is I'll say that I'm on Linux using qmake, but I'd like to be able to switch from Linux to Windows with my project whenever I need to, as well as, possibly other PCs.
In order to do this, I'd like to know how some of the programmers on here have gotten around using resource directories without using absolute path definitions. With Qt, it seems like the runtime working directory is the build directory of the application, and not the source directory.
Ideally, I think the best solution would be to somehow get the Resource directory as it resides in the source directory and copy that to the relative build directory (i.e., Debug or Release, depending on development stage) so that the application can access that via run time.
This can introduce some complication, however (at least, I think it can).
Anyway, what would be a good solution to do this?
If you are using Qt. I would suggest using deploy process.
http://doc.qt.digia.com/qtcreator/creator-building-running.html
Basically, you just need to declare which directories need to be copied.
The qt creator will copy those dirs to build dir(release/debug) after build process is done.Then you simply run the executable.
Here is one of example.
https://github.com/longwei/incubator-cordova-qt.
in the pro file
wwwDir.source = www
xmlDir.source = xml
qmlDir.source = qml
DEPLOYMENTFOLDERS = wwwDir xmlDir qmlDir
second
include(deployment.pri)
qtcAddDeployment()
then it is done.
Its not clear what exactly you're trying to achieve, but perhaps a simple solution would be for the build scripts to pass the necessary path via a compilation definition (-D with gcc). Then depending on if its a Debug, Release, etc build, the definition would be set accordingly, then the corresponding binary would have the correct path.
As a side note, I tried qmake for a while, but found SCons to be much more versatile.

How to locate a compiler in a path with a version number in it?

I'm trying to design an SConstruct file for an embedded system project. The compiler on my machine is at "C:\Program Files\IAR Systems\Embedded Workbench 5.4\arm\bin" I would like the build system to try to locate the toolchain even if there is another verison of Embedded Workbench installed, or if the user has chosen to install it elsewhere.
I'd also be interested in strategies used in makefiles or ant files since they are probably useful here as well.
What are some strategies for doing this? Do I have options other than searching the Windows registry or looking for "C:\Program Files\IAR Systems\Embedded Workbench *\arm\bin"?
The simplest solution is to use an environment variable. You still have to set that up manually for each build host, but the build system need only refer to the environment variable, so can be common for all build hosts.
For example in your case you might have:
EWBARM_V0504="C:\Program Files\IAR Systems\Embedded Workbench 5.4\arm\bin"
And similar for other versions installed, and then in your build system you would use %EWBARM_V0504% in place of the path. The worse that will happen is if the variable does not exist the build will fail, which is preferable to using the wrong compiler, and easily fixed.
Since different versions of toolchains may have different bugs and/or features, silently falling back onto different sets of tools is probably a bad idea. When I've supported multiple tools versions on a single project, I usually have the version number assigned via a makefile or the environment. Then you can pass -D TOOLS_VERSION=$(TOOLS_VERSION) to your compiler and use that value to key bugfixes and workarounds you need for particular versions of the tools. This system makes it clear which tools you want to support, while still making it easy for other developers to switch tool versions by making a single edit.
The nice thing about SCons is you have all of python at your disposal. So you can use win32.winreg to look in the registry, or glob around in sets of paths, whatever works for you. And of course you can have a command-line option or an options file to override the autodetection. Then once you've found your tool of choice, you have basically two ways to make SCons use it: either prepend the tool's dir to env['ENV']['PATH'] (you can use env.PrependEnvPath for that), or just use the tool's full path as the value of your $CC (and set $LINK, $SHLINK etc. appropriately too).
I usually make a TOOL_MYCOMPILER function that takes an env and sets it all up for use with the compiler and its toolchain (cpp, linker, whatever). It keeps things cleaner in your SConstruct/SConscript.

Adding Qt to Xcode project?

I have a fairly complex Xcode project and I want to add Qt to it. I know that I can create a new project using qmake -spec macx-xcode project.pro but I don't want to have to hand configure my old project over the auto generated Qt project. Is there another option?
[edited in a more general question below]
It seems like it would be easier to simply use qmake as my build system. Hence, adding my old project build process to the .pro file and use that to generate a new .xcodeproj? I would only do this if I could comprehensively configure the .pro file so that I don't have to hand configure the .xcodeproj - is this doable? I really don't want to have to mess around with hand configuring the .xcodeproj each time I run qmake.
Essentially, is qmake (or a meta-build in general) a valid substitute for a normal build system, such that I don't need to tweak the resulting build system generated by qmake?
Are there better resources besides the manual and tutorial provided by Trolltech? I'm concerned that wikipedia says that qmake is primarily for internal use and not well documented.
One of the main points of using Qt is the portability of the Gui. It only makes sense to extend this feature to your build process by using qmake and allowing users/developers generate whichever build system they want to use (make, visualstudio, xcode).
No, qmake is not well documented and more poignantly there are not manifold examples like there are for make. But, it is similar to make and should be intuitive. Why not absorb the overhead to learn it and pass the benefit on to your users/developers?
Build an empty xcode project with qmake and incorporate the compiler settings to your existing project from the generated Makefile. Of course, you will have to set up your existing project to run qmake as a pre-build step if you are using Qt-specific extensions.
What do you think is the easiest method for integrating established projects with Qt?
That depends on the nature of your work. I wish I could have given a more specific answer here but I really can't. Also, are you using Qt professional? In that case, you can get support (at least that's how it was, during 3.3 when I last worked on it for anything production-quality). If all you care about Qt is the graphics part, I'd say don't bother changing your build system, rather see to it that you get the code to compile and link and run just fine. But, if you are going to use signals and slots and what not -- think about moving over.
Would you recommend I do the xcodeproj merge I asked about and which you answered, or should I start from scratch with qmake like I edited a question about?
Again, look at the size of your project. Assuming a fairly complex project, I'd hazard a guess that you have about 2/3 man-days worth of effort to rewrite the build system? Is this project a serious one, something that will be maintained over a period of time? Is this cross-platform? Will you be using Qt throughout?
If there is an overbearing reason to feel that Qt is the way forward I'd suggest that you start using their build system.
It's really, really, really nice to have a single IDE and debugger that works on all the platforms you are writing for, but I have found that it's also pretty nice to just use the native tools.
Once you put in the time to learn each build system, it's pretty easy to maintain the projects to a very precise degree.