0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-26 06:41:03 +08:00

cmake: Export targets to package config

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
This commit is contained in:
Stefan Herbrechtsmeier 2017-04-04 10:34:28 +02:00
parent 4e3e3f659d
commit f186421273
2 changed files with 33 additions and 16 deletions

View File

@ -777,6 +777,15 @@ else ()
PREFIX "")
endif ()
foreach (target libzmq libzmq-static)
target_include_directories (${target}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
endforeach()
target_link_libraries (libzmq ${CMAKE_THREAD_LIBS_INIT})
if (SODIUM_FOUND)
@ -856,6 +865,7 @@ include(GNUInstallDirs)
if (MSVC)
install (TARGETS libzmq libzmq-static
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
@ -878,6 +888,7 @@ if (MSVC)
endif ()
else ()
install (TARGETS libzmq libzmq-static
EXPORT ${PROJECT_NAME}-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@ -911,26 +922,22 @@ endif ()
include(CMakePackageConfigHelpers)
if (MSVC)
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
get_property(libzmq_pf TARGET libzmq PROPERTY ${U_CMAKE_BUILD_TYPE}_POSTFIX)
set(libzmq_file libzmq${libzmq_pf}${CMAKE_LINK_LIBRARY_SUFFIX})
get_property(libzmq_static_pf TARGET libzmq-static PROPERTY ${U_CMAKE_BUILD_TYPE}_POSTFIX)
set(libzmq_static_file libzmq${libzmq_static_pf}${CMAKE_LINK_LIBRARY_SUFFIX})
else()
set(libzmq_file libzmq${CMAKE_SHARED_LIBRARY_SUFFIX})
set(libzmq_static_file libzmq${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
set(ZEROMQ_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for ZeroMQConfig.cmake")
if (NOT CMAKE_VERSION VERSION_LESS 3.0)
export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
endif()
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${ZEROMQ_CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}
COMPATIBILITY AnyNewerVersion)
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${ZEROMQ_CMAKECONFIG_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${ZEROMQ_CMAKECONFIG_INSTALL_DIR})

View File

@ -1,4 +1,12 @@
# ZeroMQ cmake module
#
# The following import targets are created
#
# ::
#
# libzmq-static
# libzmq
#
# This module sets the following variables in your project::
#
# ZeroMQ_FOUND - true if ZeroMQ found on the system
@ -8,8 +16,10 @@
@PACKAGE_INIT@
set(PN ZeroMQ)
set_and_check(${PN}_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(${PN}_LIBRARY "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@/@libzmq_file@")
set_and_check(${PN}_STATIC_LIBRARY "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@/@libzmq_static_file@")
check_required_components(${PN})
if(NOT TARGET libzmq AND NOT TARGET libzmq-static)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
endif()
get_target_property(@PROJECT_NAME@_INCLUDE_DIR libzmq INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(@PROJECT_NAME@_LIBRARY libzmq LOCATION)
get_target_property(@PROJECT_NAME@_STATIC_LIBRARY libzmq-static LOCATION)