mirror of
https://github.com/conan-io/conan-center-index.git
synced 2025-08-14 02:35:37 +00:00
(#14487) sdl_ttf: conan v2 support
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
project(cmake_wrapper C)
|
||||
|
||||
include(conanbuildinfo.cmake)
|
||||
conan_basic_setup()
|
||||
|
||||
add_subdirectory(source_subfolder)
|
@@ -5,11 +5,8 @@ sources:
|
||||
"2.0.15":
|
||||
url: "https://github.com/libsdl-org/SDL_ttf/archive/refs/tags/release-2.0.15.tar.gz"
|
||||
sha256: "02e887b560faf398cbd60f56ce0a1cbaf96012dd4ddaa455f8307cb4911c86cc"
|
||||
|
||||
patches:
|
||||
"2.0.18":
|
||||
- patch_file: "patches/cmake-fix-link-target-2.0.18.patch"
|
||||
base_path: "source_subfolder"
|
||||
"2.0.15":
|
||||
- patch_file: "patches/cmake-fix-link-target-2.0.15.patch"
|
||||
base_path: "source_subfolder"
|
||||
|
@@ -1,8 +1,12 @@
|
||||
from conans import ConanFile, CMake, tools
|
||||
from conans.errors import ConanInvalidConfiguration
|
||||
from conan import ConanFile
|
||||
from conan.errors import ConanInvalidConfiguration
|
||||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
|
||||
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir, save
|
||||
from conan.tools.microsoft import is_msvc
|
||||
from conan.tools.scm import Version
|
||||
import os
|
||||
|
||||
required_conan_version = ">=1.43.0"
|
||||
required_conan_version = ">=1.53.0"
|
||||
|
||||
|
||||
class SdlttfConan(ConanFile):
|
||||
@@ -23,21 +27,8 @@ class SdlttfConan(ConanFile):
|
||||
"fPIC": True,
|
||||
}
|
||||
|
||||
generators = "cmake", "cmake_find_package"
|
||||
_cmake = None
|
||||
|
||||
@property
|
||||
def _source_subfolder(self):
|
||||
return "source_subfolder"
|
||||
|
||||
@property
|
||||
def _build_subfolder(self):
|
||||
return "build_subfolder"
|
||||
|
||||
def export_sources(self):
|
||||
self.copy("CMakeLists.txt")
|
||||
for patch in self.conan_data.get("patches", {}).get(self.version, []):
|
||||
self.copy(patch["patch_file"])
|
||||
export_conandata_patches(self)
|
||||
|
||||
def config_options(self):
|
||||
if self.settings.os == "Windows":
|
||||
@@ -45,60 +36,68 @@ class SdlttfConan(ConanFile):
|
||||
|
||||
def configure(self):
|
||||
if self.options.shared:
|
||||
del self.options.fPIC
|
||||
del self.settings.compiler.libcxx
|
||||
del self.settings.compiler.cppstd
|
||||
self.options.rm_safe("fPIC")
|
||||
self.settings.rm_safe("compiler.cppstd")
|
||||
self.settings.rm_safe("compiler.libcxx")
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self, src_folder="src")
|
||||
|
||||
def requirements(self):
|
||||
self.requires("freetype/2.11.1")
|
||||
self.requires("sdl/2.0.18")
|
||||
self.requires("freetype/2.12.1")
|
||||
self.requires("sdl/2.26.0")
|
||||
|
||||
def validate(self):
|
||||
if self.settings.compiler == "Visual Studio" and self.options.shared:
|
||||
if is_msvc(self) and self.info.options.shared:
|
||||
raise ConanInvalidConfiguration("sdl_ttf shared is not supported with Visual Studio")
|
||||
# TODO: check that major version of sdl_tff is the same than sdl (not possible yet in validate())
|
||||
if Version(self.version).major != Version(self.dependencies["sdl"].ref.version).major:
|
||||
raise ConanInvalidConfiguration("sdl & sdl_ttf must have the same major version")
|
||||
|
||||
def source(self):
|
||||
tools.get(**self.conan_data["sources"][self.version],
|
||||
destination=self._source_subfolder, strip_root=True)
|
||||
get(self, **self.conan_data["sources"][self.version],
|
||||
destination=self.source_folder, strip_root=True)
|
||||
|
||||
def generate(self):
|
||||
tc = CMakeToolchain(self)
|
||||
tc.generate()
|
||||
deps = CMakeDeps(self)
|
||||
deps.generate()
|
||||
|
||||
def _patch_sources(self):
|
||||
for patch in self.conan_data.get("patches", {}).get(self.version, []):
|
||||
tools.patch(**patch)
|
||||
apply_conandata_patches(self)
|
||||
|
||||
# missing from distribution (only in 2.0.15?)
|
||||
tools.save(os.path.join(self._source_subfolder, "SDL2_ttfConfig.cmake"), "")
|
||||
save(self, os.path.join(self.source_folder, "SDL2_ttfConfig.cmake"), "")
|
||||
|
||||
def _configure_cmake(self):
|
||||
if self._cmake:
|
||||
return self._cmake
|
||||
self._cmake = CMake(self)
|
||||
self._cmake.configure(build_folder=self._build_subfolder)
|
||||
return self._cmake
|
||||
# workaround for a side effect of CMAKE_FIND_PACKAGE_PREFER_CONFIG ON in conan toolchain
|
||||
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
|
||||
"find_package(Freetype REQUIRED)",
|
||||
"find_package(Freetype REQUIRED MODULE)")
|
||||
|
||||
def build(self):
|
||||
self._patch_sources()
|
||||
cmake = self._configure_cmake()
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def package(self):
|
||||
self.copy("COPYING.txt", dst="licenses", src=self._source_subfolder)
|
||||
cmake = self._configure_cmake()
|
||||
copy(self, "COPYING.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
|
||||
cmake = CMake(self)
|
||||
cmake.install()
|
||||
tools.rmdir(os.path.join(self.package_folder, "cmake"))
|
||||
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
|
||||
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
|
||||
tools.rmdir(os.path.join(self.package_folder, "SDL2_ttf.framework"))
|
||||
rmdir(self, os.path.join(self.package_folder, "cmake"))
|
||||
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
|
||||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
|
||||
rmdir(self, os.path.join(self.package_folder, "SDL2_ttf.framework"))
|
||||
|
||||
def package_info(self):
|
||||
self.cpp_info.set_property("cmake_file_name", "SDL2_ttf")
|
||||
self.cpp_info.set_property("cmake_target_name", "SDL2_ttf::SDL2_ttf")
|
||||
self.cpp_info.set_property("pkg_config_name", "SDL2_ttf")
|
||||
|
||||
self.cpp_info.names["cmake_find_package"] = "SDL2_ttf"
|
||||
self.cpp_info.names["cmake_find_package_multi"] = "SDL2_ttf"
|
||||
self.cpp_info.names["pkg_config"] = "SDL2_ttf"
|
||||
|
||||
self.cpp_info.includedirs.append(os.path.join("include", "SDL2"))
|
||||
self.cpp_info.libs = ["SDL2_ttf"]
|
||||
self.cpp_info.requires = ["freetype::freetype", "sdl::libsdl2"]
|
||||
|
||||
# TODO: to remove in conan v2
|
||||
self.cpp_info.names["cmake_find_package"] = "SDL2_ttf"
|
||||
self.cpp_info.names["cmake_find_package_multi"] = "SDL2_ttf"
|
||||
|
@@ -1,10 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(test_package C)
|
||||
|
||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup(TARGETS)
|
||||
project(test_package LANGUAGES C)
|
||||
|
||||
find_package(SDL2_ttf REQUIRED CONFIG)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_package.c)
|
||||
target_link_libraries(${PROJECT_NAME} SDL2_ttf::SDL2_ttf)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_ttf::SDL2_ttf)
|
||||
|
@@ -1,10 +1,19 @@
|
||||
from conans import ConanFile, CMake, tools
|
||||
from conan import ConanFile
|
||||
from conan.tools.build import can_run
|
||||
from conan.tools.cmake import CMake, cmake_layout
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "cmake", "cmake_find_package_multi"
|
||||
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
|
||||
test_type = "explicit"
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def requirements(self):
|
||||
self.requires(self.tested_reference_str)
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
@@ -12,7 +21,7 @@ class TestPackageConan(ConanFile):
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
if not tools.cross_building(self):
|
||||
bin_path = os.path.join("bin", "test_package")
|
||||
if can_run(self):
|
||||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
|
||||
ttf_path = os.path.join(self.source_folder, "OpenSans-Bold.ttf")
|
||||
self.run("{} {}".format(bin_path, ttf_path), run_environment=True)
|
||||
self.run(f"{bin_path} {ttf_path}", env="conanrun")
|
||||
|
8
recipes/sdl_ttf/all/test_v1_package/CMakeLists.txt
Normal file
8
recipes/sdl_ttf/all/test_v1_package/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(test_package)
|
||||
|
||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup(TARGETS)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test_package)
|
18
recipes/sdl_ttf/all/test_v1_package/conanfile.py
Normal file
18
recipes/sdl_ttf/all/test_v1_package/conanfile.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from conans import ConanFile, CMake, tools
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "cmake", "cmake_find_package_multi"
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
if not tools.cross_building(self):
|
||||
bin_path = os.path.join("bin", "test_package")
|
||||
ttf_path = os.path.join(self.source_folder, os.pardir, "test_package", "OpenSans-Bold.ttf")
|
||||
self.run(f"{bin_path} {ttf_path}", run_environment=True)
|
Reference in New Issue
Block a user