Discussion:
[cmake-developers] CMake 3.12: transitive OBJECT library failing
Levi Morrison
2018-07-19 04:34:57 UTC
Permalink
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. The issue happens in debug builds and goes
away in release mode, presumably because the compiler inlines it.
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers
Deniz Bahadir
2018-07-19 09:58:21 UTC
Permalink
Post by Levi Morrison
I have an issue in CMake 3.12 with using transitive OBJECT
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
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)`.
Post by Levi Morrison
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.
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers
Loading...