diff --git a/recipes/libbasisu/all/CMakeLists.txt b/recipes/libbasisu/all/CMakeLists.txt new file mode 100644 index 0000000000000..bd4164cb5c1c7 --- /dev/null +++ b/recipes/libbasisu/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.10) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory("source_subfolder") diff --git a/recipes/libbasisu/all/conandata.yml b/recipes/libbasisu/all/conandata.yml new file mode 100644 index 0000000000000..7cca98d66479b --- /dev/null +++ b/recipes/libbasisu/all/conandata.yml @@ -0,0 +1,8 @@ +sources: + "1.15.0": + url: "https://github.com/BinomialLLC/basis_universal/archive/refs/tags/v1_15.tar.gz" + sha256: "1f8de889beb2b8d899320693b651a6b8b62a954a9b86962aaa41007ee2dbe02b" +patches: + "1.15.0": + - patch_file: "patches/cmakelist_build_lib.patch" + base_path: "source_subfolder" diff --git a/recipes/libbasisu/all/conanfile.py b/recipes/libbasisu/all/conanfile.py new file mode 100644 index 0000000000000..08181b07ffec1 --- /dev/null +++ b/recipes/libbasisu/all/conanfile.py @@ -0,0 +1,106 @@ +import os +from conans import ConanFile, CMake, tools +from conans.errors import ConanInvalidConfiguration + +required_conan_version = ">=1.33.0" + + +class LibBasisUniversalConan(ConanFile): + name = "libbasisu" + description = "Basis Universal Supercompressed GPU Texture Codec" + homepage = "https://github.com/BinomialLLC/basis_universal" + topics = ("conan", "basis", "textures", "compression") + url = "https://github.com/conan-io/conan-center-index" + license = "Apache-2.0" + exports_sources = ["CMakeLists.txt", "patches/*"] + generators = "cmake" + settings = "os", "compiler", "build_type", "arch" + options = { + "fPIC": [True, False], + "shared": [True, False], + "use_sse4": [True, False], + "with_zstd": [True, False], + "custom_iterator_debug_level": [True, False] + } + default_options = { + "fPIC": True, + "shared": False, + "use_sse4": True, + "with_zstd": True, + "custom_iterator_debug_level": False + } + + _cmake = None + + @property + def _source_subfolder(self): + return "source_subfolder" + + @property + def _build_subfolder(self): + return "build_subfolder" + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + if self.settings.compiler != "Visual Studio": + del self.options.custom_iterator_debug_level + + def _minimum_compiler_version(self) -> bool: + return { + "Visual Studio": "15", + "gcc": "5.4", + "clang": "3.9", + "apple-clang": "10" + } + + def validate(self): + min_version = self._minimum_compiler_version().get(str(self.settings.compiler)) + if not min_version: + self.output.warn("{} recipe lacks information about the {} compiler support.".format( + self.name, self.settings.compiler)) + elif tools.Version(self.settings.compiler.version) < min_version: + raise ConanInvalidConfiguration("{} {} does not support compiler with version {} {}, minimum supported compiler version is {} ".format(self.name, self.version, self.settings.compiler, self.settings.compiler.version, min_version)) + if self.settings.compiler.get_safe("cppstd"): + tools.check_min_cppstd(self, 11) + + def configure(self): + if self.options.shared: + del self.options.fPIC + + def source(self): + tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder) + + def _configure_cmake(self): + if self._cmake: + return self._cmake + self._cmake = CMake(self) + self._cmake.definitions["SSE4"] = self.options.use_sse4 + self._cmake.definitions["ZSTD"] = self.options.with_zstd + self._cmake.definitions["BASISU_NO_ITERATOR_DEBUG_LEVEL"] = not self.options.get_safe("custom_iterator_debug_level", default=self.default_options["custom_iterator_debug_level"]) + self._cmake.configure(build_folder=self._build_subfolder) + return self._cmake + + def build(self): + for patch in self.conan_data.get("patches", {}).get(self.version, []): + tools.patch(**patch) + cmake = self._configure_cmake() + cmake.build() + + def package(self): + self.copy("LICENSE", dst="licenses", src=self._source_subfolder) + self.copy("*.h", dst=os.path.join("include", self.name, "transcoder"), src=os.path.join(self._source_subfolder, "transcoder")) + self.copy("*.h", dst=os.path.join("include", self.name, "encoder"), src=os.path.join(self._source_subfolder, "encoder")) + self.copy(pattern="*.a", dst="lib", keep_path=False) + self.copy(pattern="*.so", dst="lib", keep_path=False) + self.copy(pattern="*.dylib*", dst="lib", keep_path=False) + self.copy(pattern="*.lib", dst="lib", keep_path=False) + self.copy(pattern="*.dll", dst="bin", keep_path=False) + + def package_info(self): + self.cpp_info.libs = tools.collect_libs(self) + self.cpp_info.names["cmake_find_package"] = self.name + self.cpp_info.names["cmake_find_package_multi"] = self.name + self.cpp_info.includedirs = ["include", os.path.join("include", self.name)] + if self.settings.os == "Linux": + self.cpp_info.system_libs = ["m", "pthread"] diff --git a/recipes/libbasisu/all/patches/cmakelist_build_lib.patch b/recipes/libbasisu/all/patches/cmakelist_build_lib.patch new file mode 100644 index 0000000000000..6c3b3c2ecc2d7 --- /dev/null +++ b/recipes/libbasisu/all/patches/cmakelist_build_lib.patch @@ -0,0 +1,161 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,14 +1,14 @@ +-project(basisu) +- + cmake_minimum_required(VERSION 3.0) +-option(BUILD_X64 "build 64-bit" TRUE) +-option(STATIC "static linking" FALSE) +-option(SSE "SSE 4.1 support" FALSE) ++ ++project(libbasisu VERSION 1.15.0 LANGUAGES CXX) ++ ++option(SSE4 "SSE4 4.1 support" FALSE) + option(ZSTD "ZSTD support for KTX2 transcoding/encoding" TRUE) ++option(BASISU_NO_ITERATOR_DEBUG_LEVEL "Change Iterator debug level" FALSE) ++option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF) + +-message("Initial BUILD_X64=${BUILD_X64}") + message("Initial CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") +-message("Initial SSE=${SSE}") ++message("Initial SSE4=${SSE4}") + message("Initial ZSTD=${ZSTD}") + + if( NOT CMAKE_BUILD_TYPE ) +@@ -17,16 +17,10 @@ endif() + + message( ${PROJECT_NAME} " build type: " ${CMAKE_BUILD_TYPE} ) + +-if (BUILD_X64) +- message("Building 64-bit") ++if (SSE4) ++ message("SSE4.1 enabled") + else() +- message("Building 32-bit") +-endif() +- +-if (SSE) +- message("SSE enabled") +-else() +- message("SSE disabled") ++ message("SSE4.1 disabled") + endif() + + if (ZSTD) +@@ -42,38 +36,24 @@ if (NOT MSVC) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + +- set(CMAKE_CXX_FLAGS -std=c++11) +- set(GCC_COMPILE_FLAGS "-fvisibility=hidden -fPIC -fno-strict-aliasing -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Wno-unused-local-typedefs -Wno-unused-value -Wno-unused-parameter -Wno-unused-variable") +- +- if (NOT BUILD_X64) +- set(GCC_COMPILE_FLAGS "${GCC_COMPILE_FLAGS} -m32") +- endif() +- +- if (EMSCRIPTEN) +- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -DBASISU_SUPPORT_SSE=0") +- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -DBASISU_SUPPORT_SSE=0") ++ set(GCC_COMPILE_FLAGS "-fPIC -fno-strict-aliasing -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Wno-unused-local-typedefs -Wno-unused-value -Wno-unused-parameter -Wno-unused-variable") + +- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS}") +- elseif (STATIC) +- if (SSE) ++ if (NOT BUILD_SHARED_LIBS) ++ if (SSE4) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=1 -msse4.1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=1 -msse4.1") + else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=0") +- endif() +- +- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -static-libgcc -static-libstdc++ -static") ++ endif() + else() +- if (SSE) ++ if (SSE4) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=1 -msse4.1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=1 -msse4.1") + else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=0") +- endif() +- +- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -Wl,-rpath .") ++ endif() + endif() + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COMPILE_FLAGS}") +@@ -84,7 +64,7 @@ if (NOT MSVC) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${GCC_COMPILE_FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${GCC_COMPILE_FLAGS} -D_DEBUG") + else() +- if (SSE) ++ if (SSE4) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=1") + else() +@@ -94,7 +74,6 @@ else() + endif() + + set(BASISU_SRC_LIST ${COMMON_SRC_LIST} +- basisu_tool.cpp + encoder/basisu_backend.cpp + encoder/basisu_basis_file.cpp + encoder/basisu_comp.cpp +@@ -115,42 +94,27 @@ set(BASISU_SRC_LIST ${COMMON_SRC_LIST} + encoder/jpgd.cpp + encoder/basisu_kernels_sse.cpp + transcoder/basisu_transcoder.cpp +- ) ++) + + if (ZSTD) + set(BASISU_SRC_LIST ${BASISU_SRC_LIST} zstd/zstd.c) + endif() + +-if (APPLE) +- set(BIN_DIRECTORY "bin_osx") +-else() +- set(BIN_DIRECTORY "bin") +-endif() +- +-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${BIN_DIRECTORY}) +- +-add_executable(basisu ${BASISU_SRC_LIST}) ++add_library(${PROJECT_NAME} ${BASISU_SRC_LIST}) + + if (ZSTD) +- target_compile_definitions(basisu PRIVATE BASISD_SUPPORT_KTX2_ZSTD=1) ++ target_compile_definitions(${PROJECT_NAME} PRIVATE BASISD_SUPPORT_KTX2_ZSTD=1) + else() +- target_compile_definitions(basisu PRIVATE BASISD_SUPPORT_KTX2_ZSTD=0) ++ target_compile_definitions(${PROJECT_NAME} PRIVATE BASISD_SUPPORT_KTX2_ZSTD=0) + endif() + +-if (NOT MSVC) +- target_link_libraries(basisu m pthread) ++if (WIN32) ++ set_target_properties(${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) ++else() ++ set(THREADS_PREFER_PTHREAD_FLAG ON) ++ find_package(Threads REQUIRED) ++ target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads m) + endif() + +-if (NOT EMSCRIPTEN) +- install(TARGETS basisu DESTINATION bin) +- +- if (UNIX) +- if (CMAKE_BUILD_TYPE STREQUAL Release) +- if (APPLE) +- add_custom_command(TARGET basisu POST_BUILD COMMAND strip -X -x ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/basisu) +- else() +- add_custom_command(TARGET basisu POST_BUILD COMMAND strip -g -X -x ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/basisu) +- endif() +- endif() +- endif() +-endif() ++target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11) ++set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_EXTENSIONS OFF) diff --git a/recipes/libbasisu/all/test_package/CMakeLists.txt b/recipes/libbasisu/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..2adca01f3e68a --- /dev/null +++ b/recipes/libbasisu/all/test_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.10) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_executable(${PROJECT_NAME} test_package.cpp) + +target_link_libraries(${PROJECT_NAME} PRIVATE CONAN_PKG::libbasisu) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) diff --git a/recipes/libbasisu/all/test_package/conanfile.py b/recipes/libbasisu/all/test_package/conanfile.py new file mode 100644 index 0000000000000..12dd810a6ab3b --- /dev/null +++ b/recipes/libbasisu/all/test_package/conanfile.py @@ -0,0 +1,17 @@ +import os +from conans import ConanFile, CMake, tools + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/libbasisu/all/test_package/test_package.cpp b/recipes/libbasisu/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..15a9d4d02650c --- /dev/null +++ b/recipes/libbasisu/all/test_package/test_package.cpp @@ -0,0 +1,10 @@ +#include +#include + +int main() { + basist::basisu_transcoder_init(); + std::cout << "Basisu successfuly initialized, format localized: " + << basist::basis_get_format_name(basist::transcoder_texture_format::cTFETC2_RGBA) + << std::endl; + return 0; +} diff --git a/recipes/libbasisu/config.yml b/recipes/libbasisu/config.yml new file mode 100644 index 0000000000000..d268f882f43e4 --- /dev/null +++ b/recipes/libbasisu/config.yml @@ -0,0 +1,3 @@ +versions: + "1.15.0": + folder: all