Remove duplicate code from protobuf compiler flag

This commit is contained in:
Joe Schmitt 2017-06-30 14:40:55 -07:00
parent 997107adb7
commit 294b56c593

View File

@ -17,53 +17,28 @@ index 7618ba21..bd92b09d 100644
if (protobuf_BUILD_TESTS)
include(tests.cmake)
diff --git a/cmake/install.cmake b/cmake/install.cmake
index 28dc90dc..44e4939c 100644
index 28dc90dc..52c1f721 100644
--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -1,21 +1,38 @@
@@ -1,9 +1,12 @@
include(GNUInstallDirs)
-foreach(_library
+set(LIBRARIES_TO_SET_DEST libprotobuf-lite libprotobuf)
+if(protobuf_BUILD_COMPILER)
+ list(APPEND LIBRARIES_TO_SET_DEST libprotoc)
+endif()
+
foreach(_library
- libprotobuf-lite
- libprotobuf
- libprotoc)
- set_property(TARGET ${_library}
- PROPERTY INTERFACE_INCLUDE_DIRECTORIES
- $<BUILD_INTERFACE:${protobuf_source_dir}/src>
- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
- install(TARGETS ${_library} EXPORT protobuf-targets
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
-endforeach()
+if(protobuf_BUILD_COMPILER)
+ foreach(_library
+ libprotobuf-lite
+ libprotobuf
+ libprotoc)
+ set_property(TARGET ${_library}
+ PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ $<BUILD_INTERFACE:${protobuf_source_dir}/src>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+ install(TARGETS ${_library} EXPORT protobuf-targets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
+ endforeach()
+else()
+ foreach(_library
+ libprotobuf-lite
+ libprotobuf)
+ set_property(TARGET ${_library}
+ PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ $<BUILD_INTERFACE:${protobuf_source_dir}/src>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+ install(TARGETS ${_library} EXPORT protobuf-targets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
+ endforeach()
+endif()
+ ${LIBRARIES_TO_SET_DEST})
set_property(TARGET ${_library}
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${protobuf_source_dir}/src>
@@ -14,8 +17,10 @@ foreach(_library
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
endforeach()
-install(TARGETS protoc EXPORT protobuf-targets
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
@ -74,26 +49,17 @@ index 28dc90dc..44e4939c 100644
file(STRINGS extract_includes.bat.in _extract_strings
REGEX "^copy")
@@ -94,10 +111,18 @@ configure_file(protobuf-options.cmake
@@ -94,7 +99,12 @@ configure_file(protobuf-options.cmake
${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)
# Allows the build directory to be used as a find directory.
-export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
- NAMESPACE protobuf::
- FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
-)
+set(FIND_DIRS libprotobuf-lite libprotobuf)
+if(protobuf_BUILD_COMPILER)
+ export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
+ NAMESPACE protobuf::
+ FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
+ )
+else()
+ export(TARGETS libprotobuf-lite libprotobuf
+ NAMESPACE protobuf::
+ FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
+ )
+ list(APPEND FIND_DIRS libprotoc protoc)
+endif()
+
install(EXPORT protobuf-targets
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
+export(TARGETS ${FIND_DIRS}
NAMESPACE protobuf::
FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
)