Skip to content

Commit

Permalink
(#15316) Lua: conan v2 support & v5.3.6
Browse files Browse the repository at this point in the history
* Lua: conan v2 support & v5.3.6

* Also check in test_package this time

* Fix patch

* Use cmake layout

* Use src_folder="src" for layout

* Add package_type & fix cmake syntax error

* Update required_conan_version

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Reuse test_package code in test_v1_package

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* End files with newline

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* fix apple relocatable shared libs

Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
StellaSmith and uilianries authored Jan 27, 2023
1 parent ec7a07a commit 18d4f5f
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 54 deletions.
7 changes: 1 addition & 6 deletions recipes/lua/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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://raw.githubusercontent.com/microsoft/vcpkg/master/ports/lua/CMakeLists.txt

# Lua can be compiled as either C or C++.
Expand All @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion recipes/lua/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
78 changes: 43 additions & 35 deletions recipes/lua/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,80 @@
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":
del self.options.fPIC

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"]:
Expand Down
2 changes: 1 addition & 1 deletion recipes/lua/all/patches/5.3.5/lua_mobile.patch
Original file line number Diff line number Diff line change
@@ -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 @@

Expand Down
3 changes: 0 additions & 3 deletions recipes/lua/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
28 changes: 20 additions & 8 deletions recipes/lua/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 7 additions & 0 deletions recipes/lua/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
20 changes: 20 additions & 0 deletions recipes/lua/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions recipes/lua/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ versions:
folder: all
"5.4.1":
folder: all
"5.3.6":
folder: all
"5.3.5":
folder: all

0 comments on commit 18d4f5f

Please sign in to comment.