[cmake-developers] Exported targets with imported dependencies in CMake 3.0
Philipp Möller
bootsarehax at gmail.com
Thu Mar 6 08:14:28 EST 2014
Hi,
one thing that has bothered me in earlier CMake versions is how targets
with imported dependencies are exported. Consider this contrived case:
add_library(yaml SHARED IMPORTED)
set_target_properties(yaml PROPERTIES IMPORTED_LOCATION "/usr/lib/libyaml.so")
set_target_properties(yaml PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "/usr/include")
add_library(main SHARED main.cpp)
target_link_libraries(main yaml)
export(TARGETS main FILE myproj-exports.cmake)
The generated export file is going to contain this:
# Create imported target main
add_library(main SHARED IMPORTED)
# Import target "main" for configuration ""
set_property(TARGET main APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
set_target_properties(main PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG "yaml"
IMPORTED_LOCATION_NOCONFIG "/tmp/cmake/build/libmain.so"
IMPORTED_SONAME_NOCONFIG "libmain.so"
)
The problem I see is that, to make this work for a consumer of the
imported target to have a yaml target as well. Unfortunately, I cannot
export yaml, because it isn't being build by this tree.
Of course, I can just require users to fix the dependency themselves,
but sometimes I would like to specify things like
INTERFACE_COMPILE_DEFINITIONS on an imported target that I need to
propagate.
It would be great, if I could export imported targets and if CMake could
walk the dependency tree automatically and import those targets on an
as-needed basis.
Am I missing anything here that already allows me to do this or is this
a worthwhile feature to add?
Cheers,
Philipp
More information about the cmake-developers
mailing list