| build/* | build/* | ||||
| test_package/build/* |
| from conans import ConanFile, CMake | |||||
| class ScopeguardConan(ConanFile): | |||||
| name = "scope-guard" | |||||
| version = "v0.3.4" | |||||
| license = "MIT" | |||||
| author = "offa <offa@github>" | |||||
| url = "https://github.com.offa/scope-guard" | |||||
| description = "Implementation of Scoped Guards and Unique Resource as proposed in P0052." | |||||
| homepage = "https://github.com/offa/scope-guard" | |||||
| topics = ("cpp", "cpp17", "p0052", "scope-guard", | |||||
| "scope-exit", "scope-fail", "scope-success", "unique-resource", "cmake") | |||||
| no_copy_source = True | |||||
| _source_dir = "{}-{}".format(name, version) | |||||
| scm = { | |||||
| "type": "git", | |||||
| "subfolder": _source_dir, | |||||
| "url": "{}.git".format(homepage), | |||||
| "revision": version | |||||
| } | |||||
| requires = ( | |||||
| "Catch2/2.11.0@catchorg/stable", | |||||
| "trompeloeil/v35@rollbear/stable" | |||||
| ) | |||||
| options = { | |||||
| "unittest": ["ON", "OFF"], | |||||
| "enable_compat_header": ["ON", "OFF"] | |||||
| } | |||||
| default_options = ( | |||||
| "unittest=ON", | |||||
| "enable_compat_header=OFF" | |||||
| ) | |||||
| def _configure_cmake(self): | |||||
| cmake = CMake(self) | |||||
| cmake.definitions["UNITTEST"] = self.options.unittest | |||||
| cmake.definitions["ENABLE_COMPAT_HEADER"] = self.options.enable_compat_header | |||||
| cmake.configure(source_folder=self._source_dir, build_folder="build") | |||||
| return cmake | |||||
| def package(self): | |||||
| cmake = self._configure_cmake() | |||||
| cmake.install() |
| [requires] | |||||
| Catch2/2.9.2@catchorg/stable | |||||
| trompeloeil/v35@rollbear/stable | |||||
| [generators] | |||||
| cmake_find_package | |||||
| cmake_paths | |||||
| # Conan | # Conan | ||||
| apt-get install -y python3-pip | apt-get install -y python3-pip | ||||
| pip3 install conan | pip3 install conan | ||||
| conan profile new default --detect | |||||
| if [[ "${CXX}" == clang* ]] | if [[ "${CXX}" == clang* ]] | ||||
| then | then | ||||
| export CXXFLAGS="-stdlib=libc++" | export CXXFLAGS="-stdlib=libc++" | ||||
| CONAN_STDLIB=libc++ | |||||
| else | else | ||||
| CONAN_STDLIB=libstdc++11 | |||||
| conan profile update settings.compiler.libcxx=libstdc++11 default | |||||
| fi | fi | ||||
| mkdir build && cd build | mkdir build && cd build | ||||
| conan install -s compiler.libcxx=${CONAN_STDLIB} .. | |||||
| conan install \ | |||||
| -g cmake_find_package \ | |||||
| -g cmake_paths \ | |||||
| .. | |||||
| cmake .. | cmake .. | ||||
| make | make |
| cmake_minimum_required(VERSION 3.11) | |||||
| project(PackageTest CXX) | |||||
| set(CMAKE_CXX_STANDARD 17) | |||||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | |||||
| set(CMAKE_CXX_EXTENSIONS OFF) | |||||
| include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | |||||
| conan_basic_setup() | |||||
| add_executable(example example.cpp) | |||||
| target_link_libraries(example ${CONAN_LIBS}) | |||||
| import os | |||||
| from conans import ConanFile, CMake, tools | |||||
| class ScopeguardTestConan(ConanFile): | |||||
| settings = "os", "compiler", "build_type", "arch" | |||||
| generators = "cmake" | |||||
| def build(self): | |||||
| cmake = CMake(self) | |||||
| # Current dir is "test_package/build/<build_id>" 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) |
| #include <iostream> | |||||
| #include <scope.h> | |||||
| int main() | |||||
| { | |||||
| sr::scope_exit se{[]{}}; | |||||
| sr::scope_fail sf{[]{}}; | |||||
| sr::scope_success ss{[]{}}; | |||||
| sr::unique_resource ur{3, [](auto x){}}; | |||||
| return 0; | |||||
| } |