1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
- $<INSTALL_INTERFACE:.>)
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+
+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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
- $<INSTALL_INTERFACE:.>)
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
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()
|