vcpkg/ports/ktx/0001-Use-vcpkg-zstd.patch
Sergei Kachkov b24cd526fc
[ktx] Static build fix (#29756)
* [ktx] Fix missing zstd dependency

* [ktx] Fix GNU libtool issue for static build with enabled 'tools' feature

* [ktx] Update port version
2023-02-23 12:25:09 -08:00

123 lines
4.2 KiB
Diff

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bc679fd1..c726fa71 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -185,7 +185,6 @@ set(KTX_MAIN_SRC
lib/basisu/transcoder/basisu_transcoder.cpp
lib/basisu/transcoder/basisu_transcoder.h
lib/basisu/transcoder/basisu.h
- lib/basisu/zstd/zstd.c
lib/checkheader.c
lib/dfdutils/createdfd.c
lib/dfdutils/colourspaces.c
@@ -304,7 +303,6 @@ macro(commom_lib_settings lib write)
$<INSTALL_INTERFACE:lib/basisu/transcoder>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/basisu/zstd>
- $<INSTALL_INTERFACE:lib/basisu/zstd>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/other_include>
$<INSTALL_INTERFACE:other_include>
@@ -390,6 +388,10 @@ macro(commom_lib_settings lib write)
target_compile_definitions(${lib} PUBLIC KTX_FEATURE_KTX2)
endif()
+ # Use vcpkg zstd
+ find_package(zstd CONFIG REQUIRED)
+ target_link_libraries(${lib} PRIVATE $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
+
if(WIN32)
# By wrapping in generator expression we force multi configuration
# generators (like Visual Studio) to take the exact path and not
diff --git a/cmake/KtxConfig.cmake b/cmake/KtxConfig.cmake
index 6386ba2f..537bf4f2 100644
--- a/cmake/KtxConfig.cmake
+++ b/cmake/KtxConfig.cmake
@@ -1,7 +1,8 @@
# Copyright 2015-2020 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0
-# include(CMakeFindDependencyMacro)
-# find_dependency()
+include(CMakeFindDependencyMacro)
+find_dependency(Threads)
+find_dependency(zstd CONFIG)
include("${CMAKE_CURRENT_LIST_DIR}/KtxTargets.cmake")
diff --git a/lib/basisu/CMakeLists.txt b/lib/basisu/CMakeLists.txt
index 492233ae..8786d16c 100644
--- a/lib/basisu/CMakeLists.txt
+++ b/lib/basisu/CMakeLists.txt
@@ -146,7 +146,7 @@ set(BASISU_SRC_LIST ${COMMON_SRC_LIST}
)
if (ZSTD)
- set(BASISU_SRC_LIST ${BASISU_SRC_LIST} zstd/zstd.c)
+ set(ZSTD_LIBRARIES "$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>")
endif()
if (APPLE)
@@ -165,6 +165,10 @@ else()
target_compile_definitions(basisu PRIVATE BASISD_SUPPORT_KTX2_ZSTD=0)
endif()
+if(ZSTD_LIBRARIES)
+ target_link_libraries(basisu ${ZSTD_LIBRARIES})
+endif()
+
if (NOT MSVC)
# For Non-Windows builds, let cmake try and find the system OpenCL headers/libs for us.
if (OPENCL_FOUND)
diff --git a/lib/basisu/webgl/encoder/CMakeLists.txt b/lib/basisu/webgl/encoder/CMakeLists.txt
index 588d91b4..0b380129 100644
--- a/lib/basisu/webgl/encoder/CMakeLists.txt
+++ b/lib/basisu/webgl/encoder/CMakeLists.txt
@@ -34,9 +34,7 @@ if (EMSCRIPTEN)
)
if (KTX2_ZSTANDARD)
- set(SRC_LIST ${SRC_LIST}
- ../../zstd/zstd.c
- )
+ set(ZSTD_LIBRARIES "$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>")
set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=1)
else()
set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=0)
@@ -56,6 +54,10 @@ if (EMSCRIPTEN)
target_include_directories(basis_encoder.js PRIVATE ../../transcoder)
+ if(ZSTD_LIBRARIES)
+ target_link_libraries(basis_encoder.js ${ZSTD_LIBRARIES})
+ endif()
+
set_target_properties(basis_encoder.js PROPERTIES
OUTPUT_NAME "basis_encoder"
SUFFIX ".js"
diff --git a/lib/basisu/webgl/transcoder/CMakeLists.txt b/lib/basisu/webgl/transcoder/CMakeLists.txt
index 372653de..f75e3a35 100644
--- a/lib/basisu/webgl/transcoder/CMakeLists.txt
+++ b/lib/basisu/webgl/transcoder/CMakeLists.txt
@@ -28,9 +28,7 @@ if (EMSCRIPTEN)
endif()
if (KTX2_ZSTANDARD)
- set(SRC_LIST ${SRC_LIST}
- ../../zstd/zstddeclib.c
- )
+ set(ZSTD_LIBRARIES "$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>")
set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=1)
else()
set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=0)
@@ -45,6 +43,10 @@ if (EMSCRIPTEN)
target_compile_options(basis_transcoder.js PRIVATE -O3 -fno-strict-aliasing)
target_include_directories(basis_transcoder.js PRIVATE ../../transcoder)
+ if(ZSTD_LIBRARIES)
+ target_link_libraries(basis_transcoder.js ${ZSTD_LIBRARIES})
+ endif()
+
set_target_properties(basis_transcoder.js PROPERTIES
OUTPUT_NAME "basis_transcoder"
SUFFIX ".js"