Add DEPRECATED option to add_library
In order to be able to deprecate or rename exported targets in a project, it would be very useful an additional option in add_library
, for example DEPRECATED
, that will issue a deprecation warning if CMAKE_WARN_DEPRECATED
is enabled (or a fatal error if CMAKE_ERROR_DEPRECATED
is enabled) whenever the target is used as link item in link_libraries
or in target_link_libraries
Proposed syntax
The syntax could be something like this:
add_library(<name> [DEPRECATED|DEPRECATED_MSG "<doc>"] <all the rest of the command>)
This should have impact only if for some reason someone was creating a library using a file named DEPRECATED
or DEPRECATED_MSG
as the first file of the list, and setting the LANGUAGE
property for that file. I suspect it is safe to assume that nobody is doing that.
Example 1
add_library(Foo DEPRECATED foo.cpp foo.h)
# or
add_library(Foo DEPRECATED SHARED foo.cpp foo.h)
# [...]
target_link_libraries(Bar Foo_old)
will print something like The "Foo" target is deprecated.
whenever Foo
is linked. The library will still be a normal library (SHARED
or STATIC
) and will be linked by Bar
Example 2
add_library(Foo_new ...)
add_library(Foo_old DEPRECATED_MSG "The \"Foo_old\" target is deprecated. Use \"Foo_new\" instead" ALIAS Foo_new)
# [...]
target_link_libraries(Bar Foo_old)
will print The "Foo_old" target is deprecated. Use "Foo_new" instead
, whenever Foo_old
is linked, but old builds will not break since the ALIAS
will link the Foo_new
library.