Skip to content

Commit

Permalink
(conan-io#5090) - add luajit/2.0.5
Browse files Browse the repository at this point in the history
* - add luajit/2.0.5

Signed-off-by: SSE4 <[email protected]>

* - set MACOSX_DEPLOYMENT_TARGET

Signed-off-by: SSE4 <[email protected]>

* - fix Linux and macOS shared builds
- ensure either .so or .o is built, but never both
- use install to get correct symlinks for .so or .dylib

Signed-off-by: SSE4 <[email protected]>
  • Loading branch information
SSE4 authored Apr 14, 2021
1 parent 834af0c commit e89b0a7
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/luajit/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.0.5":
url: "http://luajit.org/download/LuaJIT-2.0.5.tar.gz"
sha256: "874b1f8297c697821f561f9b73b57ffd419ed8f4278c82e05b48806d30c1e979"
107 changes: 107 additions & 0 deletions recipes/luajit/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import os
import platform
from conans import ConanFile, tools, VisualStudioBuildEnvironment, AutoToolsBuildEnvironment


class LuajitConan(ConanFile):
name = "luajit"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://luajit.org"
description = "LuaJIT is a Just-In-Time Compiler (JIT) for the Lua programming language."
topics = ("conan", "lua", "jit")
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False],
"fPIC": [True, False]}
default_options = {"shared": False,
"fPIC": True}
_env_build = None

@property
def _source_subfolder(self):
return "source_subfolder"

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def _configure_autotools(self):
if not self._env_build:
self._env_build = AutoToolsBuildEnvironment(self)
return self._env_build

def build(self):
if self.settings.compiler == 'Visual Studio':
with tools.chdir(os.path.join(self._source_subfolder, 'src')):
env_build = VisualStudioBuildEnvironment(self)
with tools.environment_append(env_build.vars), tools.vcvars(self):
variant = '' if self.options.shared else 'static'
self.run("msvcbuild.bat %s" % variant)
else:
buildmode = 'shared' if self.options.shared else 'static'
makefile = os.path.join(self._source_subfolder, 'src', 'Makefile')
tools.replace_in_file(makefile,
'BUILDMODE= mixed',
'BUILDMODE= %s' % buildmode)
tools.replace_in_file(makefile,
'TARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME)',
'TARGET_DYLIBPATH= $(TARGET_DYLIBNAME)')
# adjust mixed mode defaults to build either .so or .a, but not both
if not self.options.shared:
tools.replace_in_file(makefile,
'TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)',
'TARGET_T= $(LUAJIT_T) $(LUAJIT_A)')
tools.replace_in_file(makefile,
'TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)',
'TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_A)')
else:
tools.replace_in_file(makefile,
'TARGET_O= $(LUAJIT_A)',
'TARGET_O= $(LUAJIT_SO)')
env = dict()
if self.settings.os == "Macos":
# Per https://luajit.org/install.html: If MACOSX_DEPLOYMENT_TARGET
# is not set then it's forced to 10.4, which breaks compile on Mojave.
version = self.settings.get_safe("os.version")
if not version and platform.system() == "Darwin":
major, minor, _ = platform.mac_ver()[0].split(".")
version = "%s.%s" % (major, minor)
env["MACOSX_DEPLOYMENT_TARGET"] = version
with tools.chdir(self._source_subfolder), tools.environment_append(env):
env_build = self._configure_autotools()
env_build.make(args=["PREFIX=%s" % self.package_folder])

def package(self):
self.copy("COPYRIGHT", dst="licenses", src=self._source_subfolder)
if self.settings.compiler == 'Visual Studio':
ljs = os.path.join(self._source_subfolder, "src")
inc = os.path.join(self.package_folder, "include", "luajit-2.0")
self.copy("lua.h", dst=inc, src=ljs)
self.copy("lualib.h", dst=inc, src=ljs)
self.copy("lauxlib.h", dst=inc, src=ljs)
self.copy("luaconf.h", dst=inc, src=ljs)
self.copy("lua.hpp", dst=inc, src=ljs)
self.copy("luajit.h", dst=inc, src=ljs)
self.copy("lua51.lib", dst="lib", src=ljs)
self.copy("lua51.dll", dst="bin", src=ljs)
else:
with tools.chdir(self._source_subfolder):
env_build = self._configure_autotools()
env_build.install(args=["PREFIX=%s" % self.package_folder])
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs = ["lua51" if self.settings.compiler == "Visual Studio" else "luajit-5.1"]
self.cpp_info.includedirs = [os.path.join(self.package_folder, "include", "luajit-2.0")]
if self.settings.os == "Linux":
self.cpp_info.system_libs.extend(["m", "dl"])
10 changes: 10 additions & 0 deletions recipes/luajit/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

find_package(luajit REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} luajit::luajit)
17 changes: 17 additions & 0 deletions recipes/luajit/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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)
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)
9 changes: 9 additions & 0 deletions recipes/luajit/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <luajit.h>

int main()
{
LUAJIT_VERSION_SYM();
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/luajit/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.0.5":
folder: "all"

0 comments on commit e89b0a7

Please sign in to comment.