[CMake] Setting up a folder structure?

Michael Wild themiwi at gmail.com
Sat Jul 18 10:03:01 EDT 2009


On 18. Jul, 2009, at 14:01, motes motes wrote:

> I am setting up a new project that I need to build with cmake. It  
> has the
> following structure:
>
> /lib
>
> /registration
> /registration/typeA
> /registration/typeB
>
> /validation
>
>
>
>
> 1) In /registration/typeA I need a main file to run the typeA  
> application.
> 2) In /registration/typeB I need a main file to run the typeB  
> application.
> 3) In /validation I need a main file to run the validation  
> application.
> 4) In / I need a main file to run the all the above application.
>
> As I understand I therefore need a CMakeLists.txt file in:
>
> /
> /registration/typeA/
> /registration/typeB/
> /validation/
>
> totalling 4 CMakeLists.txt files in total. Am I doing it right?


Hi

In principle you could do it all in one single top-level  
CMakeLists.txt file. However, that single file would then become  
rather bloated and contain lots of not-directly related things. So  
yes, I would recommend having in each of above mentioned directories a  
CMakeLists.txt. You might even consider putting one into / 
registration, and in there do the add_subdirectory calls for typeA and  
typeB.

What is important that you do most of the configuration stuff in the  
top-level CMakeLists.txt file (i.e. doing find_package, find_library,  
find_path, option etc.). In the lower-level files only do what is  
directly related to the particular library/executable (i.e. defining  
the source files, calling add_library/add_executable,  
target_link_libraries, set_target_properties, ...).

HTH

Michael


More information about the CMake mailing list