A library foo
is to be built either as a project of its own, or as part of a larger project bar
. For the latter, I found no better solution than line (*):
$ cat foo/lib/CMakeLists.txt
...
set(foo_LIBRARY foo PARENT_SCOPE)
...
$ cat foo/CMakeLists.txt
...
add_subdirectory(lib)
set(cerf_LIBRARY ${cerf_LIBRARY} PARENT_SCOPE) # (*)
...
$ cat bar/CMakeLists.txt
...
add_subdirectory(link-to-foo)
...
Now building bar
works. But when building only foo
, I get
CMake Warning (dev) at CMakeLists.txt:30 (set):
Cannot set "foo_LIBRARY": current scope has no parent.
Aiming for zero warnings in my projects, I'd need a better solution.