Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ if(EMSCRIPTEN AND KTX_FEATURE_JS)
)
set_target_properties( msc_basis_transcoder_js PROPERTIES OUTPUT_NAME "msc_basis_transcoder")

target_link_libraries(msc_basis_transcoder_js basisu_encoder)
target_link_libraries(msc_basis_transcoder_js basisu::basisu_encoder)

add_custom_command(
TARGET msc_basis_transcoder_js
Expand Down Expand Up @@ -459,14 +459,10 @@ add_subdirectory(interface/basisu_c_binding)
# except for building the ktx library.
if((KTX_FEATURE_TOOLS OR KTX_FEATURE_TESTS) AND NOT TARGET fmt::fmt)
# Always build fmt static
set(BUILD_SHARED_LIBS OFF)
set(FMT_INSTALL OFF)
set(FMT_SYSTEM_HEADERS ON)
add_subdirectory(external/fmt)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_RESET})
include("external/fmt.cmake")
endif()
if(KTX_FEATURE_TOOLS AND NOT TARGET cxxopts::cxxopts)
add_subdirectory(external/cxxopts)
include("external/cxxopts.cmake")
endif()

# Tools
Expand Down
8 changes: 7 additions & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ SPDX-FileCopyrightText = "2017 Sean Barrett"
SPDX-License-Identifier = "MIT"

[[annotations]]
path = "external/basisu/Source/tinyexr.h"
path = "tools/imageio/external/tinyexr.h"
precedence = "aggregate"
SPDX-FileCopyrightText = "2014-2019 Syoyo Fujita and many contributors"
SPDX-License-Identifier = "BSD-3-Clause"
Expand Down Expand Up @@ -274,3 +274,9 @@ path = ["vcpkg.json", "vcpkg-configuration.json"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2024 The Khronos Group Inc."
SPDX-License-Identifier = "Apache-2.0"

[[annotations]]
path = ["tools/imageio/external/jpgd.h", "tools/imageio/external/jpgd.cpp"]
precedence = "aggregate"
SPDX-FileCopyrightText = "1994-2020 Rich Geldreich <richgel99@gmail.com>"
SPDX-License-Identifier = "Apache-2.0"
128 changes: 128 additions & 0 deletions external/astcenc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Copyright 2025 Danylo Sivachenko (@Daniil-SV).
# SPDX-License-Identifier: Apache-2.0

####################################################
# ASTC Encoder
####################################################
include(FetchContent)
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/compiler_query_genexs.cmake)

if (TARGET astcenc::astcenc)
message(STATUS "(${PROJECT_NAME}): Using configured ASTC Encoder target")
return()
endif()

set(ASTC_VERSION 5.3.0)
message(STATUS "ASTC VERSION: ${ASTC_VERSION}")


# Determine most of the ASTC-related settings automatically.

# On Linux and Windows only one architecture is supported at once. On
# macOS simultaneous multiple architectures are supported by the ASTC
# encoder but not by the BasisU encoder. The latter supports only SSE
# SIMD that is enabled by compile time defines which makes it not amenable
# to a standard Xcode universal binary build. To ensure BASISU_SUPPORT_SSE
# is disabled when building for multiple architectures use only the
# value of CMAKE_OSX_ARCHITECTURES to decide if a universal build
# has been requested. Do not expose the astc-encoder's
# ASTCENC_UNIVERSAL_BUILD configuration option.
set(universal_build OFF)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
# Check CMAKE_OSX_ARCHITECTURES for multiple architectures.
list(FIND CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)" archs_standard)
list(LENGTH CMAKE_OSX_ARCHITECTURES architecture_count)
if(NOT ${archs_standard} EQUAL -1 OR architecture_count GREATER 1)
set(universal_build ON)
endif()
# Set ordinary variable to override astc-encoder option's ON default
# and hide the option.
set(ASTCENC_UNIVERSAL_BUILD ${universal_build})
endif()


# If we detect the user is doing a universal build defer to astc-encoder
# to pick the architectures. If a universal build has not been requested,
# present options to the user to turn off SIMD and, if running on x86_64
# to choose which SIMD ISA to use. On arm64 always use Neon. On unknown
# CPUs use None.
#
# On x86_64, if neither ASTCENC_ISA_SSE41 nor ASTCENC_ISA_SSE2 are defined,
# choose ASTCENC_ISA_AVX2. If ASTCENC_ISA_AVX2 fails to compile user must
# choose another x86_64 option.

if(NOT ${universal_build})
set(ASTCENC_ISA_NATIVE OFF)
set(ASTCENC_ISA_NEON OFF)
if(NOT CPU_ARCHITECTURE STREQUAL x86_64)
set(ASTCENC_ISA_AVX2 OFF)
set(ASTCENC_ISA_SSE41 OFF)
set(ASTCENC_ISA_SSE2 OFF)
endif()

# "" in the CACHE sets causes use of the existing documentation string.
if(${ASTCENC_ISA_NONE})
set(ASTCENC_LIB_TARGET astcenc-none-static)
if(CPU_ARCHITECTURE STREQUAL x86_64)
set(ASTCENC_ISA_AVX2 OFF CACHE BOOL "" FORCE)
set(ASTCENC_ISA_SSE41 OFF CACHE BOOL "" FORCE)
set(ASTCENC_ISA_SSE2 OFF CACHE BOOL "" FORCE)
endif()
else()
if(CPU_ARCHITECTURE STREQUAL x86_64)
if (${ASTCENC_ISA_SSE41})
set(ASTCENC_LIB_TARGET astcenc-sse4.1-static)
set(ASTCENC_ISA_AVX2 OFF CACHE BOOL "" FORCE)
set(ASTCENC_ISA_SSE2 OFF CACHE BOOL "" FORCE)
elseif (${ASTCENC_ISA_SSE2})
set(ASTCENC_LIB_TARGET astcenc-sse2-static)
set(ASTCENC_ISA_AVX2 OFF CACHE BOOL "" FORCE)
set(ASTCENC_ISA_SSE41 OFF CACHE BOOL "" FORCE)
else()
set(ASTCENC_LIB_TARGET astcenc-avx2-static)
set(ASTCENC_ISA_AVX2 ON CACHE BOOL "" FORCE)
set(ASTCENC_ISA_SSE41 OFF CACHE BOOL "" FORCE)
set(ASTCENC_ISA_SSE2 OFF CACHE BOOL "" FORCE)
endif()
elseif(CPU_ARCHITECTURE STREQUAL armv8 OR CPU_ARCHITECTURE STREQUAL arm64)
set(ASTCENC_LIB_TARGET astcenc-neon-static)
set(ASTCENC_ISA_NEON ON)
set(ASTCENC_ISA_NONE OFF CACHE BOOL "" FORCE)
else()
message(STATUS "Unsupported ISA for ASTC on ${CPU_ARCHITECTURE} arch, using ASTCENC_ISA_NONE.")
set(ASTCENC_ISA_NONE ON CACHE BOOL "" FORCE)
set(ASTCENC_LIB_TARGET astcenc-none-static)
endif()
endif()
endif()

# setting ASTCENC_DECOMPRESSOR to ON breaks the build, so force it to OFF
# and hide it from cmake-gui (by using type INTERNAL)
set(ASTCENC_DECOMPRESSOR OFF CACHE INTERNAL "")
set(ASTCENC_CLI OFF) # Only build as library not the CLI astcencoder
# Force static build for astc-encoder
set(BUILD_SHARED_LIBS OFF)

# Declare package
FetchContent_Declare(
astcenc
GIT_REPOSITORY https://github.com/ARM-software/astc-encoder
GIT_TAG ${ASTC_VERSION}
FIND_PACKAGE_ARGS
)

# Populate astc
FetchContent_MakeAvailable(astcenc)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_RESET})

if (NOT TARGET astcenc::astcenc)
set_property(TARGET ${ASTCENC_LIB_TARGET} PROPERTY POSITION_INDEPENDENT_CODE ON)

target_compile_definitions(
${ASTCENC_LIB_TARGET} PRIVATE
$<$<AND:${is_msvccl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.40.33811>>:_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR>
$<$<AND:${is_clangcl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,17.0.3>>:_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR>
)

add_library(astcenc::astcenc ALIAS ${ASTCENC_LIB_TARGET})
endif()
78 changes: 78 additions & 0 deletions external/basisu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2025 Danylo Sivachenko (@Daniil-SV).
# SPDX-License-Identifier: Apache-2.0

####################################################
# Basis Universal Encoder
####################################################
include(FetchContent)

if (TARGET basisu::basisu_encoder)
message(STATUS "(${PROJECT_NAME}): Using configured Basis Universal Encoder target")
return()
endif()

# TODO: Restore after new basisu release
#set(BASISU_VERSION 1_60)
#message(STATUS "Basisu VERSION: ${BASISU_VERSION}")

# Options
set(BASISU_TOOL FALSE)
set(BASISU_EXAMPLES FALSE)
if(NOT ${CPU_ARCHITECTURE} STREQUAL "x86_64")
# Basisu sets this TRUE if MSVC is TRUE.
set(BASISU_SSE FALSE)
endif()

# Declare package
FetchContent_Declare(
basisu
GIT_REPOSITORY https://github.com/Daniil-SV/basis_universal.git
GIT_TAG cmake_fixes #"v${BASISU_VERSION}"
FIND_PACKAGE_ARGS
)

# Populate basisu
FetchContent_MakeAvailable(basisu)

if (NOT TARGET basisu::basisu_encoder)
add_library(basisu::basisu_encoder ALIAS basisu_encoder)

# In some package managers, like vcpkg, all headers are stored in "basisu" subdirectory,
# while in the official repository they are stored in the root folder, which creates some conflicts.
# Objectively, headers in a subdirectory look safer and better.
# So the solution is to copy the headers to the subdirectory by hands, if necessary.

# Temporary folder with our headers
set(BASISU_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include/basisu)

# Folders with headers in repo root
set(BASISU_SUBDIRS encoder transcoder)
foreach(subdir ${BASISU_SUBDIRS})
# Collecting just headers paths
file(GLOB_RECURSE headers
RELATIVE ${basisu_SOURCE_DIR}/${subdir}
${basisu_SOURCE_DIR}/${subdir}/*.h
${basisu_SOURCE_DIR}/${subdir}/*.inc
)

# Iterating over collected files
foreach(filename ${headers})
get_filename_component(directory ${filename} DIRECTORY)

# Ensure destination directory exists
file(
MAKE_DIRECTORY
${BASISU_INCLUDE_DIR} ${BASISU_INCLUDE_DIR}/${subdir}/${directory}
)

# And finally copy to temporary folder
file(COPY ${basisu_SOURCE_DIR}/${subdir}/${filename}
DESTINATION ${BASISU_INCLUDE_DIR}/${subdir}/${directory})
endforeach()
endforeach()

# Add temporary include path to target
target_include_directories(basisu_encoder PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
)
endif()
32 changes: 32 additions & 0 deletions external/cxxopts.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2025 Danylo Sivachenko (@Daniil-SV).
# SPDX-License-Identifier: Apache-2.0

####################################################
# cxxopts
####################################################
include(FetchContent)

if (TARGET cxxopts::cxxopts)
message(STATUS "(${PROJECT_NAME}): Using configured cxxopts target")
return()
endif()

set(CXXOPTS_VERSION 3.3.1)
message(STATUS "CXXOPTS VERSION: ${CXXOPTS_VERSION}")

# Options
# Always build fmt static
set(BUILD_SHARED_LIBS OFF)
set(FMT_INSTALL OFF)
set(FMT_SYSTEM_HEADERS ON)

# Declare package
FetchContent_Declare(
cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG "v${CXXOPTS_VERSION}"
FIND_PACKAGE_ARGS
)

# Populate fmt
FetchContent_MakeAvailable(cxxopts)
32 changes: 32 additions & 0 deletions external/fmt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2025 Danylo Sivachenko (@Daniil-SV).
# SPDX-License-Identifier: Apache-2.0

####################################################
# fmt
####################################################
include(FetchContent)

if (TARGET fmt::fmt)
message(STATUS "(${PROJECT_NAME}): Using configured fmt target")
return()
endif()

set(FMT_VERSION 11.2.0)
message(STATUS "FMT VERSION: ${FMT_VERSION}")

# Options
# Always build fmt static
set(BUILD_SHARED_LIBS OFF)
set(FMT_INSTALL OFF)
set(FMT_SYSTEM_HEADERS ON)

# Declare package
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG ${FMT_VERSION}
FIND_PACKAGE_ARGS
)

# Populate fmt
FetchContent_MakeAvailable(fmt)
33 changes: 33 additions & 0 deletions external/lodepng.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2025 Danylo Sivachenko (@Daniil-SV).
# SPDX-License-Identifier: Apache-2.0

####################################################
# lodepng
####################################################
include(FetchContent)

if (TARGET lodepng::lodepng)
message(STATUS "(${PROJECT_NAME}): Using configured lodepng target")
return()
endif()

# Declare package
FetchContent_Declare(
lodepng
GIT_REPOSITORY https://github.com/KhronosGroup/lodepng.git
GIT_TAG d4cc52d8c074da137303e1117cc098a97647960c
)

# Populate lodepng
FetchContent_MakeAvailable(lodepng)

add_library(
lodepng STATIC
${lodepng_SOURCE_DIR}/lodepng.cpp
${lodepng_SOURCE_DIR}/lodepng.h
)
add_library(lodepng::lodepng ALIAS lodepng)
target_include_directories(
lodepng PUBLIC
${lodepng_SOURCE_DIR}
)
Loading