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

corrade: migrate to Conan v2 #18855

Merged
merged 10 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 0 additions & 7 deletions recipes/corrade/all/CMakeLists.txt

This file was deleted.

9 changes: 4 additions & 5 deletions recipes/corrade/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ sources:
url: https://github.com/mosra/corrade/archive/v2019.10.tar.gz
patches:
"2020.06":
- base_path: "source_subfolder"
patch_file: "patches/2020.06/0001-emscripten-toolchain.patch"
# patch_type: "portability"
# description: "Remove unnecessary dependency on UseEmscripten"
# source: "https://github.com/mosra/corrade/issues/104"
- patch_file: "patches/2020.06/0001-emscripten-toolchain.patch"
patch_type: "portability"
description: "Remove unnecessary dependency on UseEmscripten"
source: "https://github.com/mosra/corrade/issues/104"
148 changes: 75 additions & 73 deletions recipes/corrade/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from conan.tools.microsoft import is_msvc
from conan.tools.microsoft.visual import vs_ide_version
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import functools
import os

required_conan_version = ">=1.45.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.microsoft.visual import vs_ide_version, check_min_vs
valgur marked this conversation as resolved.
Show resolved Hide resolved

required_conan_version = ">=1.47.0"


class CorradeConan(ConanFile):
name = "corrade"
description = "Corrade is a multiplatform utility library written in C++11/C++14."
topics = ("corrade", "magnum", "filesystem", "console", "environment", "os")
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://magnum.graphics/corrade"
license = "MIT"
topics = ("magnum", "filesystem", "console", "environment", "os")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -38,102 +42,97 @@ class CorradeConan(ConanFile):
"with_utility": True,
}

generators = "cmake"
short_paths = True

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

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

def export_sources(self):
self.copy("CMakeLists.txt")
self.copy("cmake/*")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
copy(self, "cmake/*", src=self.recipe_folder, dst=self.export_sources_folder)
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 validate(self):
if is_msvc(self) and tools.Version(vs_ide_version(self)) < 14:
raise ConanInvalidConfiguration("Corrade requires Visual Studio version 14 or greater")
def layout(self):
cmake_layout(self, src_folder="src")

if not self.options.with_utility and (self.options.with_testsuite or self.options.with_interconnect or self.options.with_pluginmanager):
raise ConanInvalidConfiguration("Component 'utility' is required for 'test_suite', 'interconnect' and 'plugin_manager'")
def validate(self):
check_min_vs(self, 190)
if not self.options.with_utility and (
self.options.with_testsuite or self.options.with_interconnect or self.options.with_pluginmanager
):
raise ConanInvalidConfiguration(
"Component 'utility' is required for 'test_suite', 'interconnect' and 'plugin_manager'"
)

def build_requirements(self):
if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True):
self.build_requires("corrade/{}".format(self.version))
if hasattr(self, "settings_build") and cross_building(self, skip_x64_x86=True):
self.tool_requires(f"corrade/{self.version}")

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

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["BUILD_STATIC"] = not self.options.shared
cmake.definitions["BUILD_STATIC_PIC"] = self.options.get_safe("fPIC", False)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_STATIC"] = not self.options.shared
tc.variables["BUILD_STATIC_PIC"] = self.options.get_safe("fPIC", False)

cmake.definitions["BUILD_DEPRECATED"] = self.options.build_deprecated
cmake.definitions["WITH_INTERCONNECT"] = self.options.with_interconnect
cmake.definitions["WITH_MAIN"] = self.options.with_main
cmake.definitions["WITH_PLUGINMANAGER"] = self.options.with_pluginmanager
cmake.definitions["WITH_TESTSUITE"] = self.options.with_testsuite
cmake.definitions["WITH_UTILITY"] = self.options.with_utility
cmake.definitions["WITH_RC"] = self.options.with_utility
tc.variables["BUILD_DEPRECATED"] = self.options.build_deprecated
tc.variables["WITH_INTERCONNECT"] = self.options.with_interconnect
tc.variables["WITH_MAIN"] = self.options.with_main
tc.variables["WITH_PLUGINMANAGER"] = self.options.with_pluginmanager
tc.variables["WITH_TESTSUITE"] = self.options.with_testsuite
tc.variables["WITH_UTILITY"] = self.options.with_utility
tc.variables["WITH_RC"] = self.options.with_utility

# Corrade uses suffix on the resulting "lib"-folder when running cmake.install()
# Set it explicitly to empty, else Corrade might set it implicitly (eg. to "64")
cmake.definitions["LIB_SUFFIX"] = ""
tc.variables["LIB_SUFFIX"] = ""

if is_msvc(self):
cmake.definitions["MSVC2015_COMPATIBILITY"] = vs_ide_version(self) == "14"
cmake.definitions["MSVC2017_COMPATIBILITY"] = vs_ide_version(self) == "15"
cmake.definitions["MSVC2019_COMPATIBILITY"] = vs_ide_version(self) == "16"

cmake.configure(build_folder=self._build_subfolder)
tc.variables["MSVC2015_COMPATIBILITY"] = vs_ide_version(self) == "14"
tc.variables["MSVC2017_COMPATIBILITY"] = vs_ide_version(self) == "15"
tc.variables["MSVC2019_COMPATIBILITY"] = vs_ide_version(self) in ("16", "17")

return cmake
tc.generate()
tc = CMakeDeps(self)
tc.generate()
Comment on lines +101 to +102
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't hurt but it's useless since there is no requirements


def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

share_cmake = os.path.join(self.package_folder, "share", "cmake", "Corrade")
self.copy("UseCorrade.cmake", src=share_cmake, dst=os.path.join(self.package_folder, "lib", "cmake"))
self.copy("CorradeLibSuffix.cmake", src=share_cmake, dst=os.path.join(self.package_folder, "lib", "cmake"))
self.copy("*.cmake", src=os.path.join(self.source_folder, "cmake"), dst=os.path.join("lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "share"))
copy(self, "UseCorrade.cmake",
src=share_cmake,
dst=os.path.join(self.package_folder, "lib", "cmake"))
copy(self, "CorradeLibSuffix.cmake",
src=share_cmake,
dst=os.path.join(self.package_folder, "lib", "cmake"))
copy(self, "*.cmake",
src=os.path.join(self.export_sources_folder, "cmake"),
dst=os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "Corrade")
self.cpp_info.names["cmake_find_package"] = "Corrade"
self.cpp_info.names["cmake_find_package_multi"] = "Corrade"
self.cpp_info.set_property("cmake_target_name", "Corrade::Corrade")

suffix = "-d" if self.settings.build_type == "Debug" else ""

# The FindCorrade.cmake file provided by the library populates some extra stuff
self.cpp_info.set_property("cmake_build_modules", [os.path.join("lib", "cmake", "conan-corrade-vars.cmake")])
self.cpp_info.components["_corrade"].build_modules.append(os.path.join("lib", "cmake", "conan-corrade-vars.cmake"))
cmake_mod = os.path.join("lib", "cmake", "conan-corrade-vars.cmake")
self.cpp_info.set_property("cmake_build_modules", [cmake_mod])
self.cpp_info.components["_corrade"].build_modules["cmake_find_package"].append(cmake_mod)
self.cpp_info.components["_corrade"].build_modules["cmake_find_package_multi"].append(cmake_mod)

if self.options.with_main:
self.cpp_info.components["main"].set_property("cmake_target_name", "Corrade::Main")
Expand All @@ -153,10 +152,10 @@ def package_info(self):
self.cpp_info.components["utility"].requires = ["_corrade"]

# This one is statically linked into utility
#self.cpp_info.components["containers"].set_property("cmake_target_name", "Corrade::Containers")
#self.cpp_info.components["containers"].names["cmake_find_package"] = "Containers"
#self.cpp_info.components["containers"].names["cmake_find_package_multi"] = "Containers"
#self.cpp_info.components["containers"].libs = ["CorradeContainers" + suffix]
# self.cpp_info.components["containers"].set_property("cmake_target_name", "Corrade::Containers")
# self.cpp_info.components["containers"].names["cmake_find_package"] = "Containers"
# self.cpp_info.components["containers"].names["cmake_find_package_multi"] = "Containers"
# self.cpp_info.components["containers"].libs = ["CorradeContainers" + suffix]

if self.options.with_interconnect:
self.cpp_info.components["interconnect"].set_property("cmake_target_name", "Corrade::Interconnect")
Expand All @@ -181,9 +180,12 @@ def package_info(self):

if self.options.with_utility:
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.output.info(f"Appending PATH environment variable: {bindir}")
self.env_info.PATH.append(bindir)

# pkg_config: Add more explicit naming to generated files (avoid filesystem collision).
for key, cmp in self.cpp_info.components.items():
self.cpp_info.components[key].names["pkg_config"] = "{}_{}".format(self.name, key)
self.cpp_info.components[key].set_property("pkg_config_name", f"{self.name}_{key}")

self.cpp_info.names["cmake_find_package"] = "Corrade"
self.cpp_info.names["cmake_find_package_multi"] = "Corrade"
11 changes: 4 additions & 7 deletions recipes/corrade/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

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

find_package(Corrade REQUIRED)
find_package(Corrade REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} Corrade::Main)
if(VERSION_2019_10)
if(VERSION_2019_10)
target_compile_definitions(${PROJECT_NAME} PRIVATE VERSION_2019_10)
endif()
if(WITH_UTILITY)
Expand Down
39 changes: 24 additions & 15 deletions recipes/corrade/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

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

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["WITH_UTILITY"] = self.dependencies["corrade"].options.with_utility
if self.dependencies["corrade"].ref.version == "2019.10":
tc.variables["VERSION_2019_10"] = True
tc.generate()

def build(self):
cmake = CMake(self)
cmake.definitions["WITH_UTILITY"] = self.options["corrade"].with_utility
if self.deps_cpp_info["corrade"].version == "2019.10":
cmake.definitions["VERSION_2019_10"] = True
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 self.options["corrade"].with_utility:
# Run corrade-rc
self.run("corrade-rc --help", run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")

if self.settings.os == "Emscripten":
bin_path = os.path.join("bin", "test_package.js")
self.run("node {}".format(bin_path), run_environment=True)
bin_path = os.path.join(self.cpp.build.bindir, "test_package.js")
self.run(f"node {bin_path}", env="conanrun")
6 changes: 3 additions & 3 deletions recipes/corrade/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <iostream>
#include <Corrade/Corrade.h> // Here it is 'nothing'
#include <Corrade/Corrade.h> // Here it is 'nothing'

#ifndef VERSION_2019_10
#include <Corrade/version.h>
Expand All @@ -9,10 +8,11 @@
#include <Corrade/Utility/Debug.h>
#endif

#include <iostream>

int main() {
std::cout << "Test package for Corrade\n";

#ifndef VERSION_2019_10
std::cout << "Corrade " << CORRADE_VERSION_YEAR << "." << CORRADE_VERSION_MONTH << std::endl;
#endif
Expand Down