[CMake] how to modify scope of imported library

Petr Kmoch petr.kmoch at gmail.com
Fri Mar 9 04:20:44 EST 2012


Hi,

I was solving a similar problem in our setup at work. The problem was
that the parent couldn't know in advance which libraries will be
imported by children. Conceptually speaking, I solved this by creating
my own set of global properties which contain all necessary details
about the libraries imported. These properties are appended to when a
child imports a library, and then scanned once more in the parent and
imported again:

child CMakeLists.txt:
...
ADD_LIBRARY(someLib IMPORTED)
SET_PROPERTY(GLOBAL APPEND PROPERTY imported_libraries someLib)
# more SET_PROPERTY calls to store lib's location etc.
...


parent CMakeLists.txt:
...
DEFINE_PROPERTY(GLOBAL PROPERTY imported_libraries ...)
...
ADD_SUBDIRECTORY(child)
...
GET_PROPERTY(GLOBAL PROPERTY imported_libraries impLibs)
# more GET_PROPERTY calls to retrieve libs' locations etc.
FOREACH(lib IN LISTS impLibs)
  ADD_LIBRARY({$lib} IMPORTED)
ENDFOREACH()
...

Petr



On Fri, Mar 9, 2012 at 8:42 AM, Andreas Pakulat <apaku at gmx.de> wrote:
> On 08.03.12 19:24:00, Cong Ma wrote:
>> Hi,
>>
>> Imported library has scope in the directory in which it is created and
>> below.
>>
>> If I want to use this library in parent scope, what should I do?
>
> Add the imported library in the top-level cmake file, not a
> subdirectory.
>
> Andreas


More information about the CMake mailing list