diff options
author | Marco Poletti <poletti.marco@gmail.com> | 2018-09-15 11:37:23 +0100 |
---|---|---|
committer | Marco Poletti <poletti.marco@gmail.com> | 2018-09-15 11:38:18 +0100 |
commit | 7d6f051e9ea9a71b4271c330d3f60ab59a1598e5 (patch) | |
tree | 2a0f3ebc82737fa7c08c748ae82f25b4fea0264c | |
parent | beb5515170c7834b77206ab502857d592cb9e937 (diff) | |
download | google-fruit-7d6f051e9ea9a71b4271c330d3f60ab59a1598e5.tar.gz |
Some improvements to the Conan packaging, in preparation for publishing Conan binaries.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | conanfile.py | 57 | ||||
-rw-r--r-- | test_package/CMakeLists.txt | 14 | ||||
-rw-r--r-- | test_package/conanfile.py | 25 | ||||
-rw-r--r-- | test_package/example.cpp | 14 |
6 files changed, 102 insertions, 13 deletions
@@ -6,6 +6,7 @@ bench_results .idea *.pyc /build* +/test_package/build /cmake-build-debug /cmake-build-release /.vs diff --git a/CMakeLists.txt b/CMakeLists.txt index d77de0c..20e5ba0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,9 @@ set(FRUIT_USES_BOOST TRUE CACHE BOOL "Whether to use Boost (specifically, boost::unordered_set and boost::unordered_map). If this is false, Fruit will use std::unordered_set and std::unordered_map instead (however this causes injection to be a bit slower).") -if("${WIN32}" AND "${FRUIT_USES_BOOST}") +set(FRUIT_IS_BEING_BUILT_BY_CONAN FALSE CACHE BOOL "This is set in Conan builds.") + +if("${WIN32}" AND "${FRUIT_USES_BOOST}" AND NOT "${FRUIT_IS_BEING_BUILT_BY_CONAN}") set(BOOST_DIR "" CACHE PATH "The directory where the boost library is installed, e.g. C:\\boost\\boost_1_62_0.") if("${BOOST_DIR}" STREQUAL "") message(FATAL_ERROR "Please re-run CMake, specifying the boost library path as BOOST_DIR, e.g. -DBOOST_DIR=C:\\boost\\boost_1_62_0, or specify -DFRUIT_USES_BOOST=False to not use boost.") diff --git a/conanfile.py b/conanfile.py index 8663191..001bcd0 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,4 +1,5 @@ from conans import ConanFile, CMake, tools +from conans.errors import ConanException class FruitConan(ConanFile): @@ -8,30 +9,62 @@ class FruitConan(ConanFile): url = "https://github.com/google/fruit" description = "C++ dependency injection framework" settings = "os", "compiler", "build_type", "arch" - options = {"shared": [True, False]} - default_options = "shared=False" + options = {"shared": [True, False], "use_boost": [True, False]} + default_options = "shared=False", "use_boost=True" generators = "cmake" + def configure(self): + min_version = { + "gcc": "5", + "clang": "3.5", + "apple-clang": "7.3", + "Visual Studio": "14", # MSVC 2015 + }.get(str(self.settings.compiler)) + if not min_version: + # Unknown minimum version, let's try going ahead with the build to see if it works. + return + if str(self.settings.compiler.version) < min_version: + raise ConanException("%s %s is not supported, must be at least %s" % (self.settings.compiler, + self.settings.compiler.version, + min_version)) + + def requirements(self): + if self.options.use_boost: + self.requires("boost/1.68.0@conan/stable") + def source(self): self.run("git clone https://github.com/google/fruit") - self.run("cd fruit && git checkout v3.4.0") + self.run("cd fruit && git checkout v%s" % self.version) + # This small hack might be useful to guarantee proper /MT /MD linkage + # in MSVC if the packaged project doesn't have variables to set it + # properly + tools.replace_in_file("fruit/CMakeLists.txt", "project(Fruit)", + '''PROJECT(Myfruit) +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup()''') def build(self): cmake = CMake(self) - if self.options.shared: - cmake.definitions["BUILD_SHARED_LIBS"] = "YES" - else: - cmake.definitions["BUILD_SHARED_LIBS"] = "NO" - cmake.definitions["FRUIT_USES_BOOST"] = "NO" - cmake.definitions["RUN_TESTS_UNDER_VALGRIND"] = "NO" - cmake.definitions["FRUIT_TESTS_USE_PRECOMPILED_HEADERS"] = "NO" - cmake.definitions["FRUIT_ENABLE_COVERAGE"] = "NO" + cmake.definitions["FRUIT_IS_BEING_BUILT_BY_CONAN"] = "YES" + cmake.definitions["BUILD_SHARED_LIBS"] = "YES" if self.options.shared else "NO" + if not self.options.use_boost: + cmake.definitions["FRUIT_USES_BOOST"] = "NO" + if self.settings.os == "Windows": + cmake.definitions["FRUIT_TESTS_USE_PRECOMPILED_HEADERS"] = "NO" cmake.configure(source_folder="fruit") cmake.build() cmake.install() def package(self): - pass + self.copy("*.h", dst="include", src="include") + self.copy("*.h", dst="include", src="fruit/include") + self.copy("*fruit.lib", dst="lib", keep_path=False) + self.copy("*.dll", dst="bin", keep_path=False) + self.copy("*.so", dst="lib", keep_path=False) + self.copy("*.dylib", dst="lib", keep_path=False) + self.copy("*.a", dst="lib", keep_path=False) + tools.save("LICENSE", tools.load("COPYING")) + self.copy("COPYING", dst="licenses", ignore_case=True, keep_path=False) def package_info(self): self.cpp_info.libs = ["fruit"] diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..ad6dc6e --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8.12) +project(PackageTest CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(example example.cpp) +target_link_libraries(example ${CONAN_LIBS}) + +# 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..38f0fc4 --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,25 @@ +import os + +from conans import ConanFile, CMake, tools + + +class FruitTestConan(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) diff --git a/test_package/example.cpp b/test_package/example.cpp new file mode 100644 index 0000000..14658b5 --- /dev/null +++ b/test_package/example.cpp @@ -0,0 +1,14 @@ +#include <fruit/fruit.h> + +struct X { + INJECT(X()) = default; +}; + +fruit::Component<X> getXComponent() { + return fruit::createComponent(); +} + +int main() { + fruit::Injector<X> injector(getXComponent); + injector.get<X*>(); +} |