Directory and files not showing up in QtCreator tree after opening a CMakeList.txt file - cmake

I apologize for the basic question but being new to Cmake, I have a hard time doing very simple things.
So basically, I'm working on the pixhawk firmware : https://github.com/PX4/Firmware which uses extensively CMake/make files.
Under the src folder, I've created my own folder containing two subfolders which contain themselves their CMakeLists.txt file and the source code (no CMakeLists.txt in my own folder).
However, when I open the top CMakeLists.txt in QtCreator, my own newly created folder (along with its sub-folder and containing files) doesn't appear in the tree, which is very inconvenient to work directly from QtCreator.
What should I modify in the top CMakeLists.txt to get it display in QtCreator ? I thought that a simple include_subdirectory would do the job but it didn't (because, if my memory's right, cmake was complaining that there is no CMakeLists.txt in my own folder, only in its sub-folders).
Ps : if by any chance, you're a drone developer and know about pixhawk, it would be very nice if you could take some time to answer the questions I posted there : http://discuss.px4.io/t/cmake-help/4523

Hum maybe you can simply add this to your top CmakeList ?
add_subdirectory(myfolder/app1)
add_subdirectory(myfolder/app2)

Related

Can CLion project files be stored in a specified folder by default?

I've been using CLion for a little while now, and I quite like it, except that it stores it's prject files by default in my CMake project. I am wondering if I can set a default place it stores it's project files(like compiled executables) in specific directory, per project.(So not one big folder that might interfere with other projects). The reason I want to do that is because I don't like having it in my git project(yes, I know about .gitignore) Anyone know how to do that?
Thanks!
To use a different folder for CLion building
In the CLion menu:
Build,Execution,Deployment -> Cmake -> Generation Path
Change the value to the folder path you want.
To include source code from a different folder out of current
In your CMakeLists.txt, add subdirectory like following:
add_subdirectory(<PATH_OF_YOUR_ANOTHER_CMAKE_PROJECT>)
Be aware PATH_OF_YOUR_ANOTHER_CMAKE_PROJECT can be anywhere on your computer, which does not have to be in your current project folder or one of the sub-folders.

Configure CMake to show include directory in QT Creator

I'm trying to figure out how SFML's CMake configuration shows the <SFML/*> include directory in a project folder.
My test project has include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) but the include folder does not appear in the project structure like SFML's
The folder will show up if you have added any source files from within that directory (or a subdirectory below it) to any target in the project. Since you are talking about headers, you can simply add the header files as sources to an existing target. CMake will just ignore them as far as the building of that target is concerned, but it will then add those headers to the project's list of files. I've also seen people add a static library target with nothing but headers listed just so those headers show up in the project view. A bit hacky in my opinion, but it gets the job done.

Something strange with Project Paths in IntelliJ 14.1.4

So, something has started to act weird in my intelliJ project. I even tried removing the iml and .idea data, to no avail.
I go to Project Structure. There, I have a content root. Withing, I have three folders - one for my jar (and jni lib), one for Samples and one for Tools (just tools written to use the jar). The jar, Samples and Tools are marked blue (sources).
In the jar folder, I have my source tree (com\company\projectname\XXX), a lib folder, a folder for my JNI lib and a folder I created call 'junit', which is the focus of this question. It is marked in Project Structure in green (Tests).
Within, I have a folder structure eerily similar to my code: com\company\projectname\junit.
When I open a file in junit\com\company\xxx\junit, I have a big red underline under my package com.company.xxx.junit; line which tells me: "Package name 'com.company.xxx.junit' does not correspond to the file path 'junit.com.company.xxx.junit'.
I was under the impression that marking a folder as 'Tests' would instruct the IDE to use that as a "parent" folder, if you will, eliminating the need to prepend another folder name.
How can I separate the code from unit tests and in fact, create two junit test suites (one is for internal use, the other is a 'skeleton' for distribution), park them under one "umbrella" folder and NOT have to prepend the package names with that folder name?
Update: Project structure:
Based on your screen shot, the issue is that the junit directory is a subdirectory of another source directory, namely MyProvider. A source directory (whether a "production" source or a unit test source directory) cannot be a subdirectory of another source directory.
You need to either:
move the junit directory out of MyProvider so it is a sibling directory, or
unmark MyProvider as a source directory, create a main (or some such directory) in MyProvider, mark it as a source directory, and then move the com directory/package into main.
Option 2 would be the preferred way to deal with this as it follows a very common directory structure standard.
UPDATE (Following comment from OP)
Here's a couple of screenshot showing the configuration you desire:
I removed the .IdeaIC15 folder and started over. Working for now. Something must have gotten confused in the config, either as part of the update, or in the course of operation. I have taken a backup copy as it is now, so if this happens again, I will have something to check.

Let CMake rescan a directory (Usage of GLOB_RECURSE)

When using GLOB_RECURSE to add a certain directory structure to a list, CMake doesn't detect if new files are added to the directory.
How can I make CMake rescan the directory structure on every run, so that new files are detected?
You have to touch CMakeLists.txt whenever you change the directory contents.
What you're doing goes counter to official advice, but I do it too. You could knock up a script which monitors a directory for changes, but CMake considers this to be not its business.
The reason, I suspect, is that directory modification timestamp attributes aren't very cross-platform.

CMAKE for a build a simple framework

I have my mind crashing with cmake. After this answer I have tried to make a simple example and put it in github because there are a lot of file inside directories and could be boring copy everything here.
What I'd like to do is to build a simple frameworks for handling my qt/opencv/opengl experiments. What I like to have is a repository with those directories:
root*
|-apps
|---test1*
|
|-build
|-cmake*
|
|-modules
|---foo*
(The * signed directory are the ones with some cmake files like CmakeLists.txt or FindXXModule.cmake)
In modules i can write the modules (for example a module for face recognition, a module for draw a red cube in opengl, a module that contains my personal qt widget extension).
Than I need an easy way for create an application and link some modules on it. For that I thought to create a cmake directory where to put the FindXXModule.cmake and in the apps just say: find_package(XXModule).
Note that for now I don't care about installing this repository and the tree structure must be this one (so if I am in a apps/test2 I know I can refer to the cmake directory as ../../cmake or the module directory is ../../modules)
I have wrote a little example with the app named test1 that uses the module foo and i put it in a github repository.
For now I can compile the application test1 with cmake calling cmake path_to_test1_CmakeLists.txt and I am happy about that. But if I try to launch cmake path_to_root_CmakeLists.txt it does not work because the file Findfoo.cmake is read two time (and i did't be able to use some if for not reading it twice).
Then, if i run the test1 cmake a foo directory with cmake cache etc are created in root/cmake and I don't want it. I want all file cmake has to generate are in root/build directory.
So, those are my 2 question:
How create a CmakeLists.txt that can build all the apps and all the future test i will write in the modules directory
How avoid that launching cmake of a single app will create files in the cmake directory.
Sorry if my english and my idea of how cmake works are not good.. i hope it is clear.
EDIT:
One more thing. In Findfoo.cmake I have a bad hack: for adding the real CMakeLists.txt inside a modules/foo when I call the cmake from test1 I have to add a subdirectory that is not in the tree.. Maybe this kind of hack could be deleted reviewing the enteire structure..
As you say you want to put the whole directory structure into source control. This means these folder structure is same on every location where you do a checkout. So why creating the Findfoo.cmake if you have a relative path the the foo directory?
I suggest to put a CMakelists.txt file in to root that adds all subdirectories. To reduce confusion between files generated by CMake and original files, you should create a folder called ./build (or even ../build) and run CMake in that directory with the root directory as first argument. This creates all CMake generated files in the ./build directory and gives you the possibility to clean it up easily. This way of working is called out-of-source build and its highly recommended to use cmake in this way. See this question for an example.