[CMake] Newie's question: Multiple applications with one common kernel

Matthias Moeller matthias.moeller at math.tu-dortmund.de
Tue Dec 8 03:27:42 EST 2009


Tyler Roscoe wrote:
> On Mon, Dec 07, 2009 at 05:53:37PM +0100, Matthias Moeller wrote:
>   
>> Our project has the following structure:
>>
>> root/applications (Applications by different users)
>>      applications/app1
>>      applications/app2
>>      applications/...
>>
>> root/kernel (common kernel source files)
>>
>> root/libraries (external libraries)
>>
>> Each application has some source files and uses the common source files
>> from the kernel directory which is *not* a subdirectory. In a first
>> attempt, I wrote one CMakeLists.txt file on the kernel directory which
>> has a list of all kernel source files. Each application/appX directory
>> has its own CMakeLists.txt file which includes the kernel sources via:
>>
>> ADD_SUBDIRECTORY (${APPX_SOURCE_DIR}/../..
>> ${CMAKE_CURRENT_BINARY_DIR}/kernel)
>>
>> Unfortunately, the variables defined in the kernel's CMakeLists.txt file
>> are not available from within the application's CMakeLists.txt file.
>>     
>
> When you do add_subdirectory(), you create a new scope. The variables in
> your kernel CMakeLists are set in that scope by default. Take a look at
> the PARENT_SCOPE argument to set() to deal with this.
>   
Thank you for your help. Actually, I need it in the opposite way, that
is, each application (parent) adds the kernel directory. In the kernel's
CMakeLists.txt file a list of source files is generated and this list
should be passed to the top directory (i.e. the application).

> Another common approach to this sort of setup is to deal with all the
> common kernel code in a top-level CMakeLists and then have that
> top-level CMakeLists do the add_subdirectory() calls into each appX subdirectory.
>   
Wouldn't this mean that cmake always works on all applications each time
it is called?

Matthias


More information about the CMake mailing list