Skip to content

Commit

Permalink
(conan-io#15069) crowcpp-crow: add version 1.0+5, support conan v2, u…
Browse files Browse the repository at this point in the history
…pdate dependencies

* crowcpp-crow: add version 1.0+5, support conan v2, update dependencies

* remove cmake_verbose_makefile

* fix patch description name

* fix patch_source

* fix urls of 0.2, 0.3

* use `dependencies`

Co-authored-by: Uilian Ries <uilianries@gmail.com>

Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
2 people authored and franramirez688 committed Jan 20, 2023
1 parent b886e31 commit 27ab96e
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 66 deletions.
19 changes: 10 additions & 9 deletions recipes/crowcpp-crow/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.0+5":
url: "https://github.com/CrowCpp/crow/archive/refs/tags/v1.0+5.tar.gz"
sha256: "4eb1b80b97dda4a3c4f613c581c734e0221911c88ff859ed679bda3dd5d7b319"
"1.0+3":
url: "https://github.com/CrowCpp/crow/archive/refs/tags/v1.0+3.tar.gz"
sha256: "509248e7bd30dad725cfb66c383405a8bdc59d1fe7f8f2b464d459444047855e"
Expand All @@ -15,19 +18,17 @@ sources:
url: "https://github.com/CrowCpp/crow/archive/refs/tags/v0.3+2.tar.gz"
sha256: "982fe978c113506aefe77c413befb3ab21fffb09d9bdf287ec8e8ba59bd786e7"
"0.3":
url: "https://github.com/CrowCpp/crow/archive/v0.3.tar.gz"
url: "https://github.com/CrowCpp/Crow/archive/refs/tags/v0.3.tar.gz"
sha256: "95538db88fba73c0bc87bbc40b62dcf488012c133a895634ade015009ebb4f25"
"0.2":
url: "https://github.com/CrowCpp/crow/archive/0.2.tar.gz"
url: "https://github.com/CrowCpp/Crow/archive/refs/tags/0.2.tar.gz"
sha256: "c419767f0a336f2add71fc8b311ad95434d59601fb8b0e5ba3048407d85d0a71"
patches:
"0.2":
- patch_file: "patches/0.2/0001-normalize-buildsystem.patch"
base_path: "source_subfolder"
# patch_type: "conan"
# description: "Skip tests and examples from build"
patch_description: "Skip tests and examples from build"
patch_type: "conan"
- patch_file: "patches/0.2/0002-replace-uint.patch"
base_path: "source_subfolder"
# patch_type: "portability"
# source: "https://github.com/CrowCpp/Crow/commit/5fe3a45793604a50f5c9086909dfa1b50dfa3e88"
# description: "Replace uint (not default type) with unsigned"
patch_description: "Replace uint (not default type) with unsigned"
patch_type: "bugfix"
patch_source: "https://github.com/CrowCpp/Crow/commit/5fe3a45793604a50f5c9086909dfa1b50dfa3e88"
137 changes: 95 additions & 42 deletions recipes/crowcpp-crow/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,135 @@
from conans import ConanFile, tools, CMake
from conan import ConanFile
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.scm import Version
import os

required_conan_version = ">=1.33.0"

required_conan_version = ">=1.52.0"

class CrowConan(ConanFile):
name = "crowcpp-crow"
homepage = "http://crowcpp.org/"
description = "Crow is a C++ microframework for running web services."
topics = ("web", "microframework", "header-only")
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://crowcpp.org/"
topics = ("web", "microframework", "header-only")
settings = "os", "compiler", "arch", "build_type"
license = "BSD-3-Clause"

provides = "crow"

options = {
"amalgamation": [True, False],
"with_ssl": [True, False],
"with_compression": [True, False],
}
default_options = {
"amalgamation": False,
"with_ssl": False,
"with_compression": False,
}

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

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 configure(self):
if Version(self.version) < "1.0":
del self.options.with_ssl
del self.options.with_compression

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

def requirements(self):
self.requires("boost/1.77.0")
self.requires("boost/1.81.0")
if self.version == "0.2":
self.requires("openssl/1.1.1l")
self.requires("openssl/1.1.1s")
if Version(self.version) >= "1.0":
if self.options.with_ssl:
self.requires("openssl/1.1.1s")
if self.options.with_compression:
self.requires("zlib/1.2.13")

def package_id(self):
self.info.settings.clear()

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)

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

def generate(self):
if self.options.amalgamation:
tc = CMakeToolchain(self)
if Version(self.version) < "1.0":
tc.variables["BUILD_EXAMPLES"] = False
tc.variables["BUILD_TESTING"] = False
else:
tc.variables["CROW_BUILD_EXAMPLES"] = False
tc.variables["CROW_BUILD_TESTS"] = False
tc.variables["CROW_AMALGAMATE"] = True
tc.generate()

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

if self.options.amalgamation:
cmake = CMake(self)
cmake.definitions["BUILD_EXAMPLES"] = False
cmake.definitions["BUILD_TESTING"] = False
cmake.configure(source_folder=self._source_subfolder)
cmake.build(target="amalgamation")
cmake.configure()
if Version(self.version) < "1.0":
cmake.build(target="amalgamation")
else:
cmake.build(target="crow_amalgamated")


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

if self.options.amalgamation:
self.copy("crow_all.h", dst="include")
copy(
self,
pattern="crow_all.h",
dst=os.path.join(self.package_folder, "include"),
src=self.build_folder,
)
else:
self.copy(
"*.h",
dst=os.path.join("include"),
src=os.path.join(self._source_subfolder, "include"),
copy(
self,
pattern="*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"),
)
self.copy(
"*.hpp",
dst=os.path.join("include"),
src=os.path.join(self._source_subfolder, "include"),
copy(
self,
pattern="*.hpp",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"),
)

def package_id(self):
self.info.settings.clear()

def package_info(self):
# These are not official targets, this is just the name (without fork prefix)
self.cpp_info.names["cmake_find_package"] = "crow"
self.cpp_info.names["cmake_find_package_multi"] = "crow"
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []

self.cpp_info.requires.append("boost::headers")

if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs = ["pthread"]

self.cpp_info.set_property("cmake_file_name", "Crow")
self.cpp_info.set_property("cmake_target_name", "Crow::Crow")

if Version(self.version) >= "1.0":
if self.options.with_ssl:
self.cpp_info.defines.append("CROW_ENABLE_SSL")
self.cpp_info.requires.append("OpenSSL::ssl")
if self.options.with_compression:
self.cpp_info.defines.append("CROW_ENABLE_COMPRESSION")
self.cpp_info.requires.append("zlib::zlib")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "Crow"
self.cpp_info.names["cmake_find_package_multi"] = "Crow"

13 changes: 5 additions & 8 deletions recipes/crowcpp-crow/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

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

find_package(crow REQUIRED)
find_package(Crow REQUIRED)

option(CROW_AMALGAMATION "CROW IS DEPLOYED AS AMALGAMATION" ON)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} crow::crow)
target_link_libraries(${PROJECT_NAME} PRIVATE Crow::Crow)

if(CROW_AMALGAMATION)
target_compile_definitions(${PROJECT_NAME} PRIVATE CROW_AMALGAMATION)
endif(CROW_AMALGAMATION)
unset(CROW_AMALGAMATION CACHE)

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
27 changes: 20 additions & 7 deletions recipes/crowcpp-crow/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +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_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", "CMakeToolchain", "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["CROW_AMALGAMATION"] = self.dependencies["crowcpp-crow"].options.amalgamation
tc.generate()

def build(self):
cmake = CMake(self)
cmake.definitions["CROW_AMALGAMATION"] = self.options["crowcpp-crow"].amalgamation
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/crowcpp-crow/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/)
19 changes: 19 additions & 0 deletions recipes/crowcpp-crow/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


class TestPackageV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.definitions["CROW_AMALGAMATION"] = self.options["crowcpp-crow"].amalgamation
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)
2 changes: 2 additions & 0 deletions recipes/crowcpp-crow/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"1.0+5":
folder: all
"1.0+3":
folder: all
"1.0+1":
Expand Down

0 comments on commit 27ab96e

Please sign in to comment.