Skip to content

Commit

Permalink
In-source native build with Conan
Browse files Browse the repository at this point in the history
The canonical build scripts for production builds are either the GNU
Makefile or Visual Studio projects, so use those in Conan instead of the
cmake adaptation. Having to install both CMake and Conan just to build a
package seems a bit overkill for such a simple project with no external
dependencies.

Also, since this conanfile is in the source tree, use the
exports_sources approach recommended for that scenario in the Conan
documentation.

Finally, we forbid compiler.libcxx=libstdc++ since that causes ABI
incompatibility.
  • Loading branch information
mattiasflodin committed May 3, 2020
1 parent df15c78 commit 82ba548
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 46 deletions.
17 changes: 2 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,5 @@
# here to build performance tests and other cruft. You need to use tup for all
# of that.

CXXFLAGS = -std=c++11 -Wall -Wextra -O3 -g -Ireckless/include -Iperformance_log/include

target = reckless/lib/libreckless.a
srcpath = reckless/src
sources := $(filter-out %_win32.cpp,$(wildcard $(srcpath)/*.cpp))
objects := $(patsubst %.cpp,%.o,$(sources))

.PHONY: clean

$(target): $(objects)
-$(RM) $(target)
ar rs $(target) $(objects)

clean:
$(RM) $(target) $(objects)
CXXFLAGS = -std=c++11 -Wall -Wextra -O3 -DNDEBUG
include Makefile.conan
16 changes: 16 additions & 0 deletions Makefile.conan
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CXXFLAGS += -Ireckless/include -g

target = reckless/lib/libreckless.a
srcpath = reckless/src
sources := $(filter-out %_win32.cpp,$(wildcard $(srcpath)/*.cpp))
objects := $(patsubst %.cpp,%.o,$(sources))

.PHONY: clean

$(target): $(objects)
-$(RM) $(target)
mkdir -p reckless/lib
ar rs $(target) $(objects)

clean:
$(RM) $(target) $(objects)
74 changes: 43 additions & 31 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,63 @@
# -*- coding: utf-8 -*-

import os, shutil
from conans import ConanFile, tools, CMake
from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild
from conans.errors import ConanException

MSDEV_PLATFORM_SHORT_NAMES = {
'x86': 'x86',
'x86_64': 'x64'
}

class RecklessConan(ConanFile):
name = 'reckless'
license = 'MIT'
version = '3.0.1'
url = 'https://github.com/mattiasflodin/reckless'
description = """Reckless is an extremely low-latency, high-throughput logging library."""
generators = 'cmake'
settings = 'arch', 'cppstd', 'compiler', 'build_type'

_build_subfolder = 'build'
_source_subfolder = 'src'
settings = 'arch', 'compiler', 'build_type'
exports_sources = (
"reckless/src/*",
"reckless/include/*",
"Makefile.conan",
"reckless.sln",
"common.props",
"*.vcxproj"
)

def configure(self):
pass

def source(self):
tools.get('%s/archive/v%s.tar.gz' % (self.url, self.version))
shutil.move('reckless-%s' % self.version, self._source_subfolder)

def _configure_cmake(self):

cmake = CMake(self)
cmake.configure(build_folder=self._build_subfolder, source_folder=self._source_subfolder)
return cmake
if self._gcc_compatible() and self.settings.compiler.libcxx == "libstdc++":
raise ConanException("This package is only compatible with libstdc++11. "
"Please run with -s compiler.libcxx=libstdc++11.")

def build(self):
os.makedirs(self._build_subfolder)
with tools.chdir(self._build_subfolder):
cmake = self._configure_cmake()
cmake.build()
if self.settings.compiler == "Visual Studio":
env = MSBuild(self)
env.build('reckless.sln', use_env=False, targets=['reckless:Rebuild'])
else:
env = AutoToolsBuildEnvironment(self)
env.make(args=['-f', 'Makefile.conan'], target="clean")
# Why doesn't Conan set CXX?
vars = env.vars
vars['CXX'] = str(self.settings.compiler)
env.make(args=['-f', 'Makefile.conan'], vars=vars)


def package(self):

self.copy('*.a', src='build', dst='lib', keep_path=False)
self.copy('*.lib', src='build', dst='lib', keep_path=False)
self.copy('*.hpp', src='src/reckless/include', dst='include', keep_path=True)

if self.settings.build_type == 'Debug':
self.copy('*.cpp', src='src/reckless/src', dst='src', keep_path=True)
self.copy('*.pdb', src='build', dst='lib', keep_path=False)
if self._gcc_compatible():
self.copy('*.a', src='reckless/lib', dst='lib', keep_path=False)
else:
platform_short_name = MSDEV_PLATFORM_SHORT_NAMES[str(self.settings.arch)]
configuration_name = str(self.settings.build_type).lower()
build_directory = os.path.join('build', '%s-%s' % (platform_short_name, configuration_name))
self.copy('*.lib', src=build_directory, dst='lib', keep_path=False)
self.copy('*.pdb', src=build_directory, dst='lib', keep_path=False)

self.copy('*.hpp', src='reckless/include', dst='include', keep_path=True)
self.copy('*.cpp', src='reckless/src', dst='src', keep_path=True)
self.copy('LICENSE.txt', src='src')

def package_info(self):
self.cpp_info.libs = ["reckless"]
pass

def _gcc_compatible(self):
return str(self.settings.compiler) in ['gcc', 'clang', 'apple-clang']

0 comments on commit 82ba548

Please sign in to comment.