Skip to content

Commit

Permalink
Fix cmake install targets (#9822)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jonringer authored Apr 21, 2022
1 parent 46710ca commit c80808c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c80808c

Please sign in to comment.