Skip to content

Instantly share code, notes, and snippets.

@ppetraki
Created March 4, 2019 19:03
Show Gist options
  • Save ppetraki/134b6ceb08535d3dd0ac729220cf81bb to your computer and use it in GitHub Desktop.
Save ppetraki/134b6ceb08535d3dd0ac729220cf81bb to your computer and use it in GitHub Desktop.
meson_conan_example
#conanfile.py
from conans import ConanFile, Meson
class KrilliaConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
# ("", "")
requires = "gtest/1.8.1@bincrafters/stable"
generators = "pkg_config", "ycm"
default_options = {"gtest:shared": True}
def imports(self):
self.copy("*.dll", dst="bin", src="bin") # From bin to bin
self.copy("*.dylib*", dst="bin", src="lib") # From lib to bin
def build(self):
meson = Meson(self)
# conan is shadowing these meson parameters...
args = ['-Db_coverage=true']
options={ 'warning_level': 3, 'cpp_std': 'c++1z'}
meson.configure(args=args, defs=options)
meson.build()
# XXX probably move all makefile magic to here
meson.test()
meson.test(targets=['coverage'])
#meson.build
# vim:ft=meson
project('kbs',
'cpp',
version : '0.1.0',
# these are overriden by conan so make sure you make changes
# in both places or you will be "surprised" when you run meson
# without conan harnessing it.
default_options : ['warning_level=3', 'cpp_std=c++1z']
)
libopenssl = dependency('openssl', version : '>= 1.1.0', required : true)
# provided by conan
libgtest = dependency('gtest', version :'>= 1.8.1', method : 'pkg-config', required: true)
include_dirs = []
include_dirs += include_directories('kbs/src')
link_flags = []
cpp_flags = [
'-Wall',
'-Wextra',
'-Wshadow',
'-Wnon-virtual-dtor',
'-Wold-style-cast',
'-Wcast-align',
'-Wunused',
'-Woverloaded-virtual',
'-Wpedantic',
'-Wconversion',
'-Wsign-conversion',
'-Wmisleading-indentation',
'-Wduplicated-cond',
'-Wduplicated-branches',
'-Wlogical-op',
'-Wnull-dereference',
'-Wuseless-cast',
'-Wdouble-promotion',
'-Wformat=2'
]
cpp = meson.get_compiler('cpp')
add_project_arguments(cpp.get_supported_arguments(cpp_flags), language : 'cpp')
add_project_link_arguments(cpp.get_supported_link_arguments(link_flags), language : 'cpp')
#... the rest is filelists and targets
#Makefile
TOP=$(shell pwd)
CURRENT_BUILD=${TOP}/current-build
# the release profile is named 'default' for conan, probably should change that.
BUILD_PROFILE=
BUILD_TYPE=
# map build types to conan build profiles
ifeq ($(MAKECMDGOALS), debug)
BUILD_PROFILE = debug
BUILD_TYPE = debug
endif
ifeq ($(MAKECMDGOALS), release)
BUILD_PROFILE = default
BUILD_TYPE = release
endif
BUILD_DIR := build-$(shell echo $(BUILD_TYPE) | tr A-Z a-z)
# just describe the project and exit if we don't target a build
ifeq ($(BUILD_PROFILE),)
all: info
endif
.PHONY: header
header:
@echo "BUILD_DIR $(BUILD_DIR)"
@echo "BUILD_TYPE $(BUILD_TYPE)"
.PHONY: info
info:
conan info .
clean:
rm -rf build-* tags current-build compile_commands.json
.PHONY: tags
tags:
ctags -R kbs
.PHONY: build_dispatch
build_dispatch:
mkdir ${BUILD_DIR} || :
rm -f current-build && ln -sf ${BUILD_DIR} current-build
conan install . -pr ${BUILD_PROFILE} --install-folder ${BUILD_DIR}
ln -sf current-build/build/compile_commands.json
ln -sf ${BUILD_DIR}/compile_commands.json
conan build . --build-folder ${BUILD_DIR}
.PHONY: debug
debug: header build_dispatch tags
.PHONY: release
release: header build_dispatch tags
.PHONY: check
check: clean
make debug
make release
.PHONY: coverage
coverage:
cd current-build && ninja coverage
.PHONY: coverage-html
coverage-html: coverage
xdg-open file://${CURRENT_BUILD}/meson-logs/coveragereport/index.html
.PHONY: coverage-report
coverage-report: coverage
gcovr ${CURRENT_BUILD}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment