Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Conandata with Development flow #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions features/package_development_flow_conandata/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8)
project(HelloWorld)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("hello")
17 changes: 17 additions & 0 deletions features/package_development_flow_conandata/build.bat
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions features/package_development_flow_conandata/build.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions features/package_development_flow_conandata/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0":
sha256: 07035d79713b5c1499cc4167701dc997da6ea8fcee170aecd08c68dd176c55d3
url: https://github.com/conan-io/hello/archive/7160a88d4f4b0a7282b599ad5161e598d7d7993b.zip
54 changes: 54 additions & 0 deletions features/package_development_flow_conandata/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from conans import ConanFile, CMake, tools
import os


class HelloConan(ConanFile):
name = "Hello"
version = "1.0"
license = "<Put the package license here>"
author = "<Put your name here> <And your email here>"
url = "<Package recipe repository url here, for issues about the package>"
description = "<Description of Hello here>"
topics = ("<Put some tag here>", "<here>", "<and here>")
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"]
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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/<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):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
#include "hello.h"

int main() {
hello();
}