diff --git a/src/libunicode/CMakeLists.txt b/src/libunicode/CMakeLists.txt index 98d598c..2969f7e 100644 --- a/src/libunicode/CMakeLists.txt +++ b/src/libunicode/CMakeLists.txt @@ -129,8 +129,9 @@ set_target_properties(unicode PROPERTIES ) add_library(unicode::core ALIAS unicode) -target_include_directories(unicode PUBLIC $ - $) +target_include_directories(unicode PUBLIC $ + $ +) target_link_libraries(unicode PUBLIC unicode::ucd) add_executable(unicode_tablegen tablegen.cpp) @@ -140,17 +141,14 @@ target_link_libraries(unicode_tablegen PRIVATE unicode::loader) set(LIBUNICODE_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/libunicode" CACHE PATH "Installation directory for cmake files, a relative path that will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute path.") set(LIBUNICODE_INSTALL_CMAKE_FILES ${MASTER_PROJECT} CACHE BOOL "Decides whether or not to install CMake config and -version files.") -set(INSTALL_TARGETS unicode_ucd unicode_loader unicode) -set(TARGETS_EXPORT_NAME unicode-targets) - # Create and install package configuration and version files. # Install library and headers. -install(TARGETS ${INSTALL_TARGETS} - EXPORT ${TARGETS_EXPORT_NAME} +install(TARGETS unicode_ucd unicode_loader unicode + EXPORT unicode-targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include/libunicode" - PRIVATE_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include/libunicode" + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libunicode" + PRIVATE_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libunicode" FRAMEWORK DESTINATION "." RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -162,21 +160,32 @@ install( ucd_ostream.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libunicode" ) +# }}} +# {{{ Generate the version, config and target files if(LIBUNICODE_INSTALL_CMAKE_FILES) - set(version "${CMAKE_PROJECT_VERSION}") - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libunicode-config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/libunicode-config.cmake @ONLY) + # Install version, config and target files. + include(CMakePackageConfigHelpers) + + write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/libunicode-config-version.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion + ) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libunicode-config-version.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/libunicode-config-version.cmake @ONLY) + configure_package_config_file(libunicode-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libunicode-config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libunicode + ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libunicode-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/libunicode-config-version.cmake - DESTINATION ${LIBUNICODE_CMAKE_DIR}) + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libunicode + ) - # Install version, config and target files. - install(EXPORT ${TARGETS_EXPORT_NAME} DESTINATION ${LIBUNICODE_CMAKE_DIR} NAMESPACE unicode::) + install(EXPORT unicode-targets + DESTINATION ${LIBUNICODE_CMAKE_DIR} + NAMESPACE unicode:: + ) endif() # }}} diff --git a/src/libunicode/libunicode-config-version.cmake.in b/src/libunicode/libunicode-config-version.cmake.in deleted file mode 100644 index 21f50f2..0000000 --- a/src/libunicode/libunicode-config-version.cmake.in +++ /dev/null @@ -1,7 +0,0 @@ -set(PACKAGE_VERSION "@version@") -if(NOT "${PACKAGE_FIND_VERSION}" VERSION_GREATER "@version@") - set(PACKAGE_VERSION_COMPATIBLE 1) # compatible with older - if("${PACKAGE_FIND_VERSION}" VERSION_EQUAL "@version@") - set(PACKAGE_VERSION_EXACT 1) # exact match for this version - endif() -endif() diff --git a/src/libunicode/libunicode-config.cmake.in b/src/libunicode/libunicode-config.cmake.in index 4517db0..b025b9a 100644 --- a/src/libunicode/libunicode-config.cmake.in +++ b/src/libunicode/libunicode-config.cmake.in @@ -1,10 +1,8 @@ -# Compute installation prefix relative to this file. -get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) -get_filename_component(_prefix "${_dir}/../../.." ABSOLUTE) +@PACKAGE_INIT@ -# Import the targets. -include("${_dir}/@TARGETS_EXPORT_NAME@.cmake") +# prevent repeatedly including the targets +if(NOT TARGET unicode::core) + include(${CMAKE_CURRENT_LIST_DIR}/libunicode-targets.cmake) +endif() -# Report other information. -set(libunicode_INCLUDE_DIRS "${_prefix}/include") -set(libunicode_FOUND TRUE) +message(STATUS "Found @PROJECT_NAME@, version: ${@PROJECT_NAME@_VERSION}")