[CMake] Newie's question: Multiple applications with one common kernel
Michael Wild
themiwi at gmail.com
Tue Dec 8 04:06:17 EST 2009
On 8. Dec, 2009, at 9:27 , Matthias Moeller wrote:
> 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
Adding a subdirectory multiple times is a recipe for disaster. What
you probably want is to write CMake-function/macro that does all the
stuff you are doing now in the Kernel subdirectory and call that
function from the various applications/app* subdirectories.
Michael
More information about the CMake
mailing list