summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-05-19 18:17:47 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-05-19 18:17:50 (GMT)
commit561e5edc3c63495bb7f9d09b5b1fda136bc07cf4 (patch)
tree0398b138b49cd644cdca4142894707d68efca425
parenta2f1c8bd98decaaf7402519217dbf0fd386f92ff (diff)
parent37627217082be815cb42611d1d23721ad0799c5c (diff)
downloadCMake-561e5edc3c63495bb7f9d09b5b1fda136bc07cf4.zip
CMake-561e5edc3c63495bb7f9d09b5b1fda136bc07cf4.tar.gz
CMake-561e5edc3c63495bb7f9d09b5b1fda136bc07cf4.tar.bz2
Merge topic 'FindProtobuf-targets'
37627217 Help: Add notes for topic 'FindProtobuf-targets' e4e1d194 FindProtobuf: add tests f29635b6 FindProtobuf: add targets Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !861
-rw-r--r--Help/release/dev/FindProtobuf-targets.rst5
-rw-r--r--Modules/FindProtobuf.cmake81
-rw-r--r--Tests/CMakeLists.txt4
-rw-r--r--Tests/FindProtobuf/CMakeLists.txt10
-rw-r--r--Tests/FindProtobuf/Test/CMakeLists.txt32
-rw-r--r--Tests/FindProtobuf/Test/main-protoc.cxx8
-rw-r--r--Tests/FindProtobuf/Test/main.cxx8
7 files changed, 148 insertions, 0 deletions
diff --git a/Help/release/dev/FindProtobuf-targets.rst b/Help/release/dev/FindProtobuf-targets.rst
new file mode 100644
index 0000000..e38303d
--- /dev/null
+++ b/Help/release/dev/FindProtobuf-targets.rst
@@ -0,0 +1,5 @@
+FindProtobuf-targets
+--------------------
+
+* The :module:`FindProtobuf` module now provides imported targets
+ when the libraries are found.
diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
index 102ed42..6dc0444 100644
--- a/Modules/FindProtobuf.cmake
+++ b/Modules/FindProtobuf.cmake
@@ -40,6 +40,15 @@
# ``Protobuf_LITE_LIBRARIES``
# The protobuf-lite libraries
#
+# The following :prop_tgt:`IMPORTED` targets are also defined:
+#
+# ``Protobuf::protobuf``
+# The protobuf library.
+# ``Protobuf::protobuf-lite``
+# The protobuf lite library.
+# ``Protobuf::protoc``
+# The protoc library.
+#
# The following cache variables are also available to set or use:
#
# ``Protobuf_LIBRARY``
@@ -409,6 +418,78 @@ if(Protobuf_INCLUDE_DIR)
message(WARNING "Protobuf compiler version ${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}"
" doesn't match library version ${Protobuf_VERSION}")
endif()
+
+ if(Protobuf_LIBRARY)
+ if(NOT TARGET Protobuf::protobuf)
+ add_library(Protobuf::protobuf UNKNOWN IMPORTED)
+ set_target_properties(Protobuf::protobuf PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
+ if(EXISTS "${Protobuf_LIBRARY}")
+ set_target_properties(Protobuf::protobuf PROPERTIES
+ IMPORTED_LOCATION "${Protobuf_LIBRARY}")
+ endif()
+ if(EXISTS "${Protobuf_LIBRARY_RELEASE}")
+ set_property(TARGET Protobuf::protobuf APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(Protobuf::protobuf PROPERTIES
+ IMPORTED_LOCATION_RELEASE "${Protobuf_LIBRARY_RELEASE}")
+ endif()
+ if(EXISTS "${Protobuf_LIBRARY_DEBUG}")
+ set_property(TARGET Protobuf::protobuf APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties(Protobuf::protobuf PROPERTIES
+ IMPORTED_LOCATION_DEBUG "${Protobuf_LIBRARY_DEBUG}")
+ endif()
+ endif()
+ endif()
+
+ if(Protobuf_LITE_LIBRARY)
+ if(NOT TARGET Protobuf::protobuf-lite)
+ add_library(Protobuf::protobuf-lite UNKNOWN IMPORTED)
+ set_target_properties(Protobuf::protobuf-lite PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
+ if(EXISTS "${Protobuf_LITE_LIBRARY}")
+ set_target_properties(Protobuf::protobuf-lite PROPERTIES
+ IMPORTED_LOCATION "${Protobuf_LITE_LIBRARY}")
+ endif()
+ if(EXISTS "${Protobuf_LITE_LIBRARY_RELEASE}")
+ set_property(TARGET Protobuf::protobuf-lite APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(Protobuf::protobuf-lite PROPERTIES
+ IMPORTED_LOCATION_RELEASE "${Protobuf_LITE_LIBRARY_RELEASE}")
+ endif()
+ if(EXISTS "${Protobuf_LITE_LIBRARY_DEBUG}")
+ set_property(TARGET Protobuf::protobuf-lite APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties(Protobuf::protobuf-lite PROPERTIES
+ IMPORTED_LOCATION_DEBUG "${Protobuf_LITE_LIBRARY_DEBUG}")
+ endif()
+ endif()
+ endif()
+
+ if(Protobuf_PROTOC_LIBRARY)
+ if(NOT TARGET Protobuf::protoc)
+ add_library(Protobuf::protoc UNKNOWN IMPORTED)
+ set_target_properties(Protobuf::protoc PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
+ if(EXISTS "${Protobuf_PROTOC_LIBRARY}")
+ set_target_properties(Protobuf::protoc PROPERTIES
+ IMPORTED_LOCATION "${Protobuf_PROTOC_LIBRARY}")
+ endif()
+ if(EXISTS "${Protobuf_PROTOC_LIBRARY_RELEASE}")
+ set_property(TARGET Protobuf::protoc APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(Protobuf::protoc PROPERTIES
+ IMPORTED_LOCATION_RELEASE "${Protobuf_PROTOC_LIBRARY_RELEASE}")
+ endif()
+ if(EXISTS "${Protobuf_PROTOC_LIBRARY_DEBUG}")
+ set_property(TARGET Protobuf::protoc APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties(Protobuf::protoc PROPERTIES
+ IMPORTED_LOCATION_DEBUG "${Protobuf_PROTOC_LIBRARY_DEBUG}")
+ endif()
+ endif()
+ endif()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index acd014a..4b335bd 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1438,6 +1438,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindPNG)
endif()
+ if(CMake_TEST_FindProtobuf)
+ add_subdirectory(FindProtobuf)
+ endif()
+
if(CMake_TEST_FindTIFF)
add_subdirectory(FindTIFF)
endif()
diff --git a/Tests/FindProtobuf/CMakeLists.txt b/Tests/FindProtobuf/CMakeLists.txt
new file mode 100644
index 0000000..1cdb2ae
--- /dev/null
+++ b/Tests/FindProtobuf/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindProtobuf.Test COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindProtobuf/Test"
+ "${CMake_BINARY_DIR}/Tests/FindProtobuf/Test"
+ ${build_generator_args}
+ --build-project TestFindProtobuf
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
diff --git a/Tests/FindProtobuf/Test/CMakeLists.txt b/Tests/FindProtobuf/Test/CMakeLists.txt
new file mode 100644
index 0000000..d7a5081
--- /dev/null
+++ b/Tests/FindProtobuf/Test/CMakeLists.txt
@@ -0,0 +1,32 @@
+cmake_minimum_required(VERSION 3.4)
+project(TestFindProtobuf CXX)
+include(CTest)
+
+find_package(Protobuf REQUIRED)
+
+add_executable(test_tgt main.cxx)
+target_link_libraries(test_tgt Protobuf::protobuf)
+add_test(NAME test_tgt COMMAND test_tgt)
+
+add_executable(test_var main.cxx)
+target_include_directories(test_var PRIVATE ${Protobuf_INCLUDE_DIRS})
+target_link_libraries(test_var PRIVATE ${Protobuf_LIBRARIES})
+add_test(NAME test_var COMMAND test_var)
+
+add_executable(test_tgt_lite main.cxx)
+target_link_libraries(test_tgt_lite Protobuf::protobuf-lite)
+add_test(NAME test_tgt_lite COMMAND test_tgt_lite)
+
+add_executable(test_var_lite main.cxx)
+target_include_directories(test_var_lite PRIVATE ${Protobuf_INCLUDE_DIRS})
+target_link_libraries(test_var_lite PRIVATE ${Protobuf_LITE_LIBRARIES})
+add_test(NAME test_var_lite COMMAND test_var_lite)
+
+add_executable(test_tgt_protoc main-protoc.cxx)
+target_link_libraries(test_tgt_protoc Protobuf::protoc)
+add_test(NAME test_tgt_protoc COMMAND test_tgt_protoc)
+
+add_executable(test_var_protoc main-protoc.cxx)
+target_include_directories(test_var_protoc PRIVATE ${Protobuf_INCLUDE_DIRS})
+target_link_libraries(test_var_protoc PRIVATE ${Protobuf_PROTOC_LIBRARIES})
+add_test(NAME test_var_protoc COMMAND test_var_protoc)
diff --git a/Tests/FindProtobuf/Test/main-protoc.cxx b/Tests/FindProtobuf/Test/main-protoc.cxx
new file mode 100644
index 0000000..64e5ada
--- /dev/null
+++ b/Tests/FindProtobuf/Test/main-protoc.cxx
@@ -0,0 +1,8 @@
+#include <google/protobuf/compiler/command_line_interface.h>
+
+int main()
+{
+ google::protobuf::compiler::CommandLineInterface();
+
+ return 0;
+}
diff --git a/Tests/FindProtobuf/Test/main.cxx b/Tests/FindProtobuf/Test/main.cxx
new file mode 100644
index 0000000..87d5c12
--- /dev/null
+++ b/Tests/FindProtobuf/Test/main.cxx
@@ -0,0 +1,8 @@
+#include <google/protobuf/stubs/common.h>
+
+int main()
+{
+ GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+ return 0;
+}