How to load cmake script with more than one project with Qt Creator - cmake

I have a CMake project, and until now, I was using Visual C++ for developing.
Using CMake-gui to generate a solution for VC++, it generates more than one project in the same solution.
But when the script is loaded in qt-creator, only one project is defined, with all the code and folder tree inside, so I can not compile it (or I don't know how to do it).
How can I load the cmake file to load all the projects?
More info:
The first CMakeList.txt has some common configuration. Then, with 'add_subdirectory' function, I add a project to make a library, and another project to make a sample application to use this library.

You should add multiple projects to the root cmake file with help of "add_subdirectory()". Then in Qt Creator you should open the root cmake file. After that you could choose which project to run in the select a kit for running (3) or debugging (4) application pane (check the link).
It sad that you can't (or I don't know how) build only one project. You have to build all projects are added to the root cmake file and then choose which one of them you want to run.
I use Qt Creator 4.0 .

Here is the offical doc http://qt-project.org/doc/qtcreator-2.8/creator-project-cmake.html
My project have a similar structure, just open the top-most CMakeLists.txt file of the project, and qtcreator will import your project.

Related

cmake v2.8.19.2 include folder from outside project

I am trying to build a library using cmake version 2.8.10.2
A header is included from a directory outside of the project, I’ve tried adding the path to the directory using:
add_subdirectory($ENV{PRJ2}/path/)
I’ve check the path is correct but when building I get:
fatal error: header_name.h: No such file or directory
It’s driving me crazy…
add_subdirectory adds a folder to the cmake project, searching for the CMakeLists.txt file in it and loading the configuration. If you want to add headers from a directory to a project you should use include_directories (link here)
Consider that using a directory out of the main folder of the project is not convenient. I suggest you two possibilities:
If you are using some headers that are not part of another project (for example you developed by yourself for other reasons and want to add them to your project), then move them inside one of your project folders
If the headers are from another library/project add them using the find_package system. I was not able to find a good guide for the 2.x versions of cmake, but I strongly suggest you to move to 3.x

How can I configure CMake generated Eclipse project's Build Command and Project Paths?

Our project uses CMake to configure our code. We use Ninja along with a distributed build system. A number of people on our team use Eclipse CDT. We run CMake with the "Eclipse CDT4 - Ninja" generator and the result is generally pretty good.
The issues is that any time a CMake file is changed and you ask Eclipse to build the code it regenerate the eclipse project file overwriting any manual changes you've made to the project.
For example the default build command that it provides the eclipse project is /usr/bin/ninja when in fact I want to take advantage of our distributed build system and set the build command to /usr/bin/ninja -j16. It would be nice if I could have the project file that CMake generates automatically include this setting change.
The other setting I am most interested in preserving is the C/C++ Project Paths->Source. As a general rule we place our CMake build directory as a sibling to the main project directory i.e. ./project ./build. We want to include some files in the build directory in the Eclipse index to make code completion and other tools work better. The default project doesn't include the build directory in source path and thus it does not get indexed.
Is there some way to remedy these issues?
I found a solution to build command issue.
When you run cmake to generate the eclipse project include the additional argument:-DCMAKE_ECLIPSE_NINJA_ARGUMENTS=-j100. I haven't confirmed but I believe a similar command is required for eclipse make projects -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-j100.
Unfortunately this feature is poorly documented and I have not found a solution to my other issue.

How to let some file to be visiable in QtCreator

I'm using cmake to configure my project. It seems QtCreator only show those files referred by add_executable, add_library and configure_file. Other files in project directory are not visiable in the Projects panel.
Although we can still visit those files by file->open, it make me feel bad that many important source files are not visiable in the Projects panel. So...
How does QtCreator decide whether to show a file?
Is there any cmake command that can make arbitrary file to be visiable in QtCreator?
=======================
Some additional info:
My project is a C++ library with PerlXS interface. XS code is preprocessed into C code by xsubpp, and this action is added into cmake project via add_custom_target. However, the XS file is not added into Porjects panel by QtCreator. Besides, a project can have non-source text files such as README, Changes, etc..
I see no reason to put something specific with project, when you can switch to "File System" browser in QtCreator.
But anyway, the answer still the same. If you wish to see something in project - add it to add_executable, add_library.
For example
set(DATA_FILE ${PROJECT_SOURCE_DIR}/build/README.txt)
...
add_executable(${TARGET_NAME} ${SRC_FILES} ${GLB_HDR_FILES} ${DATA_FILE})
And now we can see README.txt in project
Same trick can be done for other files. Just add them to DATA_FILE variable.

Using cmake-gui with Qt Creator

I started trying to convert a project to use CMake so that I could import the project into QtCreator to make use of the QtCreator IDE for this straight C code. This worked pretty nicely as far as giving me auto completions, code diving, etc etc.
I have had a bit of a time getting CMake to build the code as I expected, mostly because it was the first time I have been using it. I recently discovered that there is a cmake-gui that you can point at your source and it will show you the CMake variables and such. What is the proper way to actually use cmake-gui within QtCreator? When I just manually made my CMakelists.txt files within my project, it was enough to get the project in there. Should I just run Cmake-gui using locator and point it to those files? Should I keep the same build directory in cmake-gui that was created from QtCreator? Any tutorial links or guidance apprecaited - didnt find a whole lot googling.
The way I use cmake-gui with QtCreator is this:
Create a build directory and configure it with cmake-gui, like:
cmake/project$ mkdir build
cmake/project$ cd build
cmake/project/build$ cmake-gui ..
Open the CMakeLists.txt file in QtCreator, and set the build path to where you did the configuration:
Let QtCreator run the configuration by clicking "Run CMake", it will use the values you configured with cmake-gui in step 1:
You are done :)
When you need to reconfigure the CMake build, just fire up the command line, navigate to the build directory and re-run cmake-gui.

Populating the configuration to the nested library project

I have a main project, which includes a nested library project which produces a libCore.a library.
Both of the projects have the two configurations debug and release. Now if I build the main project with a given configuration, how can I make sure that this is passed down to the library project as well?
Make your project directly dependent on the libCore project. Do achieve this, do the following:
Drag the libCore project file to your main project. It happens sometimes, that only the xcodeproj file is moved. If this happens to you, restart XCode (this happend to me with RestKit and the latest XCode).
After point 1 is done and you can browse the dependency project, go to your target build phases and add the libCore as the target dependencies.
Link against libCore.a by adding in the Link Binary with Libraries phase.
These are 3 basic steps, I don't know what the libCore is, if it needs to be linked with any other libraries then you will also have to link your target against those libraries.