From 3ae26b54302a4700083576b02c091d70449ffe2f Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Sun, 28 Jul 2019 12:15:50 +0200 Subject: [PATCH] refine conan requirements and packaging --- conanfile.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/conanfile.py b/conanfile.py index 29a52b6..17aab81 100644 --- a/conanfile.py +++ b/conanfile.py @@ -22,22 +22,39 @@ class NameofConan(ConanFile): exports_sources = ['example/*','include/*','test/*','CMakeLists.txt','LICENSE'] exports = ['LICENSE.md'] _build_subfolder = 'build_subfolder' - build_requires = 'Catch2/2.9.1@catchorg/stable' + settings = ('os', 'compiler', 'build_type', 'arch') + options = { + 'build_tests': [True, False], + 'build_examples': [True, False], + } + default_options = { + 'build_tests': False, + 'build_examples': False, + } - def configure_cmake(self, build_tests_and_examples): + def requirements(self): + if self.options.build_tests: + self.requires('Catch2/2.9.1@catchorg/stable') + + def config_options(self): + needs_build = self.options.build_tests or self.options.build_examples + if not needs_build: + # remove all build settings since it is a header-only library + self.options.remove(['os', 'compiler', 'build_type', 'arch']) + + def configure_cmake(self): cmake = CMake(self) - if self.develop: - self.output.info("Develop mode on, building with tests and examples") - cmake.definitions['NAMEOF_OPT_BUILD_TESTS'] = build_tests_and_examples - cmake.definitions['NAMEOF_OPT_BUILD_EXAMPLES'] = build_tests_and_examples + cmake.definitions['NAMEOF_OPT_BUILD_TESTS'] = self.options.build_tests + cmake.definitions['NAMEOF_OPT_BUILD_EXAMPLES'] = self.options.build_examples cmake.configure(build_folder=self._build_subfolder) return cmake def build(self): - cmake = self.configure_cmake(build_tests_and_examples = True) + cmake = self.configure_cmake() cmake.build() - cmake.test() + if self.options.build_tests: + cmake.test() def package(self): - cmake = self.configure_cmake(build_tests_and_examples = False) + cmake = self.configure_cmake() cmake.install()