-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
95 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,82 @@ | ||
import os | ||
|
||
from conans import ConanFile, CMake, tools | ||
from os import path | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMake | ||
from conan.tools.env import VirtualRunEnv | ||
from conan.tools.files import load | ||
|
||
|
||
class LibCosimCConan(ConanFile): | ||
# Basic package info | ||
name = "libcosimc" | ||
|
||
def set_version(self): | ||
self.version = load(self, os.path.join(self.recipe_folder, "version.txt")).strip() | ||
|
||
# Metadata | ||
license = "MPL-2.0" | ||
author = "osp" | ||
exports = "version.txt" | ||
scm = { | ||
"type": "git", | ||
"url": "auto", | ||
"revision": "auto" | ||
} | ||
description = "A C wrapper for libcosim, a co-simulation library for C++" | ||
|
||
# Binary configuration | ||
package_type = "library" | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "virtualrunenv" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
} | ||
default_options = { | ||
"shared": True, | ||
"fPIC": True, | ||
} | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
self.options["*"].shared = self.options.shared | ||
|
||
# Dependencies/requirements | ||
tool_requires = "cmake/[>=3.15]" | ||
requires = ( | ||
"libcosim/0.10.2@osp/stable" | ||
) | ||
"boost/[>=1.71.0]", | ||
"libcosim/0.11.0@osp/testing-feature_conan-2", | ||
) | ||
|
||
def set_version(self): | ||
self.version = tools.load(path.join(self.recipe_folder, "version.txt")).strip() | ||
# Exports | ||
exports = "version.txt" | ||
exports_sources = "*" | ||
|
||
def imports(self): | ||
binDir = os.path.join("output", str(self.settings.build_type).lower(), "bin") | ||
self.copy("*.dll", dst=binDir, keep_path=False) | ||
self.copy("*.pdb", dst=binDir, keep_path=False) | ||
# Build steps | ||
generators = "CMakeDeps", "CMakeToolchain" | ||
|
||
def configure_cmake(self): | ||
def build(self): | ||
cmake = CMake(self) | ||
cmake.definitions["LIBCOSIMC_USING_CONAN"] = "ON" | ||
cmake.configure() | ||
return cmake | ||
|
||
def build(self): | ||
cmake = self.configure_cmake() | ||
cmake.build() | ||
cmake.build(target="doc") | ||
if self._is_tests_enabled(): | ||
env = VirtualRunEnv(self).environment() | ||
env.define("CTEST_OUTPUT_ON_FAILURE", "ON") | ||
with env.vars(self).apply(): | ||
cmake.test() | ||
|
||
# Packaging | ||
def package(self): | ||
cmake = self.configure_cmake() | ||
cmake = CMake(self) | ||
cmake.install() | ||
cmake.build(target="install-doc") | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = [ "cosimc" ] | ||
# Ensure that consumers use our CMake package configuration files | ||
# rather than ones generated by Conan. | ||
self.cpp_info.set_property("cmake_find_mode", "none") | ||
self.cpp_info.builddirs.append(".") | ||
|
||
# Helper functions | ||
def _is_tests_enabled(self): | ||
return os.getenv("LIBCOSIMC_RUN_TESTS_ON_CONAN_BUILD", "False").lower() in ("true", "1") |