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

wil: recipe added #16701

Merged
merged 19 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions recipes/wil/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.230202.1":
url: "https://github.com/microsoft/wil/archive/refs/tags/v1.0.230202.1.tar.gz"
sha256: "7bf01e9d93fb93f0fe2614492fac4a423b3a97b435015db74f5ac4a0270ebc8a"
105 changes: 105 additions & 0 deletions recipes/wil/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os


required_conan_version = ">=1.52.0"


class WilConan(ConanFile):
name = "wil"
description = (
"The Windows Implementation Libraries (WIL) is a header-only C++ library"
"created to make life easier for developers on Windows through readable"
"type-safe C++ interfaces for common Windows coding patterns."
)
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/microsoft/wil"
topics = ("win", "wil", "header-only")
package_type = "header-library"
# only arch is aplicable, windows library
settings = "os", "arch", "compiler", "build_type"
# Do not copy sources to build folder for header only projects, unless you need to apply patches
no_copy_source = True

@property
def _min_cppstd(self):
return 11

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "15",
"msvc": "14.1",
"gcc": "5",
"clang": "5",
"apple-clang": "5.1",
}

# About compiler version: https://github.com/microsoft/wil/issues/207#issuecomment-991722592
def export_sources(self):
export_conandata_patches(self)
Comment on lines +41 to +43
Copy link
Contributor

Choose a reason for hiding this comment

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

why this comment is attached to export_sources?


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

# same package ID for any package
def package_id(self):
self.info.clear()

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
# Validate the minimum cpp standard supported when installing the package. For C++ projects only
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

if self.settings.os != "Windows":
raise ConanInvalidConfiguration(f"{self.ref} can be used only on Windows.")

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

def build(self):
apply_conandata_patches(self)

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(
self,
pattern="*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"),
)

def package_info(self):
# Folders not used for header-only
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []

# Set these to the appropriate values if the package has an official FindPACKAGE.cmake
# listed in https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules
# examples: bzip2, freetype, gdal, icu, libcurl, libjpeg, libpng, libtiff, openssl, sqlite3, zlib...
self.cpp_info.set_property("cmake_module_file_name", "WIL")
self.cpp_info.set_property("cmake_module_target_name", "WIL::WIL")
# Set these to the appropriate values if package provides a CMake config file
# (package-config.cmake or packageConfig.cmake, with package::package target, usually installed in <prefix>/lib/cmake/<package>/)
self.cpp_info.set_property("cmake_file_name", "wil")
self.cpp_info.set_property("cmake_target_name", "wil::wil")
# Set this to the appropriate value if the package provides a pkgconfig file
# (package.pc, usually installed in <prefix>/lib/pkgconfig/)
self.cpp_info.set_property("pkg_config_name", "wil")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "WIL"
self.cpp_info.filenames["cmake_find_package_multi"] = "wil"
self.cpp_info.names["cmake_find_package"] = "WIL"
self.cpp_info.names["cmake_find_package_multi"] = "WIL"
10 changes: 10 additions & 0 deletions recipes/wil/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(wil REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE wil::wil)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
27 changes: 27 additions & 0 deletions recipes/wil/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


# It will become the standard on Conan 2.x
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

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

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/wil/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <cstdlib>
#include <iostream>
#include "wil/resource.h"


int main(void) {
std::cout << "wil/resource.h included correctly" << std::endl;

return EXIT_SUCCESS;
}
8 changes: 8 additions & 0 deletions recipes/wil/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.8)
project(test_package LANGUAGES CXX)

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

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


# legacy validation with Conan 1.x
class TestPackageV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
3 changes: 3 additions & 0 deletions recipes/wil/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.230202.1":
folder: "all"