From 244bbafc9cdf704d96393c36c5fc3c2d6ff8eb1f Mon Sep 17 00:00:00 2001 From: Joel Falcou Date: Fri, 10 Apr 2020 21:18:34 +0200 Subject: [PATCH] Add CONAN support (#8) SPY is now supporting Conan Package --- conanfile.py | 26 ++++++++++++++++++++++++++ docs/index.html | 30 +++++++++++++++--------------- test_package/CMakeLists.txt | 17 +++++++++++++++++ test_package/conanfile.py | 25 +++++++++++++++++++++++++ test_package/example.cpp | 12 ++++++++++++ 5 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 conanfile.py create mode 100644 test_package/CMakeLists.txt create mode 100644 test_package/conanfile.py create mode 100644 test_package/example.cpp diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..c5bc0db --- /dev/null +++ b/conanfile.py @@ -0,0 +1,26 @@ +import os + +from conans import ConanFile, tools +class SpyConan(ConanFile): + name = "spy" + settings = "os", "compiler", "build_type", "arch" + version = "0.0.3" + license = "MIT" + author = "Joel FALCOU joel.falcou@compilaction.net" + url = "https://github.com/jfalcou/spy.git" + homepage = "https://jfalcou.github.io/spy/" + description = "C++ 17 for constexpr-proof detection and classification of informations about OS, compiler, etc..." + topics = ("c++17", "config", "metaprogramming") + no_copy_source = True + scm = { + "type": "git", + "url": "auto", + "revision": "auto" + } + + def package(self): + self.copy("LICENSE", "licenses") + self.copy("*.hpp") + + def package_id(self): + self.info.header_only() diff --git a/docs/index.html b/docs/index.html index c34ce8e..5c77ad6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -49,7 +49,7 @@ int main() { - std::cout << spy::os << std::endl; + std::cout << spy::operating_system << std::endl; std::cout << spy::architecture << std::endl; std::cout << spy::simd_instruction_set << std::endl; std::cout << spy::compiler << std::endl; @@ -67,7 +67,7 @@ SPY can detect: - Architecture family via the `spy::architecture` object. -- OS vendor via the `spy::os` object. +- OS vendor via the `spy::operating_system` object. - Compiler vendor and version (in the M.N.P format) via the `spy::compiler` object. - libc vendor and version (in the M.N.P format) via the `spy::libc` object. - stdlib vendor and version (in the M.N.P format) via the `spy::stdlib` object. @@ -82,11 +82,11 @@ int main() { - std::cout << spy::os << "\n"; - std::cout << spy::architecture << "\n"; - std::cout << spy::compiler << "\n"; - std::cout << spy::stdlib << "\n"; - std::cout << spy::libc << "\n"; + std::cout << spy::operating_system << "\n"; + std::cout << spy::architecture << "\n"; + std::cout << spy::compiler << "\n"; + std::cout << spy::stdlib << "\n"; + std::cout << spy::libc << "\n"; } ~~~~~ @@ -96,13 +96,13 @@ so you can branch off your code based on this informations. Here is the list of each detected vendor for each SPY objects. -| Detector | Supported vendor | -| ------------------- | ------------------------------------------------------------------------------ | -| `spy::architecture` | `x86_`, `amd64_`, `ppc_`, `arm_` | -| `spy::os` | `android_`, `bsd_`, `cygwin_`, `ios_`, `linux_`, `macos_`, `unix_`, `windows_` | -| `spy::compiler` | `clang_`, `gcc_`, `intel_`, `msvc_` | -| `spy::libc` | `cloudabi_`, `gnu_` `uc_`, `vms_`, `zos_` | -| `spy::stdlib` | `gnucpp_`, `libcpp_` | +| Detector | Supported vendor | +| ----------------------- | ------------------------------------------------------------------------------ | +| `spy::architecture` | `x86_`, `amd64_`, `ppc_`, `arm_` | +| `spy::operating_system` | `android_`, `bsd_`, `cygwin_`, `ios_`, `linux_`, `macos_`, `unix_`, `windows_` | +| `spy::compiler` | `clang_`, `gcc_`, `intel_`, `msvc_` | +| `spy::libc` | `cloudabi_`, `gnu_` `uc_`, `vms_`, `zos_` | +| `spy::stdlib` | `gnucpp_`, `libcpp_` | Here is a sample code comparing some detectors to a specific vendor: @@ -113,7 +113,7 @@ void f() { - if constexpr( spy::os == spy::windows_ ) + if constexpr( spy::operating_system == spy::windows_ ) { std::cout << "This code is Windows only.\n"; } diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..73c5626 --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8.12) +project(PackageTest CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_library(spy_config INTERFACE) +target_compile_features ( spy_config INTERFACE cxx_std_17 ) + +add_executable(example example.cpp) +target_link_libraries(example ${CONAN_LIBS} PUBLIC spy_config) + +# CTest is a testing tool that can be used to test your project. +# enable_testing() +# add_test(NAME example +# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin +# COMMAND example) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..0382a54 --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,25 @@ +import os + +from conans import ConanFile, CMake, tools + + +class SpyTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + # Current dir is "test_package/build/" and CMakeLists.txt is + # in "test_package" + cmake.configure() + cmake.build() + + def imports(self): + self.copy("*.dll", dst="bin", src="bin") + self.copy("*.dylib*", dst="bin", src="lib") + self.copy('*.so*', dst='bin', src='lib') + + def test(self): + if not tools.cross_building(self.settings): + os.chdir("bin") + self.run(".%sexample" % os.sep) diff --git a/test_package/example.cpp b/test_package/example.cpp new file mode 100644 index 0000000..6633150 --- /dev/null +++ b/test_package/example.cpp @@ -0,0 +1,12 @@ +#include +#include + +int main() +{ + std::cout << spy::operating_system << std::endl; + std::cout << spy::architecture << std::endl; + std::cout << spy::simd_instruction_set << std::endl; + std::cout << spy::compiler << std::endl; + std::cout << spy::libc << std::endl; + std::cout << spy::stdlib << std::endl; +}