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

coin-cgl: add 0.60.6 + conan v2 support #15838

Merged
merged 3 commits into from
Apr 2, 2023
Merged
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
10 changes: 7 additions & 3 deletions recipes/coin-cgl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
sources:
"0.60.6":
url: "https://github.com/coin-or/Cgl/archive/refs/tags/releases/0.60.6.tar.gz"
sha256: "9e2c51ffad816ab408763d6b931e2a3060482ee4bf1983148969de96d4b2c9ce"
"0.60.3":
url: "https://github.com/coin-or/Cgl/archive/releases/0.60.3.tar.gz"
url: "https://github.com/coin-or/Cgl/archive/refs/tags/releases/0.60.3.tar.gz"
sha256: "cfeeedd68feab7c0ce377eb9c7b61715120478f12c4dd0064b05ad640e20f3fb"
patches:
"0.60.6":
- patch_file: "patches/0.60.6-0001-no-pkg-config-check.patch"
"0.60.3":
- patch_file: "patches/0001-no-pkg-config-check.patch"
base_path: "source_subfolder"
- patch_file: "patches/0.60.3-0001-no-pkg-config-check.patch"
173 changes: 84 additions & 89 deletions recipes/coin-cgl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import rename, get, apply_conandata_patches, rmdir
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, 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, msvc_runtime_flag, unix_path
import os
import shutil

required_conan_version = ">=1.47.0"
required_conan_version = ">=1.57.0"


class CoinCglConan(ConanFile):
name = "coin-cgl"
description = "COIN-OR Cut Generator Library"
topics = ("cgl", "simplex", "solver", "linear", "programming")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/coin-or/Cgl"
license = ("EPL-2.0",)
license = "EPL-2.0"
package_type = "library"
settings = "os", "arch", "build_type", "compiler"
options = {
"shared": [True, False],
Expand All @@ -26,51 +29,41 @@ class CoinCglConan(ConanFile):
"shared": False,
"fPIC": True,
}
generators = "pkg_config"

_autotools = None

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

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

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
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

def requirements(self):
self.requires("coin-utils/2.11.4")
self.requires("coin-osi/0.108.6")
self.requires("coin-clp/1.17.6")
self.options.rm_safe("fPIC")

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
def layout(self):
basic_layout(self, src_folder="src")

@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)
def requirements(self):
self.requires("coin-utils/2.11.6")
self.requires("coin-osi/0.108.7")
self.requires("coin-clp/1.17.7")

def build_requirements(self):
self.tool_requires("gnu-config/cci.20201022")
self.tool_requires("pkgconf/1.7.4")
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.tool_requires("msys2/cci.latest")
if self.settings.compiler == "Visual Studio":
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 validate(self):
if self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration("coin-cgl does not support shared builds on Windows")
Expand All @@ -79,70 +72,72 @@ def validate(self):
raise ConanInvalidConfiguration("coin-cgl shared not supported yet when cross-building")

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

@contextmanager
def _build_context(self):
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)),
get(self, **self.conan_data["sources"][self.version], strip_root=True)

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

tc = AutotoolsToolchain(self)
tc.configure_args.extend([
"--without-blas",
"--without-lapack",
]
if self.settings.compiler == "Visual Studio":
self._autotools.cxx_flags.append("-EHsc")
configure_args.append(f"--enable-msvc={self.settings.compiler.runtime}")
if Version(self.settings.compiler.version) >= 12:
self._autotools.flags.append("-FS")
self._autotools.configure(configure_dir=os.path.join(self.source_folder, self._source_subfolder), args=configure_args)
return self._autotools
])
if is_msvc(self):
tc.extra_cxxflags.append("-EHsc")
tc.configure_args.append(f"--enable-msvc={msvc_runtime_flag(self)}")
if 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)
Comment on lines +104 to +108
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcar87 There's some suspicious code 🏫

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related issue (for coin-osi): conan-io/conan#13098

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")
with self._build_context():
autotools = self._configure_autotools()
autotools.install()

os.unlink(os.path.join(self.package_folder, "lib", "libCgl.la"))

if self.settings.compiler == "Visual Studio":
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
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"))
fix_apple_shared_install_name(self)
if is_msvc(self):
rename(self,
os.path.join(self.package_folder, "lib", "libCgl.a"),
os.path.join(self.package_folder, "lib", "Cgl.lib"))

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "cgl")
self.cpp_info.libs = ["Cgl"]
self.cpp_info.includedirs.append(os.path.join("include", "coin"))
self.cpp_info.names["pkg_config"] = "cgl"
13 changes: 13 additions & 0 deletions recipes/coin-cgl/all/patches/0.60.6-0001-no-pkg-config-check.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- Cgl/Makefile.in
+++ Cgl/Makefile.in
@@ -894,8 +894,8 @@

install-data-hook:
@$(mkdir_p) "$(addlibsdir)"
-@COIN_HAS_PKGCONFIG_TRUE@ PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@:$(DESTDIR)$(pkgconfiglibdir) \
-@COIN_HAS_PKGCONFIG_TRUE@ $(PKG_CONFIG) --libs cgl > $(addlibsdir)/cgl_addlibs.txt
+@COIN_HAS_PKGCONFIG_TRUE@ #PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@:$(DESTDIR)$(pkgconfiglibdir) \
+@COIN_HAS_PKGCONFIG_TRUE@ #$(PKG_CONFIG) --libs cgl > $(addlibsdir)/cgl_addlibs.txt
@COIN_CXX_IS_CL_TRUE@@COIN_HAS_PKGCONFIG_FALSE@ echo "-libpath:`$(CYGPATH_W) @abs_lib_dir@` libCgl.lib @CGLLIB_LIBS_INSTALLED@" > $(addlibsdir)/cgl_addlibs.txt
@COIN_CXX_IS_CL_FALSE@@COIN_HAS_PKGCONFIG_FALSE@ echo -L@abs_lib_dir@ -lCgl @CGLLIB_LIBS_INSTALLED@ > $(addlibsdir)/cgl_addlibs.txt

10 changes: 3 additions & 7 deletions recipes/coin-cgl/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(Cgl REQUIRED IMPORTED_TARGET cgl)

add_executable(${PROJECT_NAME} test_package.cpp)
Expand Down
24 changes: 17 additions & 7 deletions recipes/coin-cgl/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
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", "compiler", "build_type", "arch"
generators = "cmake", "pkg_config"
settings = "os", "arch", "compiler", "build_type"
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")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/coin-cgl/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)
20 changes: 20 additions & 0 deletions recipes/coin-cgl/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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")
self.run(bin_path, run_environment=True)
2 changes: 2 additions & 0 deletions recipes/coin-cgl/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"0.60.6":
folder: "all"
"0.60.3":
folder: "all"