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

proposing example for new virtualenvs #90

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
57 changes: 57 additions & 0 deletions features/environment/buildrunenv/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from conans import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake


class HelloConan(ConanFile):
name = "hello"
version = "0.1"

# Optional metadata
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>")

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "src/*"

requires = "openssl/1.1.1k"
build_requires = "cmake/3.19.8"

def build_requirements(self):
self.build_requires("gtest/1.11.0", force_host_context=True)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def layout(self):
self.folders.source = "src"
self.folders.build = "build/{}".format(self.settings.build_type)
self.folders.generators = "build/generators"

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("*.h", dst="include")
self.copy("*.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.dylib*", dst="lib", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)

def package_info(self):
self.cpp_info.libs = ["hello"]
6 changes: 6 additions & 0 deletions features/environment/buildrunenv/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.15)
project(hello CXX)

message(STATUS "CMAKE VERSION = ${CMAKE_VERSION}!!!")

add_library(hello hello.cpp)
14 changes: 14 additions & 0 deletions features/environment/buildrunenv/src/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include "hello.h"

void hello(){
std::cout << hello_str();
}

std::string hello_str(){
#ifdef NDEBUG
return "hello/0.1: Hello World Release!\n";
#else
return "hello/0.1: Hello World Debug!\n";
#endif
}
12 changes: 12 additions & 0 deletions features/environment/buildrunenv/src/hello.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <string>

#ifdef WIN32
#define hello_EXPORT __declspec(dllexport)
#else
#define hello_EXPORT
#endif

hello_EXPORT void hello();
hello_EXPORT std::string hello_str();
10 changes: 10 additions & 0 deletions features/environment/buildrunenv/src/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>
#include "hello.h"

void hello(){
#ifdef NDEBUG
std::cout << "hello/0.1: Hello World Release!" <<std::endl;
#else
std::cout << "hello/0.1: Hello World Debug!" <<std::endl;
#endif
}
14 changes: 14 additions & 0 deletions features/environment/buildrunenv/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

# TODO: Remove this when layouts are available
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

find_package(hello CONFIG REQUIRED)

add_executable(example example.cpp)
target_link_libraries(example hello::hello)
19 changes: 19 additions & 0 deletions features/environment/buildrunenv/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

from conans import ConanFile, tools
from conan.tools.cmake import CMake


class HelloTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv"
apply_env = False

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
self.run(os.path.sep.join([".", "bin", "example"]), env="conanrunenv")
5 changes: 5 additions & 0 deletions features/environment/buildrunenv/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "hello.h"

int main() {
hello();
}