[CMake] Re: Sharing code between projects

James Bigler bigler at cs.utah.edu
Fri Aug 24 12:11:26 EDT 2007


kitts wrote:
> On Thursday 23 Aug 2007 3:53:41 pm kitts wrote:
>> Anyway, I have a new set of projects and my current problem is that i have
>> some code that i share between projects. Once source can be shared not
>> binaries.
>>
>> Code is organized as;
>> src/common
>> src/project1
>> src/project2
>>
>> The CMakeLists.tst files are located inside for each project which sets the
>> right compiler and sources to be built. Now i want common to be included in
>> each of these proejects and build separately for each by inheriting all the
>> settings for that project.
>>
>> What is the best way to achieve this? I cant use ADD_SUBDIRECTORY() as it
>> is really a sibling folder (cmake complains if I use "../common").
> 
> Does anybody have a solution around this? The only way i could think of is to 
> copy the common folder during configure time and run cmake again inside it by 
> using the current cache. This is not a very efficient way as not all of the 
> common folder code is necessary in every project. Also code changes in the 
> common directory will not result in an update in the project.

Have a look at LOAD_CACHE in the documentation.  This will allow you to 
load in cache variables from another cmake build.

Also look at EXPORT_LIBRARY_DEPENDENCIES if you need to get out library 
dependencies of your project.  With that file you can simply IMPORT() 
said file in your new project and life gets happy again.  I've done this 
with projects that build static libraries, and I need to tell an 
external project the library dependencies.

James


More information about the CMake mailing list