Skip to content

Commit

Permalink
(conan-io#15836) coin-clp: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* add package_type
  • Loading branch information
SpaceIm authored and 0xFireWolf committed Apr 2, 2023
1 parent bb62300 commit 9450588
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 103 deletions.
16 changes: 7 additions & 9 deletions recipes/coin-clp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
sources:
"1.17.6":
url: "https://github.com/coin-or/Clp/archive/releases/1.17.6.tar.gz"
sha256: "afff465b1620cfcbb7b7c17b5d331d412039650ff471c4160c7eb24ae01284c9"
"1.17.7":
url: "https://github.com/coin-or/Clp/archive/releases/1.17.7.tar.gz"
url: "https://github.com/coin-or/Clp/archive/refs/tags/releases/1.17.7.tar.gz"
sha256: "c4c2c0e014220ce8b6294f3be0f3a595a37bef58a14bf9bac406016e9e73b0f5"
patches:
"1.17.6":
- patch_file: "patches/0001-no-pkg-config-check.patch"
base_path: "source_subfolder"
url: "https://github.com/coin-or/Clp/archive/refs/tags/releases/1.17.6.tar.gz"
sha256: "afff465b1620cfcbb7b7c17b5d331d412039650ff471c4160c7eb24ae01284c9"
patches:
"1.17.7":
- patch_file: "patches/0002-no-pkg-config-check.patch"
base_path: "source_subfolder"
- patch_file: "patches/1.17.7-0001-no-pkg-config-check.patch"
"1.17.6":
- patch_file: "patches/1.17.6-0001-no-pkg-config-check.patch"
153 changes: 74 additions & 79 deletions recipes/coin-clp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import get, apply_conandata_patches, mkdir, rm, rmdir, rename
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.build import cross_building
from conan.tools.scm import Version
from conans import AutoToolsBuildEnvironment, tools
from contextlib import contextmanager
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, mkdir, rename, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain, PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.microsoft import check_min_vs, is_msvc, unix_path
import os
import shutil

required_conan_version = ">=1.50.0"
required_conan_version = ">=1.57.0"


class CoinClpConan(ConanFile):
Expand All @@ -17,7 +18,8 @@ class CoinClpConan(ConanFile):
topics = ("clp", "simplex", "solver", "linear", "programming")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/coin-or/Clp"
license = ("EPL-2.0",)
license = "EPL-2.0"
package_type = "library"
settings = "os", "arch", "build_type", "compiler"
options = {
"shared": [True, False],
Expand All @@ -27,34 +29,24 @@ class CoinClpConan(ConanFile):
"shared": False,
"fPIC": True,
}
exports_sources = "patches/**.patch"
generators = "pkg_config"

_autotools = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)
def export_sources(self):
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires("coin-utils/2.11.6")
Expand All @@ -68,83 +60,86 @@ def validate(self):
raise ConanInvalidConfiguration("coin-clp shared not supported yet when cross-building")

def build_requirements(self):
self.build_requires("gnu-config/cci.20201022")
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
if self.settings.compiler == "Visual Studio":
self.build_requires("automake/1.16.4")
self.build_requires("pkgconf/1.7.4")
self.tool_requires("gnu-config/cci.20210814")
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
self.tool_requires("pkgconf/1.9.3")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")
if is_msvc(self):
self.tool_requires("automake/1.16.5")

def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

@contextmanager
def _build_context(self):
with tools.environment_append({"PKG_CONFIG_PATH": self.install_folder}):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self.settings):
env = {
"CC": "{} cl -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
"CXX": "{} cl -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
"LD": "{} link -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
"AR": "{} lib".format(tools.unix_path(self._user_info_build["automake"].ar_lib)),
}
with tools.environment_append(env):
yield
else:
yield

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
self._autotools.libs = []
yes_no = lambda v: "yes" if v else "no"
configure_args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
]
if self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) >= 12:
self._autotools.flags.append("-FS")
self._autotools.configure(self._source_subfolder, args=configure_args)
return self._autotools
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()

tc = AutotoolsToolchain(self)
if is_msvc(self) and check_min_vs(self, "180", raise_invalid=False):
tc.extra_cflags.append("-FS")
tc.extra_cxxflags.append("-FS")
env = tc.environment()
if is_msvc(self):
compile_wrapper = unix_path(self, self.conf.get("user.automake:compile-wrapper", check_type=str))
ar_wrapper = unix_path(self, self.conf.get("user.automake:lib-wrapper", check_type=str))
env.define("CC", f"{compile_wrapper} cl -nologo")
env.define("CXX", f"{compile_wrapper} cl -nologo")
env.define("LD", f"{compile_wrapper} link -nologo")
env.define("AR", f"{ar_wrapper} \"lib -nologo\"")
env.define("NM", "dumpbin -symbols")
env.define("OBJDUMP", ":")
env.define("RANLIB", ":")
env.define("STRIP", ":")
if self._settings_build.os == "Windows":
# TODO: Something to fix in conan client or pkgconf recipe?
# This is a weird workaround when build machine is Windows. Here we have to inject regular
# Windows path to pc files folder instead of unix path flavor injected by AutotoolsToolchain...
env.define("PKG_CONFIG_PATH", self.generators_folder)
tc.generate(env)

deps = PkgConfigDeps(self)
deps.generate()

def build(self):
apply_conandata_patches(self)
shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB,
os.path.join(self._source_subfolder, "config.sub"))
shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS,
os.path.join(self._source_subfolder, "config.guess"))
with self._build_context():
autotools = self._configure_autotools()
autotools.make()
if not is_msvc(self):
for gnu_config in [
self.conf.get("user.gnu-config:config_guess", check_type=str),
self.conf.get("user.gnu-config:config_sub", check_type=str),
]:
if gnu_config:
copy(self, os.path.basename(gnu_config), src=os.path.dirname(gnu_config), dst=self.source_folder)
autotools = Autotools(self)
autotools.configure()
autotools.make()

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
# Installation script expects include/coin to already exist
mkdir(self, os.path.join(self.package_folder, "include", "coin"))
with self._build_context():
autotools = self._configure_autotools()
autotools.install(args=["-j1"]) # due to configure generated with old autotools version

autotools = Autotools(self)
autotools.install(args=["-j1"])
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
if self.settings.compiler == "Visual Studio":
fix_apple_shared_install_name(self)
if is_msvc(self):
for l in ("Clp", "ClpSolver", "OsiClp"):
rename(self, os.path.join(self.package_folder, "lib", f"lib{l}.a"),
os.path.join(self.package_folder, "lib", f"{l}.lib"))

def package_info(self):
self.cpp_info.components["clp"].set_property("pkg_config_name", "clp")
self.cpp_info.components["clp"].libs = ["ClpSolver", "Clp"]
self.cpp_info.components["clp"].includedirs.append(os.path.join("include", "coin"))
self.cpp_info.components["clp"].names["pkg_config"] = "clp"
self.cpp_info.components["clp"].requires = ["coin-utils::coin-utils"]

self.cpp_info.components["osi-clp"].set_property("pkg_config_name", "osi-clp")
self.cpp_info.components["osi-clp"].libs = ["OsiClp"]
self.cpp_info.components["osi-clp"].names["pkg_config"] = "osi-clp"
self.cpp_info.components["osi-clp"].requires = ["clp", "coin-osi::coin-osi"]

bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)
# TODO: to remove in conan v2
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
10 changes: 3 additions & 7 deletions recipes/coin-clp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

include(FindPkgConfig)
cmake_minimum_required(VERSION 3.6)
project(test_package LANGUAGES CXX)

find_package(PkgConfig REQUIRED)
pkg_check_modules(OsiClp REQUIRED IMPORTED_TARGET osi-clp)

add_executable(${PROJECT_NAME} test_package.cpp)
Expand Down
22 changes: 16 additions & 6 deletions recipes/coin-clp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "pkg_config"
generators = "CMakeToolchain", "PkgConfigDeps", "VirtualBuildEnv", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build_requirements(self):
self.build_requires("pkgconf/1.7.4")
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
self.tool_requires("pkgconf/1.9.3")

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
mps = os.path.join(self.source_folder, "sample.mps")
self.run("{} {}".format(bin_path, mps), run_environment=True)
self.run(f"{bin_path} {mps}", env="conanrun")
8 changes: 8 additions & 0 deletions recipes/coin-clp/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
21 changes: 21 additions & 0 deletions recipes/coin-clp/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "pkg_config"

def build_requirements(self):
self.build_requires("pkgconf/1.9.3")

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
mps = os.path.join(self.source_folder, os.pardir, "test_package", "sample.mps")
self.run(f"{bin_path} {mps}", run_environment=True)
4 changes: 2 additions & 2 deletions recipes/coin-clp/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
versions:
"1.17.6":
folder: "all"
"1.17.7":
folder: "all"
"1.17.6":
folder: "all"

0 comments on commit 9450588

Please sign in to comment.