initial implementation of conan recipe
This commit is contained in:
parent
18a7bb7f8c
commit
f0720ba756
4 changed files with 100 additions and 0 deletions
43
conanfile.py
Normal file
43
conanfile.py
Normal file
|
@ -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 <neargye@gmail.com>'
|
||||
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()
|
11
test_package/CMakeLists.txt
Normal file
11
test_package/CMakeLists.txt
Normal file
|
@ -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)
|
19
test_package/conanfile.py
Normal file
19
test_package/conanfile.py
Normal file
|
@ -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)
|
27
test_package/test_package.cpp
Normal file
27
test_package/test_package.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <nameof.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in a new issue