Using Cmake with Qt Creator - c++

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.

When you add new files in QtCreator using the "New File or Project..." dialog it only creates the files on disk, it doesn't automatically add the files to the CMakeLists.txt. You need to do this by hand by editing the CMakeLists.txt file.
The next time you build the project, CMake will be re-run, and QtCreator will pick up the new files and show them in the project browser.

I solve this problem that I added new files in standard way (CTRL+N), then added needed files in CMakeLists. After that, right click on project in project tree view and choose option Run CMake. After this, files showed in project list tree. Only build was not enough.

I tested here and happened the same behavior because those options you were asking were really disabled.
Use File -> "New File or Project..." or CTRL+N to add new files and after that add to CMakeLists.txt

I'm adding an updated answer for newer versions of QtCreator (4.x, I don't know precisely which release but at least from 4.7). In the Tools > Options... menu, choose the Build & Run section and then the CMake tab. You will see the Adding Files settings, and you can set it to Copy file paths :
This way, when you want to add a new file to your project, in the Project view, right click on the desired CMake Executable/Library's name and select Add New..., go through the Add dialog, and when you'll validate the dialog, QtCreator will open CMakeLists.txt in the Editor view. Finally, paste the content of the clipboard at the end of the corresponding source file list and save CMakeLists.txt. The CMake project will be parsed, and your new file will show up in the Project view.

Related

How can I get "go to definition" working in a JUCE project?

I'm trying to get "go to definition" working for a JUCE project created with Projucer. I've tried both CLion and Visual Studio Code, but they can't seem to find definitions that live in the JUCE libraries.
I'm on Ubuntu. Is there a blessed path for this? I'm normally a vim user, but I'm willing to try any IDE.
I've just figured this out!
In VS Code go View and Command Palette and type C/C++: Edit Configurations (UI) which will take to the IntelliSense Configurations page. Under Include path, on a new line, specify the path to JUCE e.g. ~/JUCE/**.
Note: The two stars are needed to tell VS Code to look through subdirectories.
This will create a hidden folder .vscode in your project folder with this configuration.
You will need to repeat these steps for each project you make.
Definitions and code completion should now work.
To compile your code, in your project folder go Builds then LinuxMakefile and in a terminal run the command make. Finally, go to the builds folder and run your project ./exampleProject.
You need to add the JUCE/modules folder to your search path, not the top-level JUCE/ folder!
If you're using the Projucer, you'll also need to add the JuceLibrarySource/ folder to your search path.
What I ended up doing was using FRUT to convert my project from a Projucer project to a CMake project. CLion was able to understand the CMake project, and thus, the "go to definition" and autocomplete features started working.

CLion import existing cmake projects with dependencies

I'm testing CLion to check if it will adapt to our needs.I have like 9 different projects in C++ and we generate makefiles using CMake. I read that CLion works well with this kind of projects. I'm trying to create a workspace including these 9 modules in a big project in CLion. The reason is that some of them have dependencies and could be great if we can navigate from one module to other one. I Tried to import them using the option "import project from sources". This detects all my modules but create a huge CMakeLists.txt in the root folder and this is not working for me.
I Would like to have this workspace with these modules and compile them independently but having their dependencies for navigation. I searched a lot but I didn't find anything. Can this be done in CLion?
Thank you
To create a root CMakeList.txt, which includes all sub-projects/modules is the way-to-go with CMake. If you want to compile a single submodule you only need to make a single target: make [target].
I think there is a Tool Window in CLion, where you can see all your targets and compile each independently (similar to the Maven Tool-Window in IntelliJ).
Alternativly you can create Run Configurations..
(I will append my answer later, to back it with facts.. No CLion at work..)
Unfortunately I was wrong about the Tool Window.. But CLion is creating automatically a Run/Debug Configuration for each target it has found. You can select them by clicking on the Drop-Down Menu in the upper right corner. You can either choose Build All or a specific target. Next to this menu are 3 buttons - Compile, Run and Debug - to trigger any actions.

Setup cocos2d-x application through visual studio 2010 project template

I'm trying to setup an application on Windows 7 using Cocos2D-x.
I followed this tutorial.
I did the following:
Built the library running Build-win32.bat script. Works.
Installed VS2010 project template. Works.
Run successfully all test programs.
Created a new cocos2D-x project through the installed template. Works
When I compile the Hello World application I have the follwing errors:
error C1083: impossible to open inclusion file 'CCstdC.h' No such file or directory
error C1083: impossible to open inclusion file 'cocos2d.h' No such file or directory
It's a wrong include path.
I could fix it by manually modifying include path but since I'm creating project through the template I-d like to solve this, possibly not having to modify paths manually for each new project I'll create.
Did anyone ever had the same issue?Do you know how to fix this?
Well, I setup cocos2dx projects like this:
create an empty win32 app in VS
open the folder contains your .sln file (your solution folder)
open the cocos2dx package (i.e. cocos2d-1.0.1-x-0.12.0.zip) with 7z or something
drag cocos2dx, and optionally CocosDenshion, Box2D, etc. to your solution folder
add cocos2dx project (cocos2dx\proj.win32\cocos2d-win32.vcxproj) into your solution
go to your project's properties, select C/C++->General, add the following entries to your Additional Include Directories option:
..\cocos2dx; ..\cocos2dx\include; ..\cocos2dx\platform; ..\cocos2dx\platform\win32; ..\cocos2dx\platform\third_party\win32\OGLES
and ..\CocosDenshion\include if you're using the SimpleAudioEngine
in the Linker->Input->Additional Dependencies option, add libcocos2d.lib, and libCocosDenshion.lib if you use the audio engine; in the Linker->General->Additional Library Directories option, add $(OutDir)
go to the Configuration Properties->General->Output Directory option, set it to $(SolutionDir)\build\
open the project property for cocos2d library, go to the Configuration Properties->General->Output Directory, set it to $(SolutionDir)\build\, also do that to the rest of the libraries you included.
All set, you're ready to go.
Unfortunately that template is not that useful. I believe that in a previous version of cocos2d-x (the one that tutorial is based on) the paths were absolute, and referenced the cocos2dx, cocosdenshion projects directly.
Now, as they're relative (..\..\cocos2dx), and they are not copied to the solution directory when a project is created, it just doesn't work.
You could obviously fix the paths (as you suggested) but my suggestion is: copy the HelloWorld project and use it as a template. The solution structure is much better than the one in the template as it's already prepared for iOS, win32 and Android. Trust me, can't get any easier than that.
Now, here's the catch: if you copy the HelloWorld project to a sibling folder, you're done, as all the references are already setup. If you want to copy to other place you'll have to also copy cocos2dx, cocosdenshion along, leaving the target structure like:
target_path\cocos2dx
target_path\cocosdenshion
target_path\Copy_of_Hello_World
I solved opening the cocos2dx library solution and add to it a new project through VS template wizard.

QtCreator and "Run CMake"

When running CMake from the project view in QtCreator ("Run CMake" command), CMake wizard pops up. This is becoming really annoying and since I'm QtCreator newbie, I don't know if there is any remedy for this.
Desired effect would be automatic execution of cmake, without the CMake wizard pestilence.
Yes, this GUI annoying me too.
The only option is to add custom build step in your Project configuration
run app: cmake
params CMakeLists.txt
working folder: %{sourceDir}
this step should be added BEFORE make step.
Once you have created a project in Qt Creator, you do not need to use the "Run CMake" command unless for some reason you think the project files are out of date. Just click build, run, debug etc and it will take care of compiling the files that need to be compiled and invoking CMake as and when necessary.
Underneath it uses Unix Makefiles with Codeblocks in order to generate an XML description of the project. Running CMake from the menu explicitly re-runs CMake and reparses the XML description.

Qt on Mac: add an existing UI file without rebuilding the whole project

I have a Qt project in XCode on Mac. I want to add an existing .UI file to it. When I do that by listing in the .pri file, the XCode project itself is rebuilt by qmake, and all my post-qmake settings are lost. Is there a way to insert a UI file without listing in the .pri? It's doable in a very straightforward way on Visual Studio...
There are two custom steps in the target - both call make over files in the project bundle (xcodeproj). The first one invokes qmake. The second invokes the Qt proprocessors - uic, moc. So the answer is - comment out or delete the first step, modify the makefile of the second one by hand. Add generated files (once they're generated at least once) to the project as necessary.