From 07c98896e3f57b97a2dfe3ad482ed770369cc323 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:32:21 +0100 Subject: [PATCH 1/3] conan v2 support --- recipes/coin-cgl/all/conandata.yml | 1 - recipes/coin-cgl/all/conanfile.py | 168 ++++++++---------- .../coin-cgl/all/test_package/CMakeLists.txt | 10 +- .../coin-cgl/all/test_package/conanfile.py | 24 ++- .../all/test_v1_package/CMakeLists.txt | 8 + .../coin-cgl/all/test_v1_package/conanfile.py | 20 +++ 6 files changed, 127 insertions(+), 104 deletions(-) create mode 100644 recipes/coin-cgl/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/coin-cgl/all/test_v1_package/conanfile.py diff --git a/recipes/coin-cgl/all/conandata.yml b/recipes/coin-cgl/all/conandata.yml index d3e1494065212..c539236e12908 100644 --- a/recipes/coin-cgl/all/conandata.yml +++ b/recipes/coin-cgl/all/conandata.yml @@ -5,4 +5,3 @@ sources: patches: "0.60.3": - patch_file: "patches/0001-no-pkg-config-check.patch" - base_path: "source_subfolder" diff --git a/recipes/coin-cgl/all/conanfile.py b/recipes/coin-cgl/all/conanfile.py index 152335302dd9a..fb0cbcd7f0676 100644 --- a/recipes/coin-cgl/all/conanfile.py +++ b/recipes/coin-cgl/all/conanfile.py @@ -1,14 +1,16 @@ 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" @@ -16,7 +18,8 @@ class CoinCglConan(ConanFile): 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], @@ -26,21 +29,13 @@ 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": @@ -48,29 +43,27 @@ def config_options(self): 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") @@ -79,70 +72,67 @@ 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", ":") + 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" diff --git a/recipes/coin-cgl/all/test_package/CMakeLists.txt b/recipes/coin-cgl/all/test_package/CMakeLists.txt index a0a2ed56424aa..7c4558f1caa45 100644 --- a/recipes/coin-cgl/all/test_package/CMakeLists.txt +++ b/recipes/coin-cgl/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/coin-cgl/all/test_package/conanfile.py b/recipes/coin-cgl/all/test_package/conanfile.py index 9e09e219fdcb3..af1af0ebb3d7f 100644 --- a/recipes/coin-cgl/all/test_package/conanfile.py +++ b/recipes/coin-cgl/all/test_package/conanfile.py @@ -1,13 +1,23 @@ -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) @@ -15,6 +25,6 @@ def build(self): 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") diff --git a/recipes/coin-cgl/all/test_v1_package/CMakeLists.txt b/recipes/coin-cgl/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..0d20897301b68 --- /dev/null +++ b/recipes/coin-cgl/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/coin-cgl/all/test_v1_package/conanfile.py b/recipes/coin-cgl/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..e6b0fdb8110e8 --- /dev/null +++ b/recipes/coin-cgl/all/test_v1_package/conanfile.py @@ -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) From fde010a8b98853e81ac2f3efbd246247292327c5 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Thu, 9 Feb 2023 18:12:12 +0100 Subject: [PATCH 2/3] add 0.60.6 --- recipes/coin-cgl/all/conandata.yml | 9 +++++++-- ....patch => 0.60.3-0001-no-pkg-config-check.patch} | 0 .../patches/0.60.6-0001-no-pkg-config-check.patch | 13 +++++++++++++ recipes/coin-cgl/config.yml | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) rename recipes/coin-cgl/all/patches/{0001-no-pkg-config-check.patch => 0.60.3-0001-no-pkg-config-check.patch} (100%) create mode 100644 recipes/coin-cgl/all/patches/0.60.6-0001-no-pkg-config-check.patch diff --git a/recipes/coin-cgl/all/conandata.yml b/recipes/coin-cgl/all/conandata.yml index c539236e12908..5fc7e9f24039c 100644 --- a/recipes/coin-cgl/all/conandata.yml +++ b/recipes/coin-cgl/all/conandata.yml @@ -1,7 +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" + - patch_file: "patches/0.60.3-0001-no-pkg-config-check.patch" diff --git a/recipes/coin-cgl/all/patches/0001-no-pkg-config-check.patch b/recipes/coin-cgl/all/patches/0.60.3-0001-no-pkg-config-check.patch similarity index 100% rename from recipes/coin-cgl/all/patches/0001-no-pkg-config-check.patch rename to recipes/coin-cgl/all/patches/0.60.3-0001-no-pkg-config-check.patch diff --git a/recipes/coin-cgl/all/patches/0.60.6-0001-no-pkg-config-check.patch b/recipes/coin-cgl/all/patches/0.60.6-0001-no-pkg-config-check.patch new file mode 100644 index 0000000000000..4e3b6ea5ea929 --- /dev/null +++ b/recipes/coin-cgl/all/patches/0.60.6-0001-no-pkg-config-check.patch @@ -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 + diff --git a/recipes/coin-cgl/config.yml b/recipes/coin-cgl/config.yml index f112a543d6350..c588b8cdfa767 100644 --- a/recipes/coin-cgl/config.yml +++ b/recipes/coin-cgl/config.yml @@ -1,3 +1,5 @@ versions: + "0.60.6": + folder: "all" "0.60.3": folder: "all" From c5956e296859cb4c902e4646f72183b64da6912e Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Tue, 28 Mar 2023 22:48:45 +0200 Subject: [PATCH 3/3] fix PKG_CONFIG_PATH on Windows --- recipes/coin-cgl/all/conanfile.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/recipes/coin-cgl/all/conanfile.py b/recipes/coin-cgl/all/conanfile.py index fb0cbcd7f0676..8da58a4cb0487 100644 --- a/recipes/coin-cgl/all/conanfile.py +++ b/recipes/coin-cgl/all/conanfile.py @@ -101,6 +101,11 @@ def generate(self): 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)