[cmake-developers] CMake 3.12: transitive OBJECT library failing
Deniz Bahadir
dbahadir at benocs.com
Thu Jul 19 05:58:21 EDT 2018
Am 19.07.2018 um 06:34 schrieb Levi Morrison:
> I have an issue in CMake 3.12 with using transitive OBJECT
> libraries.The basic skeleton is:
>
> cmake_minimum_required(VERSION 3.12)
> project(objectlib LANGUAGES CXX)
>
> add_library(box OBJECT box.cc box.hh)
> add_library(make_box OBJECT make_box.cc make_box.hh)
> target_link_libraries(make_box PUBLIC box)
>
> add_executable(main main.cc)
> target_link_libraries(main PUBLIC make_box)
>
> Note that `main` depends on `make_box`, not `box`, which should be
> transitive (correct?). The full files can be seen in this gist:
> https://gist.github.com/morrisonlevi/b1508531b1464921664ca06c0fd889bb
>
> The issue is that when building`main` it does not include `box.o` in
> the link line.
>
> Given how new this feature is, I'm not sure if it's an issue with my
> expectations or with CMake.
It is an issue with your expectations.
Object files are non-transitive only the usage-requirements of an OBJECT
library are transitive.
The command `target_link_libraries(make_box PUBLIC box)` behaves for the
usage-requirements of `box` as written (and expected by you) but for the
object files it behaves as if you had written
`target_link_libraries(make_box PRIVATE box)`.
> The issue happens in debug builds and goes
> away in release mode, presumably because the compiler inlines it.
>
Your guess is probably correct.
HTH,
Deniz
PS: There is already a feature-request to lift this restriction.
(https://gitlab.kitware.com/cmake/cmake/issues/18090) If you want this
restriction lifted you should probably participate in the discussion and
mention possible use-cases.
More information about the cmake-developers
mailing list