From f0720ba756234a7286955925bed5a7d687c09759 Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Sat, 27 Jul 2019 18:53:03 +0200 Subject: [PATCH] initial implementation of conan recipe --- conanfile.py | 43 +++++++++++++++++++++++++++++++++++ test_package/CMakeLists.txt | 11 +++++++++ test_package/conanfile.py | 19 ++++++++++++++++ test_package/test_package.cpp | 27 ++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 conanfile.py create mode 100644 test_package/CMakeLists.txt create mode 100644 test_package/conanfile.py create mode 100644 test_package/test_package.cpp diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..29a52b6 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from conans import ConanFile, tools, CMake +import os + + +class NameofConan(ConanFile): + name = 'nameof' + version = '0.9.0' + description = 'Header-only C++17 library provides nameof macros and functions to obtain simple name of variable, type, function, macro, and enum.' + topics = ( + 'conan', + 'nameof', + 'introspection', + 'compile-time' + ) + url = 'https://github.com/Neargye/nameof' + author = 'Daniil Goncharov ' + license = 'MIT' + generators = 'cmake_find_package' + exports_sources = ['example/*','include/*','test/*','CMakeLists.txt','LICENSE'] + exports = ['LICENSE.md'] + _build_subfolder = 'build_subfolder' + build_requires = 'Catch2/2.9.1@catchorg/stable' + + def configure_cmake(self, build_tests_and_examples): + 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.configure(build_folder=self._build_subfolder) + return cmake + + def build(self): + cmake = self.configure_cmake(build_tests_and_examples = True) + cmake.build() + cmake.test() + + def package(self): + cmake = self.configure_cmake(build_tests_and_examples = False) + cmake.install() diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..a3911f2 --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8.12) +project(test_package CXX) + +set(CMAKE_VERBOSE_MAKEFILE TRUE) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(test_package test_package.cpp) +target_link_libraries(test_package ${CONAN_LIBS}) +set_target_properties(test_package PROPERTIES CXX_STANDARD 17) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..4736904 --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + 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) diff --git a/test_package/test_package.cpp b/test_package/test_package.cpp new file mode 100644 index 0000000..0dfd7af --- /dev/null +++ b/test_package/test_package.cpp @@ -0,0 +1,27 @@ +#include + +#include +#include +#include + +struct SomeStruct {}; +enum class Color { RED = -12, GREEN = 7, BLUE = 15 }; + +SomeStruct structvar; +int main() { + // Compile-time. + constexpr auto name = NAMEOF(structvar); + static_assert("structvar" == name); + + // Nameof. + using std::literals::string_view_literals::operator""sv; + + std::string_view res1 = NAMEOF(structvar); + std::string_view res2 = NAMEOF(::structvar); + + std::cout << res1 << '\n' << res2 << '\n'; + + bool success = res1 == "structvar"sv + && res2 == "structvar"sv; + return success ? EXIT_SUCCESS : EXIT_FAILURE; +}