Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake] Place export target file in the correct directory #5677

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ else()
NO_DEFAULT_PATH)
find_package(Protobuf)
if (Protobuf_FOUND)
set(PROTOBUF_DIR "${_PROTOBUF_INSTALL_PREFIX}")
set(PROTOBUF_INCLUDE_DIR "${_PROTOBUF_INSTALL_PREFIX}/include")
set(Build_Protobuf OFF)
if ("${Protobuf_VERSION}" VERSION_GREATER_EQUAL "4.22.0")
# There are extra dependencies for protobuf.
Expand Down Expand Up @@ -265,6 +267,8 @@ else()
set(Protobuf_VERSION "4.22.3")
# Change back the BUILD_SHARED_LIBS to control the onnx project.
set(BUILD_SHARED_LIBS ${ONNX_BUILD_SHARED_LIBS})
set(PROTOBUF_DIR "${protobuf_BINARY_DIR}")
set(PROTOBUF_INCLUDE_DIR "${protobuf_SOURCE_DIR}/src")
endif()
message(STATUS "ONNX_PROTOC_EXECUTABLE: ${ONNX_PROTOC_EXECUTABLE}")
message(STATUS "Protobuf_VERSION: ${Protobuf_VERSION}")
Expand Down Expand Up @@ -717,7 +721,19 @@ install(FILES
${PROJECT_BINARY_DIR}/ONNXConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ONNX
COMPONENT dev)
install(EXPORT ONNXTargets DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/ONNX")
install(EXPORT ONNXTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/ONNX"
NAMESPACE ONNX::
)
if (NOT Build_Protobuf)
# If we fetched a Protobuf release (and didn't run its install step), then we
# don't have the export sets for protobuf and its dependencies, which
# prevents us from creating an export set for ONNXTargets.
export(EXPORT ONNXTargets
FILE "${PROJECT_BINARY_DIR}/ONNXTargets.cmake"
NAMESPACE ONNX::
)
endif()
install(TARGETS
onnx onnx_proto
EXPORT ONNXTargets DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand Down
4 changes: 4 additions & 0 deletions cmake/ONNXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
# library version information
set(ONNX_VERSION "@ONNX_VERSION@")

list(APPEND CMAKE_PREFIX_PATH "@PROTOBUF_DIR@")
set(Protobuf_INCLUDE_DIR "@PROTOBUF_INCLUDE_DIR@")
find_package(Protobuf REQUIRED)

# import targets
include ("${CMAKE_CURRENT_LIST_DIR}/ONNXTargets.cmake")

Expand Down