[CMake] add_library without source code

Michael Wild themiwi at gmail.com
Wed Jul 28 06:26:10 EDT 2010


On 28. Jul, 2010, at 10:57 , Ingolf Steinbach wrote:

> 2010/7/28 Michael Wild <themiwi at gmail.com>:
>> 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
>>  )
> 
> Even if they are not going to be *installed* as separate libraries,
> there are realistic cases in which your approach is not ideal:
> 
> Let's assume that these are third-party libraries which come with
> their own (and maybe even conflicting) compilation settings (compiler
> flags, internal include files, ...). The top-level CMakeLists.txt
> would have to
> - "know" all the sources contributing to the libraries and
> - reflect all these internals with respect to different compilation
> settings on a source-by-source basis.
> 
> And if you are going to update one of these libraries you would have
> to reflect all the necessary changes in the top-level file.
> 
> Kind regards
> Ingolf

So, these external libraries should be compiled using ExternalProject_Add (refer to the docs). Then, in your CMakeLists.txt you should create IMPORTED libraries (again, refer to the docs of the add_library command and the IMPORTED_* target properties) for the built libraries. However, I still don't see how that would lead to the need of creating an executable or a library without any source files. Usually when you use a library, you still have to provide some of your own code, otherwise it wouldn't be a library, right?

If I didn't understand your scenario correctly, please provide some more detail and what you would CMake expect to do. Also, what would you do in "manual mode", i.e. if you did it by just using command line operations.


Michael



More information about the CMake mailing list