FindProtobuf: Rename imported targets to match upstream names

Rename our recently added imported targets to match those provided by
the upstream's CMake-based build.  That way a project using
`find_package(Protobuf)` can get the same target names no matter how
protobuf is found.

Suggested-by: Konstantin Podsvirov <konstantin@podsvirov.pro>
This commit is contained in:
Brad King 2017-05-22 10:48:41 -04:00
parent 73038a85ea
commit a5ccddf057
2 changed files with 30 additions and 30 deletions

View File

@ -42,11 +42,11 @@
# #
# The following :prop_tgt:`IMPORTED` targets are also defined: # The following :prop_tgt:`IMPORTED` targets are also defined:
# #
# ``Protobuf::protobuf`` # ``protobuf::libprotobuf``
# The protobuf library. # The protobuf library.
# ``Protobuf::protobuf-lite`` # ``protobuf::libprotobuf-lite``
# The protobuf lite library. # The protobuf lite library.
# ``Protobuf::protoc`` # ``protobuf::libprotoc``
# The protoc library. # The protoc library.
# #
# The following cache variables are also available to set or use: # The following cache variables are also available to set or use:
@ -420,72 +420,72 @@ if(Protobuf_INCLUDE_DIR)
endif() endif()
if(Protobuf_LIBRARY) if(Protobuf_LIBRARY)
if(NOT TARGET Protobuf::protobuf) if(NOT TARGET protobuf::libprotobuf)
add_library(Protobuf::protobuf UNKNOWN IMPORTED) add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
set_target_properties(Protobuf::protobuf PROPERTIES set_target_properties(protobuf::libprotobuf PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}") INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
if(EXISTS "${Protobuf_LIBRARY}") if(EXISTS "${Protobuf_LIBRARY}")
set_target_properties(Protobuf::protobuf PROPERTIES set_target_properties(protobuf::libprotobuf PROPERTIES
IMPORTED_LOCATION "${Protobuf_LIBRARY}") IMPORTED_LOCATION "${Protobuf_LIBRARY}")
endif() endif()
if(EXISTS "${Protobuf_LIBRARY_RELEASE}") if(EXISTS "${Protobuf_LIBRARY_RELEASE}")
set_property(TARGET Protobuf::protobuf APPEND PROPERTY set_property(TARGET protobuf::libprotobuf APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE) IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(Protobuf::protobuf PROPERTIES set_target_properties(protobuf::libprotobuf PROPERTIES
IMPORTED_LOCATION_RELEASE "${Protobuf_LIBRARY_RELEASE}") IMPORTED_LOCATION_RELEASE "${Protobuf_LIBRARY_RELEASE}")
endif() endif()
if(EXISTS "${Protobuf_LIBRARY_DEBUG}") if(EXISTS "${Protobuf_LIBRARY_DEBUG}")
set_property(TARGET Protobuf::protobuf APPEND PROPERTY set_property(TARGET protobuf::libprotobuf APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG) IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(Protobuf::protobuf PROPERTIES set_target_properties(protobuf::libprotobuf PROPERTIES
IMPORTED_LOCATION_DEBUG "${Protobuf_LIBRARY_DEBUG}") IMPORTED_LOCATION_DEBUG "${Protobuf_LIBRARY_DEBUG}")
endif() endif()
endif() endif()
endif() endif()
if(Protobuf_LITE_LIBRARY) if(Protobuf_LITE_LIBRARY)
if(NOT TARGET Protobuf::protobuf-lite) if(NOT TARGET protobuf::libprotobuf-lite)
add_library(Protobuf::protobuf-lite UNKNOWN IMPORTED) add_library(protobuf::libprotobuf-lite UNKNOWN IMPORTED)
set_target_properties(Protobuf::protobuf-lite PROPERTIES set_target_properties(protobuf::libprotobuf-lite PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}") INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
if(EXISTS "${Protobuf_LITE_LIBRARY}") if(EXISTS "${Protobuf_LITE_LIBRARY}")
set_target_properties(Protobuf::protobuf-lite PROPERTIES set_target_properties(protobuf::libprotobuf-lite PROPERTIES
IMPORTED_LOCATION "${Protobuf_LITE_LIBRARY}") IMPORTED_LOCATION "${Protobuf_LITE_LIBRARY}")
endif() endif()
if(EXISTS "${Protobuf_LITE_LIBRARY_RELEASE}") if(EXISTS "${Protobuf_LITE_LIBRARY_RELEASE}")
set_property(TARGET Protobuf::protobuf-lite APPEND PROPERTY set_property(TARGET protobuf::libprotobuf-lite APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE) IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(Protobuf::protobuf-lite PROPERTIES set_target_properties(protobuf::libprotobuf-lite PROPERTIES
IMPORTED_LOCATION_RELEASE "${Protobuf_LITE_LIBRARY_RELEASE}") IMPORTED_LOCATION_RELEASE "${Protobuf_LITE_LIBRARY_RELEASE}")
endif() endif()
if(EXISTS "${Protobuf_LITE_LIBRARY_DEBUG}") if(EXISTS "${Protobuf_LITE_LIBRARY_DEBUG}")
set_property(TARGET Protobuf::protobuf-lite APPEND PROPERTY set_property(TARGET protobuf::libprotobuf-lite APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG) IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(Protobuf::protobuf-lite PROPERTIES set_target_properties(protobuf::libprotobuf-lite PROPERTIES
IMPORTED_LOCATION_DEBUG "${Protobuf_LITE_LIBRARY_DEBUG}") IMPORTED_LOCATION_DEBUG "${Protobuf_LITE_LIBRARY_DEBUG}")
endif() endif()
endif() endif()
endif() endif()
if(Protobuf_PROTOC_LIBRARY) if(Protobuf_PROTOC_LIBRARY)
if(NOT TARGET Protobuf::protoc) if(NOT TARGET protobuf::libprotoc)
add_library(Protobuf::protoc UNKNOWN IMPORTED) add_library(protobuf::libprotoc UNKNOWN IMPORTED)
set_target_properties(Protobuf::protoc PROPERTIES set_target_properties(protobuf::libprotoc PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}") INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
if(EXISTS "${Protobuf_PROTOC_LIBRARY}") if(EXISTS "${Protobuf_PROTOC_LIBRARY}")
set_target_properties(Protobuf::protoc PROPERTIES set_target_properties(protobuf::libprotoc PROPERTIES
IMPORTED_LOCATION "${Protobuf_PROTOC_LIBRARY}") IMPORTED_LOCATION "${Protobuf_PROTOC_LIBRARY}")
endif() endif()
if(EXISTS "${Protobuf_PROTOC_LIBRARY_RELEASE}") if(EXISTS "${Protobuf_PROTOC_LIBRARY_RELEASE}")
set_property(TARGET Protobuf::protoc APPEND PROPERTY set_property(TARGET protobuf::libprotoc APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE) IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(Protobuf::protoc PROPERTIES set_target_properties(protobuf::libprotoc PROPERTIES
IMPORTED_LOCATION_RELEASE "${Protobuf_PROTOC_LIBRARY_RELEASE}") IMPORTED_LOCATION_RELEASE "${Protobuf_PROTOC_LIBRARY_RELEASE}")
endif() endif()
if(EXISTS "${Protobuf_PROTOC_LIBRARY_DEBUG}") if(EXISTS "${Protobuf_PROTOC_LIBRARY_DEBUG}")
set_property(TARGET Protobuf::protoc APPEND PROPERTY set_property(TARGET protobuf::libprotoc APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG) IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(Protobuf::protoc PROPERTIES set_target_properties(protobuf::libprotoc PROPERTIES
IMPORTED_LOCATION_DEBUG "${Protobuf_PROTOC_LIBRARY_DEBUG}") IMPORTED_LOCATION_DEBUG "${Protobuf_PROTOC_LIBRARY_DEBUG}")
endif() endif()
endif() endif()

View File

@ -5,7 +5,7 @@ include(CTest)
find_package(Protobuf REQUIRED) find_package(Protobuf REQUIRED)
add_executable(test_tgt main.cxx) add_executable(test_tgt main.cxx)
target_link_libraries(test_tgt Protobuf::protobuf) target_link_libraries(test_tgt protobuf::libprotobuf)
add_test(NAME test_tgt COMMAND test_tgt) add_test(NAME test_tgt COMMAND test_tgt)
add_executable(test_var main.cxx) add_executable(test_var main.cxx)
@ -14,7 +14,7 @@ target_link_libraries(test_var PRIVATE ${Protobuf_LIBRARIES})
add_test(NAME test_var COMMAND test_var) add_test(NAME test_var COMMAND test_var)
add_executable(test_tgt_lite main.cxx) add_executable(test_tgt_lite main.cxx)
target_link_libraries(test_tgt_lite Protobuf::protobuf-lite) target_link_libraries(test_tgt_lite protobuf::libprotobuf-lite)
add_test(NAME test_tgt_lite COMMAND test_tgt_lite) add_test(NAME test_tgt_lite COMMAND test_tgt_lite)
add_executable(test_var_lite main.cxx) add_executable(test_var_lite main.cxx)
@ -23,7 +23,7 @@ target_link_libraries(test_var_lite PRIVATE ${Protobuf_LITE_LIBRARIES})
add_test(NAME test_var_lite COMMAND test_var_lite) add_test(NAME test_var_lite COMMAND test_var_lite)
add_executable(test_tgt_protoc main-protoc.cxx) add_executable(test_tgt_protoc main-protoc.cxx)
target_link_libraries(test_tgt_protoc Protobuf::protoc) target_link_libraries(test_tgt_protoc protobuf::libprotoc)
add_test(NAME test_tgt_protoc COMMAND test_tgt_protoc) add_test(NAME test_tgt_protoc COMMAND test_tgt_protoc)
add_executable(test_var_protoc main-protoc.cxx) add_executable(test_var_protoc main-protoc.cxx)