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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build/
# VS project and working files
*.vcxproj.user
.vs/
.vscode/
Debug/
Release/
x64/
Expand Down
52 changes: 43 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(BASISU_STATIC "static linking" FALSE)
option(BASISU_STATIC "Link runtime libraries statically" FALSE)
option(BASISU_SHARED "Build basis-universal as a shared library" FALSE)
option(BASISU_SAN "sanitize" FALSE)
option(BASISU_EXAMPLES "build examples" TRUE)
option(BASISU_WASM_THREADING "Enable WASI threading support" OFF)
Expand Down Expand Up @@ -84,9 +85,18 @@ if (BASISU_BUILD_WASM)

# WASM cannot use sanitizers
set(BASISU_SAN OFF CACHE BOOL "" FORCE)

# WASM cannot link as a shared object
set(BASISU_SHARED OFF CACHE BOOL "" FORCE)
endif()

if (BASISU_BUILD_PYTHON)
# Dynamic linking is not supported on Python builds
set(BASISU_SHARED OFF CACHE BOOL "" FORCE)
endif()

message("Initial CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
message("Initial BASISU_SHARED=${BASISU_SHARED}")
message("Initial BASISU_BUILD_X64=${BASISU_BUILD_X64}")
message("Initial BASISU_BUILD_WASM=${BASISU_BUILD_WASM}")
message("Initial BASISU_WASM_THREADING=${BASISU_WASM_THREADING}")
Expand Down Expand Up @@ -248,6 +258,8 @@ set(ENCODER_LIB_SRC_LIST
encoder/basisu_astc_ldr_common.cpp
encoder/basisu_astc_ldr_encode.cpp
encoder/basisu_tinyexr.cpp
encoder/basisu_wasm_api.cpp
encoder/basisu_wasm_transcoder_api.cpp
transcoder/basisu_transcoder.cpp
encoder/basisu_astc_hdr_6x6_enc.h
encoder/basisu_astc_hdr_common.h
Expand Down Expand Up @@ -305,19 +317,42 @@ if (BASISU_ZSTD)
set(ENCODER_LIB_SRC_LIST ${ENCODER_LIB_SRC_LIST} zstd/zstd.c)
endif()

# Create the static library
add_library(basisu_encoder STATIC ${ENCODER_LIB_SRC_LIST})
# Create the library

if (BASISU_SHARED)
add_library(basisu_encoder SHARED ${ENCODER_LIB_SRC_LIST})

set_target_properties(basisu_encoder PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
VERSION 2.10
SOVERSION 2
)

if (MSVC)
set_target_properties(basisu_encoder PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
endif()

target_compile_definitions(basisu_encoder PUBLIC BASISU_SHARED)
else()
add_library(basisu_encoder STATIC ${ENCODER_LIB_SRC_LIST})
endif()

# Create the basisu executable and link against the static library
# Create the basisu executable and link against the library
add_executable(basisu basisu_tool.cpp)
target_link_libraries(basisu PRIVATE basisu_encoder)

# Create the new example executable and link against the static library
# Create the new example executable and link against the library
if(BASISU_EXAMPLES)
add_executable(example example/example.cpp)
target_link_libraries(example PRIVATE basisu_encoder)

add_executable(example_capi example_capi/example_capi.c encoder/basisu_wasm_api.cpp encoder/basisu_wasm_transcoder_api.cpp)
add_executable(example_capi example_capi/example_capi.c)
target_link_libraries(example_capi PRIVATE basisu_encoder)

add_executable(example_transcoding example_transcoding/example_transcoding.cpp example_transcoding/utils.cpp zstd/zstddeclib.c transcoder/basisu_transcoder.cpp)
Expand Down Expand Up @@ -355,7 +390,7 @@ if (BASISU_BUILD_WASM)

endif()

# 256 MB initial, 3.5 GB max safe defaults for BasisU
# 256 MB initial, 3.5 GB max — safe defaults for BasisU
target_link_options(basisu PRIVATE
-Wl,--initial-memory=268435456
-Wl,--max-memory=3758096384
Expand Down Expand Up @@ -592,7 +627,6 @@ if (BASISU_BUILD_WASM)
endif()

add_executable(${BASISU_TRANSCODER_WASM_OUTPUT_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/encoder/basisu_wasm_transcoder_api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/transcoder/basisu_transcoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/zstd/zstddeclib.c)

Expand Down Expand Up @@ -655,7 +689,7 @@ if (BASISU_BUILD_PYTHON AND NOT BASISU_BUILD_WASM)

pybind11_add_module(basisu_transcoder_python
python/basisu_transcoder_pybind11.cpp
encoder/basisu_wasm_transcoder_api.cpp
encoder/basisu_wasm_transcoder_api.cpp
transcoder/basisu_transcoder.cpp
zstd/zstddeclib.c
)
Expand Down
5 changes: 3 additions & 2 deletions encoder/basisu_wasm_api_common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// File: basisu_wasm_api_common.h
#pragma once
#include "stdint.h"
#include "../transcoder/basisu_config.h"

#if defined(__wasm__)
#if defined(__cplusplus)
Expand All @@ -9,9 +10,9 @@
#define BU_WASM_EXPORT(name) __attribute__((export_name(name)))
#endif
#elif defined(__cplusplus)
#define BU_WASM_EXPORT(name) extern "C"
#define BU_WASM_EXPORT(name) extern "C" BASISU_API
#else
#define BU_WASM_EXPORT(name)
#define BU_WASM_EXPORT(name) BASISU_API
#endif

// wasm_bool_t is an alias for uint32_t
Expand Down
17 changes: 17 additions & 0 deletions transcoder/basisu_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#ifndef BASISU_SHARED
#define BASISU_API
#elif defined(_WIN32)
#ifdef basisu_encoder_EXPORTS
#define BASISU_API __declspec(dllexport)
#else
#define BASISU_API __declspec(dllimport)
#endif
#else
#ifdef basisu_encoder_EXPORTS
#define BASISU_API __attribute__((visibility("default")))
#else
#define BASISU_API
#endif
#endif