Skip to content

Instantly share code, notes, and snippets.

@Sahnvour
Created March 17, 2021 19:23
Show Gist options
  • Save Sahnvour/5810692a395589c62086f1bc7f0ddf13 to your computer and use it in GitHub Desktop.
Save Sahnvour/5810692a395589c62086f1bc7f0ddf13 to your computer and use it in GitHub Desktop.
from conans.model import Generator
from conans import ConanFile
class MesonDeps(object):
def __init__(self, dep, deps_cpp_info):
self.include_paths = ",\n".join("'%s'" % p.replace("\\", "/")
for p in deps_cpp_info.include_paths)
self.lib_paths = ",\n".join("'%s'" % p.replace("\\", "/")
for p in deps_cpp_info.lib_paths)
self.libs = ''
for l in deps_cpp_info.libs:
self.libs += f"_conan_compiler.find_library('{l}', dirs: _{dep}_lib_paths),"
self.defines = ", ".join("'-D%s'" % p for p in deps_cpp_info.defines)
self.cppflags = ", ".join('"%s"' % p for p in deps_cpp_info.cppflags)
self.cflags = ", ".join('"%s"' % p for p in deps_cpp_info.cflags)
self.sharedlinkflags = ", ".join('"%s"' % p for p in deps_cpp_info.sharedlinkflags)
self.exelinkflags = ", ".join('"%s"' % p for p in deps_cpp_info.exelinkflags)
self.rootpath = "%s" % deps_cpp_info.rootpath.replace("\\", "/")
class meson(Generator):
@property
def filename(self):
return "meson.build"
@property
def content(self):
template = """_{dep}_lib_paths = [{deps.lib_paths}]
{dep}_dep = declare_dependency(
include_directories: [{deps.include_paths}],
dependencies: [{deps.libs}],
compile_args: [{deps.cppflags}] + [{deps.defines}],
link_args: [{deps.exelinkflags}]
# not handled by generator:
# conan_cflags = {{{deps.cflags}}}
# conan_sharedlinkflags = {{{deps.sharedlinkflags}}}
)"""
sections = ["_conan_compiler = meson.get_compiler('cpp')"]
for dep_name, dep_cpp_info in self.deps_build_info.dependencies:
if dep_name == 'mesongen':
continue
deps = MesonDeps(dep_name, dep_cpp_info)
dep_name = dep_name.replace("-", "_")
dep_flags = template.format(dep=dep_name, deps=deps)
sections.append(dep_flags)
return "\n\n".join(sections)
class MesonGeneratorPackage(ConanFile):
name = "mesongen"
version = "0.1"
license = "MIT"
_conan_compiler = meson.get_compiler('cpp')
_glfw_lib_paths = ['C:/Users/user/.conan/data/glfw/3.3.3/_/_/package/d3cffeefc8c8bcb6be8abdd182cb1b56fc81bacc/lib']
glfw_dep = declare_dependency(
include_directories: ['C:/Users/user/.conan/data/glfw/3.3.3/_/_/package/d3cffeefc8c8bcb6be8abdd182cb1b56fc81bacc/include'],
dependencies: [_conan_compiler.find_library('glfw3', dirs: _glfw_lib_paths),],
compile_args: [] + [],
link_args: []
# not handled by generator:
# conan_cflags = {}
# conan_sharedlinkflags = {}
)
_opengl_lib_paths = []
opengl_dep = declare_dependency(
include_directories: [],
dependencies: [],
compile_args: [] + [],
link_args: []
# not handled by generator:
# conan_cflags = {}
# conan_sharedlinkflags = {}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment