From c80808ce1defa4a6f02ceba8e1415b0bcdd068fd Mon Sep 17 00:00:00 2001 From: Jonathan Ringer Date: Wed, 20 Apr 2022 18:38:43 -0700 Subject: [PATCH] Fix cmake install targets (#9822) * Avoid exporting build tree targets to installation directory `export(TARGETS ...)` is meant to allow for build trees to be found from other projects, however, writing the file to an installation directory causes buildtree paths to be hardcoded in the installed protobuf-targets.cmake * Install protobuf-targets.cmake from target, not build tree This allows for installation prefixes to match the intended installation directories, instead of being copied from the build tree. --- cmake/install.cmake | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cmake/install.cmake b/cmake/install.cmake index 825cb25fc1..c1f6f4aab2 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -128,24 +128,20 @@ configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-options.cmake if (protobuf_BUILD_PROTOC_BINARIES) export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc NAMESPACE protobuf:: - FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake + FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/protobuf/protobuf-targets.cmake ) else (protobuf_BUILD_PROTOC_BINARIES) export(TARGETS libprotobuf-lite libprotobuf NAMESPACE protobuf:: - FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake + FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/protobuf/protobuf-targets.cmake ) endif (protobuf_BUILD_PROTOC_BINARIES) install(EXPORT protobuf-targets + FILE protobuf-targets.cmake DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" NAMESPACE protobuf:: - COMPONENT protobuf-export) - -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/ - DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" COMPONENT protobuf-export - PATTERN protobuf-targets.cmake EXCLUDE ) option(protobuf_INSTALL_EXAMPLES "Install the examples folder" OFF)