From e0c27ee7cf16ba2fc25f84b60ddc75d7e96f5b55 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 20 Jul 2023 23:15:50 +0300 Subject: [PATCH] godot-cpp: migrate to Conan v2 --- recipes/godot-cpp/all/conanfile.py | 193 +++++++++++------- .../godot-cpp/all/test_package/CMakeLists.txt | 11 +- .../godot-cpp/all/test_package/conanfile.py | 22 +- .../all/test_v1_package/CMakeLists.txt | 8 + .../all/test_v1_package/conanfile.py | 18 ++ 5 files changed, 162 insertions(+), 90 deletions(-) create mode 100644 recipes/godot-cpp/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/godot-cpp/all/test_v1_package/conanfile.py diff --git a/recipes/godot-cpp/all/conanfile.py b/recipes/godot-cpp/all/conanfile.py index 625aabfb6d9025..e4a84dedfe7ad4 100644 --- a/recipes/godot-cpp/all/conanfile.py +++ b/recipes/godot-cpp/all/conanfile.py @@ -1,8 +1,15 @@ -import glob import os -from conans import ConanFile, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import copy, get +from conan.tools.layout import basic_layout +from conan.tools.microsoft import is_msvc +from conan.tools.scm import Version + +required_conan_version = ">=1.53.0" class GodotCppConan(ConanFile): @@ -12,20 +19,85 @@ class GodotCppConan(ConanFile): url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/godotengine/godot-cpp" topics = ("game-engine", "game-development", "c++") + + package_type = "library" settings = "os", "arch", "compiler", "build_type" - build_requires = ["scons/3.1.2"] + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def layout(self): + basic_layout(self, src_folder="src") + + def requirements(self): + self.requires(f"godot_headers/{self.version}", transitive_headers=True) + + def package_id(self): + if self.info.settings.build_type == "Debug": + self.info.settings.build_type = "Debug" + else: + self.info.settings.build_type = "Release" + + def validate(self): + minimal_cpp_standard = 14 + if self.settings.compiler.cppstd: + check_min_cppstd(self, minimal_cpp_standard) + + minimal_version = { + "gcc": "5", + "clang": "4", + "apple-clang": "10", + "msvc": "191", + "Visual Studio": "15", + } + + compiler = str(self.settings.compiler) + if compiler not in minimal_version: + self.output.warning( + f"{self.name} recipe lacks information about the {compiler} compiler standard version support" + ) + self.output.warning( + f"{self.name} requires a compiler that supports at least C++{minimal_cpp_standard}" + ) + return + + version = Version(self.settings.compiler.version) + if version < minimal_version[compiler]: + if compiler in ["apple-clang", "clang"]: + raise ConanInvalidConfiguration( + f"{self.name} requires a clang version that supports the '-Og' flag" + ) + raise ConanInvalidConfiguration( + f"{self.name} requires a compiler that supports at least C++{minimal_cpp_standard}" + ) + + def build_requirements(self): + self.tool_requires("scons/4.3.0") @property def _bits(self): - return 64 if self.settings.get_safe("arch") in ["x86_64", "armv8"] else 32 + return 32 if self.settings.arch in ["x86"] else 64 @property def _custom_api_file(self): - return "{}/api.json".format(self._godot_headers.res_paths[0]) + return f"{self._godot_headers.resdirs[0]}/api.json" @property def _headers_dir(self): - return self._godot_headers.include_paths[0] + return self._godot_headers.includedirs[0] @property def _platform(self): @@ -34,98 +106,71 @@ def _platform(self): "Linux": "linux", "Macos": "osx", } - return flag_map[self.settings.get_safe("os")] + return flag_map[str(self.settings.os)] @property def _target(self): - return "debug" if self.settings.get_safe("build_type") == "Debug" else "release" + return "debug" if self.settings.build_type == "Debug" else "release" @property def _use_llvm(self): - return self.settings.get_safe("compiler") in ["clang", "apple-clang"] + return self.settings.compiler in ["clang", "apple-clang"] @property def _use_mingw(self): - return self._platform == "windows" and self.settings.compiler == "gcc" + return self.settings.os == "Windows" and self.settings.compiler == "gcc" @property def _libname(self): - return "godot-cpp.{platform}.{target}.{bits}".format(platform=self._platform, target=self._target, bits=self._bits) - - @property - def _source_subfolder(self): - return "source_subfolder" + return f"godot-cpp.{self._platform}.{self._target}.{self._bits}" @property def _godot_headers(self): - return self.deps_cpp_info["godot_headers"] + return self.dependencies["godot_headers"].cpp_info def source(self): - tools.get(**self.conan_data["sources"][self.version]) - tools.rename(glob.glob("godot-cpp-*")[0], self._source_subfolder) + get(self, **self.conan_data["sources"][self.version], strip_root=True) - def requirements(self): - self.requires("godot_headers/{}".format(self.version)) - - def configure(self): - minimal_cpp_standard = "14" - if self.settings.compiler.cppstd: - tools.check_min_cppstd(self, minimal_cpp_standard) - - minimal_version = { - "gcc": "5", - "clang": "4", - "apple-clang": "10", - "Visual Studio": "15", - } - - compiler = str(self.settings.compiler) - if compiler not in minimal_version: - self.output.warn( - "{} recipe lacks information about the {} compiler standard version support".format(self.name, compiler)) - self.output.warn( - "{} requires a compiler that supports at least C++{}".format(self.name, minimal_cpp_standard)) - return - - version = tools.Version(self.settings.compiler.version) - if version < minimal_version[compiler]: - if compiler in ["apple-clang", "clang"]: - raise ConanInvalidConfiguration( - "{} requires a clang version that supports the '-Og' flag".format(self.name)) - raise ConanInvalidConfiguration( - "{} requires a compiler that supports at least C++{}".format(self.name, minimal_cpp_standard)) + def generate(self): + VirtualBuildEnv(self).generate() def build(self): self.run("python --version") if self.settings.os == "Macos": self.run("which python") self.run("scons --version") - self.run( - " ".join([ - "scons", - "-C{}".format(self._source_subfolder), - "-j{}".format(tools.cpu_count()), - "generate_bindings=yes", - "use_custom_api_file=yes", - "bits={}".format(self._bits), - "custom_api_file={}".format(self._custom_api_file), - "headers_dir={}".format(self._headers_dir), - "platform={}".format(self._platform), - "target={}".format(self._target), - "use_llvm={}".format(self._use_llvm), - "use_mingw={}".format(self._use_mingw), - ]) - ) + self.run(" ".join([ + "scons", + f"-C{self.source_folder}", + f"-j{os.cpu_count()}", + "generate_bindings=yes", + "use_custom_api_file=yes", + f"bits={self._bits}", + f"custom_api_file={self._custom_api_file}", + f"headers_dir={self._headers_dir}", + f"platform={self._platform}", + f"target={self._target}", + f"use_llvm={self._use_llvm}", + f"use_mingw={self._use_mingw}", + ])) def package(self): - self.copy("LICENSE*", dst="licenses", src=self._source_subfolder) - self.copy("*.hpp", dst="include/godot-cpp", src=os.path.join(self._source_subfolder, "include")) - self.copy("*.a", dst="lib", src=os.path.join(self._source_subfolder, "bin")) - self.copy("*.lib", dst="lib", src=os.path.join(self._source_subfolder, "bin")) + copy(self, "LICENSE*", + dst=os.path.join(self.package_folder, "licenses"), + src=self.source_folder) + copy(self, "*.hpp", + dst=os.path.join(self.package_folder, "include/godot-cpp"), + src=os.path.join(self.source_folder, "include")) + copy(self, "*.a", + dst=os.path.join(self.package_folder, "lib"), + src=os.path.join(self.source_folder, "bin")) + copy(self, "*.lib", + dst=os.path.join(self.package_folder, "lib"), + src=os.path.join(self.source_folder, "bin")) def package_info(self): - if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio": - self.cpp_info.libs = ["lib{}".format(self._libname)] + if is_msvc(self): + self.cpp_info.libs = [f"lib{self._libname}"] else: self.cpp_info.libs = [self._libname] @@ -134,9 +179,3 @@ def package_info(self): os.path.join("include", "godot-cpp", "core"), os.path.join("include", "godot-cpp", "gen"), ] - - def package_id(self): - if self._target == "release": - self.info.settings.build_type = "Release" - else: - self.info.settings.build_type = "Debug" diff --git a/recipes/godot-cpp/all/test_package/CMakeLists.txt b/recipes/godot-cpp/all/test_package/CMakeLists.txt index cb623ce6ed58f7..49d358aeae0efd 100644 --- a/recipes/godot-cpp/all/test_package/CMakeLists.txt +++ b/recipes/godot-cpp/all/test_package/CMakeLists.txt @@ -1,9 +1,8 @@ -cmake_minimum_required(VERSION "3.1") +cmake_minimum_required(VERSION 3.15) project("test_package" LANGUAGES CXX) -include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup() +find_package(godot-cpp REQUIRED CONFIG) -add_executable("${PROJECT_NAME}" "test_package.cpp") -target_link_libraries("${PROJECT_NAME}" ${CONAN_LIBS}) -set_property(TARGET "${PROJECT_NAME}" PROPERTY CXX_STANDARD "14") +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} godot-cpp::godot-cpp) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) diff --git a/recipes/godot-cpp/all/test_package/conanfile.py b/recipes/godot-cpp/all/test_package/conanfile.py index 4dea15a1318e13..fae501d0afb9e4 100644 --- a/recipes/godot-cpp/all/test_package/conanfile.py +++ b/recipes/godot-cpp/all/test_package/conanfile.py @@ -1,11 +1,19 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os -from conans import ConanFile, CMake, tools - class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -13,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/godot-cpp/all/test_v1_package/CMakeLists.txt b/recipes/godot-cpp/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..91630d79f4abb3 --- /dev/null +++ b/recipes/godot-cpp/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +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/) diff --git a/recipes/godot-cpp/all/test_v1_package/conanfile.py b/recipes/godot-cpp/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..75634e62bcb667 --- /dev/null +++ b/recipes/godot-cpp/all/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +import os + +from conans import ConanFile, CMake, tools + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + 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") + self.run(bin_path, run_environment=True)