diff --git a/README.md b/README.md index e772e374..8016516d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,13 @@ Example how to use Conan commands to develop a package recipe. Documentation: https://docs.conan.io/en/latest/developing_packages/package_dev_flow.html +### [Package development flow with conandata.yml](features/package_development_flow_conandata) + +Example how to use Conan commands to develop a package recipe which requires a conandata.yml. + +Documentation: https://docs.conan.io/en/latest/developing_packages/package_dev_flow.html + https://docs.conan.io/en/latest/reference/config_files/conandata.yml.html + ### [Workspace](features/workspace) Example how to use Conan Workspaces. diff --git a/features/package_development_flow_conandata/CMakeLists.txt b/features/package_development_flow_conandata/CMakeLists.txt new file mode 100644 index 00000000..d6b5772b --- /dev/null +++ b/features/package_development_flow_conandata/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8) +project(HelloWorld) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory("hello") diff --git a/features/package_development_flow_conandata/build.bat b/features/package_development_flow_conandata/build.bat new file mode 100644 index 00000000..e0f7748e --- /dev/null +++ b/features/package_development_flow_conandata/build.bat @@ -0,0 +1,17 @@ +@ECHO ON + +RMDIR /Q /S tmp + +conan source . --source-folder=tmp/source +conan install . --install-folder=tmp/build +conan build . --source-folder=tmp/source --build-folder=tmp/build +conan package . --source-folder=tmp/source --build-folder=tmp/build --package-folder=tmp/package + +REM NOTE: Use --force to prevent ERROR: Package already exists +conan export-pkg . user/testing --source-folder=tmp/source --build-folder=tmp/build --force + +REM You can also test the package that was just exported +conan test test_package Hello/1.0@user/testing + +REM Finally, run a full create, does all of the above + test_package +conan create . user/testing diff --git a/features/package_development_flow_conandata/build.sh b/features/package_development_flow_conandata/build.sh new file mode 100755 index 00000000..49ace031 --- /dev/null +++ b/features/package_development_flow_conandata/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e +set -x + +rm -rf tmp + +conan source . --source-folder=tmp/source +conan install . --install-folder=tmp/build +conan build . --source-folder=tmp/source --build-folder=tmp/build +conan package . --source-folder=tmp/source --build-folder=tmp/build --package-folder=tmp/package + +# NOTE: Use --force to prevent ERROR: Package already exists +conan export-pkg . user/testing --source-folder=tmp/source --build-folder=tmp/build --force + +# You can also test the package that was just exported +conan test test_package Hello/1.0@user/testing + +# Finally, run a full create, does all of the above + test_package +conan create . user/testing diff --git a/features/package_development_flow_conandata/conandata.yml b/features/package_development_flow_conandata/conandata.yml new file mode 100644 index 00000000..37336bbb --- /dev/null +++ b/features/package_development_flow_conandata/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.0": + sha256: 07035d79713b5c1499cc4167701dc997da6ea8fcee170aecd08c68dd176c55d3 + url: https://github.com/conan-io/hello/archive/7160a88d4f4b0a7282b599ad5161e598d7d7993b.zip diff --git a/features/package_development_flow_conandata/conanfile.py b/features/package_development_flow_conandata/conanfile.py new file mode 100644 index 00000000..342f7fdf --- /dev/null +++ b/features/package_development_flow_conandata/conanfile.py @@ -0,0 +1,54 @@ +from conans import ConanFile, CMake, tools +import os + + +class HelloConan(ConanFile): + name = "Hello" + version = "1.0" + license = "" + author = " " + url = "" + description = "" + topics = ("", "", "") + settings = "os", "compiler", "build_type", "arch" + options = {"shared": [True, False]} + default_options = {"shared": False} + exports_sources = "CMakeLists.txt" + generators = "cmake" + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + os.rename("hello-7160a88d4f4b0a7282b599ad5161e598d7d7993b", "hello") + # 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 + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + # Explicit way: + # self.run('cmake %s/hello %s' + # % (self.source_folder, cmake.command_line)) + # self.run("cmake --build . %s" % cmake.build_config) + + def package(self): + # CMake way: + # cmake = CMake(self) + # cmake.configure() + # cmake.install() + + # Explicit way: + # self.run('cmake %s/hello %s' % (self.source_folder, cmake.command_line)) + # self.run("cmake --build . %s --target install" % cmake.build_config) + + self.copy("*.h", dst="include", src="hello") + self.copy("*hello.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) + + def package_info(self): + self.cpp_info.libs = ["hello"] diff --git a/features/package_development_flow_conandata/test_package/CMakeLists.txt b/features/package_development_flow_conandata/test_package/CMakeLists.txt new file mode 100644 index 00000000..ad6dc6eb --- /dev/null +++ b/features/package_development_flow_conandata/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/features/package_development_flow_conandata/test_package/conanfile.py b/features/package_development_flow_conandata/test_package/conanfile.py new file mode 100644 index 00000000..cd8770a6 --- /dev/null +++ b/features/package_development_flow_conandata/test_package/conanfile.py @@ -0,0 +1,25 @@ +import os + +from conans import ConanFile, CMake, tools + + +class HelloTestConan(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): + bin_path = os.path.join("bin", "example") + self.run(bin_path, run_environment=True) diff --git a/features/package_development_flow_conandata/test_package/example.cpp b/features/package_development_flow_conandata/test_package/example.cpp new file mode 100644 index 00000000..4a5549c5 --- /dev/null +++ b/features/package_development_flow_conandata/test_package/example.cpp @@ -0,0 +1,6 @@ +#include +#include "hello.h" + +int main() { + hello(); +}