[CMake] add_library without source code
Michael Wild
themiwi at gmail.com
Wed Jul 28 03:43:28 EDT 2010
On 28. Jul, 2010, at 9:32 , Matthias Goesswein wrote:
> Am 27.07.2010 20:01, schrieb Alexander Neundorf:
>> On Tuesday 27 July 2010, Matthias Gwein wrote:
>>> Hello!
>>>
>>> I'm using cmake 2.8.2 and I'd like to build a library of libraries and
>>> i have no additional source code.
>>> I tried something like that:
>>>
>>> add_library(mylib )
>>> target_link_libraries(mylib lib1 lib2)
>>>
>>> But that doesn't work, because add_library needs at least a source file.
>>>
>>> Is there any way to get that work, without creating a dummy source file?
>>
>> AFAIK no.
>> If you want, you can create that dummy file e.g. with file(WRITE ...), so it
>> doesn't have to go into version control.
>>
>> lib1 and lib2 are shared libs, right ?
>>
>> Alex
>
> No they are static libraries. I recognized that i have the same problem with add_executable, there is also at least one source file necessary and i don't like to make dummy files for nothing.
>
> But maybe the configuration of my build is unusual for CMake. I've configured them like in my old Make Projects:
>
> I organize different software modules in subdirectories, so i have e.g.
>
> /modul1/modul1.c
> /modul1/CMakelists.txt
> /modul2/modul2.c
> /modul2/CMakelists.txt
> /CMakelists.txt
>
> The CMakelists is in the project root directory and adds the subdirectories (there are also CMakeLists.txt in the subdirectories)
>
> In the Subdirectories, I make libraries (e.g. add_library(modul1 modul1.c)), and in the root directory i'd like to link all libraries to a big library or to a executable. I tried to use add_library only with the library name and too use target_link_libraries to add the libraries of the su-modules, which didn't work.
> I don't like to have source files in the root directory, so i don't have source files for the commands add_library or add_executable in the root CMakeLists.txt file.
>
> How is somethiong like that usually done with CMake?
>
> Matthias.
Are those libraries only "convenience" libraries? I.e. are you ever going to install them? If not, just list the source-files in the top-level CMakeLists.txt:
add_executable(super-duper
modul1/modul1.c
module2/module2.c
)
This also saves time since you don't have to run ar and ranlib.
HTH
Michael
More information about the CMake
mailing list