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..