From: =?utf-8?q?Timo_R=C3=B6hling?= Date: Wed, 27 Jul 2022 00:52:18 +0200 Subject: Export library with proper CMake config Forwarded: not-needed --- CMakeLists.txt | 19 +++++++++++++++++++ Source/UnitTest/cmake_core.cmake | 2 +- Source/astcenc.h | 2 +- Source/cmake_core.cmake | 23 +++++++++++++++++++---- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a471af5..673cf04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,8 @@ endif() project(astcencoder VERSION 5.3.0) +include(GNUInstallDirs) + set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -153,6 +155,23 @@ printopt("Unit tests " ${ASTCENC_UNITTEST}) # Subcomponents add_subdirectory(Source) +include(CMakePackageConfigHelpers) +configure_package_config_file(debian/extra/config.cmake.in astcencConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/astcenc + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) +write_basic_package_version_file(astcencConfigVersion.cmake + VERSION ${ASTCENC_VERSION} + COMPATIBILITY SameMinorVersion +) +install(FILES Source/astcenc.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(EXPORT astcencTargets NAMESPACE astcenc:: DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/astcenc) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/astcencConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/astcencConfigVersion.cmake DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/astcenc) + # Configure package archive if(ASTCENC_PACKAGE) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") diff --git a/Source/UnitTest/cmake_core.cmake b/Source/UnitTest/cmake_core.cmake index a467354..52c617f 100644 --- a/Source/UnitTest/cmake_core.cmake +++ b/Source/UnitTest/cmake_core.cmake @@ -51,7 +51,7 @@ target_include_directories(${ASTCENC_TEST} target_link_libraries(${ASTCENC_TEST} PRIVATE - astcenc-${ASTCENC_ISA_SIMD}-static) + astcenc-static) target_compile_options(${ASTCENC_TEST} PRIVATE diff --git a/Source/astcenc.h b/Source/astcenc.h index 8ecdc16..af508c4 100644 --- a/Source/astcenc.h +++ b/Source/astcenc.h @@ -177,7 +177,7 @@ #define ASTCENC_PUBLIC extern "C" __attribute__ ((visibility ("default"))) #endif #else - #define ASTCENC_PUBLIC + #define ASTCENC_PUBLIC extern "C" #endif /* ============================================================================ diff --git a/Source/cmake_core.cmake b/Source/cmake_core.cmake index a9196b1..ae4e052 100644 --- a/Source/cmake_core.cmake +++ b/Source/cmake_core.cmake @@ -15,7 +15,7 @@ # under the License. # ---------------------------------------------------------------------------- -set(ASTCENC_TARGET astc${ASTCENC_CODEC}-${ASTCENC_ISA_SIMD}) +set(ASTCENC_TARGET astc${ASTCENC_CODEC}) project(${ASTCENC_TARGET}) @@ -49,7 +49,9 @@ add_library(${ASTCENC_TARGET}-static target_include_directories(${ASTCENC_TARGET}-static PUBLIC $ - $) + $) + +install(TARGETS ${ASTCENC_TARGET}-static EXPORT astcencTargets) if(${ASTCENC_SHAREDLIB}) add_library(${ASTCENC_TARGET}-shared @@ -80,7 +82,7 @@ if(${ASTCENC_SHAREDLIB}) target_include_directories(${ASTCENC_TARGET}-shared PUBLIC $ - $) + $) endif() if(${ASTCENC_CLI}) @@ -477,6 +479,12 @@ target_compile_options(${ASTCENC_TARGET}-static PRIVATE $<${is_msvc_fe}:/W4>) +set_target_properties(${ASTCENC_TARGET}-static + PROPERTIES + OUTPUT_NAME ${ASTCENC_TARGET} + VERSION ${ASTCENC_VERSION} +) + if(${ASTCENC_SHAREDLIB}) astcenc_set_properties(${ASTCENC_TARGET}-shared OFF) @@ -489,8 +497,15 @@ if(${ASTCENC_SHAREDLIB}) $<${is_gnu_fe}:-fvisibility=hidden> $<${is_msvc_fe}:/W4>) + set_target_properties(${ASTCENC_TARGET}-shared + PROPERTIES + OUTPUT_NAME ${ASTCENC_TARGET} + VERSION ${ASTCENC_VERSION} + SOVERSION ${ASTCENC_SOVERSION} + ) + if(NOT ${ASTCENC_UNIVERSAL_BUILD}) - install(TARGETS ${ASTCENC_TARGET}-shared) + install(TARGETS ${ASTCENC_TARGET}-shared EXPORT astcencTargets) endif() endif()