Skip to content

Commit

Permalink
(#23286) libassert: refactor recipe into v1 and v2 folders
Browse files Browse the repository at this point in the history
* Split recipe into v1 and v2 folders

* Add libm

* Update recipes/libassert/v2/conanfile.py

Co-authored-by: Jordan Williams <[email protected]>

* Guard libm on v1 recipe

---------

Co-authored-by: Jordan Williams <[email protected]>
  • Loading branch information
jeremy-rifkin and jwillikers authored Apr 3, 2024
1 parent 976b1cd commit d4f3987
Show file tree
Hide file tree
Showing 25 changed files with 273 additions and 93 deletions.
18 changes: 0 additions & 18 deletions recipes/libassert/all/test_package/CMakeLists.txt

This file was deleted.

10 changes: 5 additions & 5 deletions recipes/libassert/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
versions:
# Newer versions at the top
"2.0.0":
folder: all
folder: v2
"1.2.2":
folder: all
folder: v1
"1.2.1":
folder: all
folder: v1
"1.1":
folder: all
folder: v1
"1.0":
folder: all
folder: v1
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
sources:
# Newer versions at the top
"2.0.0":
url:
- "https://github.com/jeremy-rifkin/libassert/archive/refs/tags/v2.0.0.tar.gz"
sha256: "d4b2da2179a94637b34d18813a814531a1eceb0ddc6dd6db6098050dd638f4a1"
"1.2.2":
url:
- "https://github.com/jeremy-rifkin/libassert/archive/refs/tags/v1.2.2.tar.gz"
Expand All @@ -22,11 +18,6 @@ sources:
sha256: "e1bb3b50767994ca4d0f60b7977b279cf32b8569ff92c5830e7a1de567b82fd5"

patches:
"2.0.0":
- patch_file: "patches/2.0.0/0001-fix-export-and-include.patch"
patch_type: "bugfix"
patch_source: https://github.com/jeremy-rifkin/libassert/commit/25c1f3e43737ab18490a0d9430cb1c70f976a662
patch_description: "Fix export header and an incorrect #include"
"1.2.2":
- patch_file: "patches/1.2.2/0001-cpptrace-dll-copy.patch"
patch_type: "conan"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,13 @@ def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if Version(self.version) >= "2.0.0":
# libassert::detail::process_assert_fail
self.requires("cpptrace/0.5.0", transitive_headers=True, transitive_libs=True)
elif Version(self.version) >= "1.2.2":
if Version(self.version) >= "1.2.2":
self.requires("cpptrace/0.3.1")
elif Version(self.version) >= "1.2.1":
self.requires("cpptrace/0.2.1")

def validate(self):
if Version(self.version) <= "2.0.0" and is_apple_os(self):
if is_apple_os(self):
raise ConanInvalidConfiguration(f"{self.ref} is not supported on Mac. Please, update to version >=2.0.0")

if self.settings.compiler.cppstd:
Expand All @@ -86,16 +83,11 @@ def generate(self):
if is_msvc(self):
tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self)

if Version(self.version) >= "2.0.0":
tc.variables["LIBASSERT_USE_EXTERNAL_CPPTRACE"] = True
deps = CMakeDeps(self)
deps.generate()
elif Version(self.version) >= "1.2.1":
if not self.options.shared:
tc.variables["ASSERT_STATIC"] = True
tc.variables["ASSERT_USE_EXTERNAL_CPPTRACE"] = True
deps = CMakeDeps(self)
deps.generate()
if not self.options.shared:
tc.variables["ASSERT_STATIC"] = True
tc.variables["ASSERT_USE_EXTERNAL_CPPTRACE"] = True
deps = CMakeDeps(self)
deps.generate()

tc.generate()

Expand Down Expand Up @@ -132,48 +124,25 @@ def package(self):
def package_info(self):
self.cpp_info.libs = ["assert"]

if Version(self.version) >= "2.0.0":
self.cpp_info.set_property("cmake_file_name", "libassert")
self.cpp_info.set_property("cmake_target_name", "libassert::assert")
else:
self.cpp_info.set_property("cmake_file_name", "assert")
self.cpp_info.set_property("cmake_target_name", "assert::assert")
self.cpp_info.set_property("cmake_file_name", "assert")
self.cpp_info.set_property("cmake_target_name", "assert::assert")

# the first version of this library used assert/assert as include folder
# appending this one but not removing the default to not break consumers
if Version(self.version) >= "2.0.0":
self.cpp_info.includedirs.append(os.path.join("include", "libassert"))
else:
self.cpp_info.includedirs.append(os.path.join("include", "assert"))
self.cpp_info.includedirs.append(os.path.join("include", "assert"))

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
if Version(self.version) >= "2.0.0":
self.cpp_info.filenames["cmake_find_package"] = "libassert"
self.cpp_info.filenames["cmake_find_package_multi"] = "libassert"
self.cpp_info.names["cmake_find_package"] = "libassert"
self.cpp_info.names["cmake_find_package_multi"] = "libassert"

self.cpp_info.components["assert"].names["cmake_find_package"] = "assert"
self.cpp_info.components["assert"].names["cmake_find_package_multi"] = "assert"
self.cpp_info.components["assert"].requires = ["cpptrace::cpptrace"]
self.cpp_info.components["assert"].libs = ["assert"]
if not self.options.shared:
self.cpp_info.components["assert"].defines.append("LIBASSERT_STATIC_DEFINE")
else:
self.cpp_info.filenames["cmake_find_package"] = "assert"
self.cpp_info.filenames["cmake_find_package_multi"] = "assert"
self.cpp_info.names["cmake_find_package"] = "assert"
self.cpp_info.names["cmake_find_package_multi"] = "assert"
self.cpp_info.filenames["cmake_find_package"] = "assert"
self.cpp_info.filenames["cmake_find_package_multi"] = "assert"
self.cpp_info.names["cmake_find_package"] = "assert"
self.cpp_info.names["cmake_find_package_multi"] = "assert"

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

if Version(self.version) < "1.2.1":
# pre-cpptrace
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("dl")
if self.settings.os == "Windows":
self.cpp_info.system_libs.append("dbghelp")

if Version(self.version) >= "2.0.0":
self.cpp_info.system_libs.append("m")

if Version(self.version) >= "2.0.0":
self.cpp_info.requires = ["cpptrace::cpptrace"]
12 changes: 12 additions & 0 deletions recipes/libassert/v1/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.15)

project(test_package CXX)


add_executable(${PROJECT_NAME} test_package.cpp)

find_package(assert REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE assert::assert)


target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def layout(self):

def generate(self):
tc = CMakeToolchain(self)
tc.variables["LIBASSERT2"] = self.dependencies[self.tested_reference_str].ref.version >= "2.0.0"
tc.generate()

def build(self):
Expand Down
16 changes: 16 additions & 0 deletions recipes/libassert/v1/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <cstdlib>
#include <iostream>
#include <assert/assert.hpp>

int main(void) {
std::cout << "Testing libassert\n";

try{
VERIFY(1 != 1);
}
catch (...){
return EXIT_SUCCESS;
}

return EXIT_FAILURE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class TestPackageV1Conan(ConanFile):

def build(self):
cmake = CMake(self)
cmake.definitions["LIBASSERT2"] = "ON" if self.deps_cpp_info["libassert"].version >= "2.0.0" else "OFF"
cmake.configure()
cmake.build()

Expand Down
13 changes: 13 additions & 0 deletions recipes/libassert/v2/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sources:
# Newer versions at the top
"2.0.0":
url:
- "https://github.com/jeremy-rifkin/libassert/archive/refs/tags/v2.0.0.tar.gz"
sha256: "d4b2da2179a94637b34d18813a814531a1eceb0ddc6dd6db6098050dd638f4a1"

patches:
"2.0.0":
- patch_file: "patches/2.0.0/0001-fix-export-and-include.patch"
patch_type: "bugfix"
patch_source: https://github.com/jeremy-rifkin/libassert/commit/25c1f3e43737ab18490a0d9430cb1c70f976a662
patch_description: "Fix export header and an incorrect #include"
141 changes: 141 additions & 0 deletions recipes/libassert/v2/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc
from conan.tools.apple import is_apple_os
from conan.tools.files import get, copy, rm, rmdir
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.files import apply_conandata_patches, export_conandata_patches
import os

required_conan_version = ">=1.53.0"

class LibassertConan(ConanFile):
name = "libassert"
description = "The most over-engineered C++ assertion library"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/jeremy-rifkin/libassert"
package_type = "library"

topics = ("assert", "library", "assertions", "stacktrace", "diagnostics", "defensive programming", "testing")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"gcc": "8",
"clang": "9"
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

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

def requirements(self):
self.requires("cpptrace/0.5.1", transitive_headers=True, transitive_libs=True)

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

check_min_vs(self, 192)
if not is_msvc(self):
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.")

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

def export_sources(self):
export_conandata_patches(self)

def generate(self):
tc = CMakeToolchain(self)

if is_msvc(self):
tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self)

tc.variables["LIBASSERT_USE_EXTERNAL_CPPTRACE"] = True
deps = CMakeDeps(self)
deps.generate()

tc.generate()

def build(self):
apply_conandata_patches(self)

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

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

if self.settings.os == "Windows" and self.options.shared:
copy(
self,
"*.dll",
src=self.build_folder,
dst=os.path.join(self.package_folder, "bin"),
keep_path=False
)

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.libs = ["assert"]

self.cpp_info.set_property("cmake_file_name", "libassert")
self.cpp_info.set_property("cmake_target_name", "libassert::assert")

# the first version of this library used assert/assert as include folder
# appending this one but not removing the default to not break consumers
self.cpp_info.includedirs.append(os.path.join("include", "libassert"))

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

self.cpp_info.components["assert"].names["cmake_find_package"] = "assert"
self.cpp_info.components["assert"].names["cmake_find_package_multi"] = "assert"
self.cpp_info.components["assert"].requires = ["cpptrace::cpptrace"]
self.cpp_info.components["assert"].libs = ["assert"]
if not self.options.shared:
self.cpp_info.components["assert"].defines.append("LIBASSERT_STATIC_DEFINE")

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
self.cpp_info.requires = ["cpptrace::cpptrace"]
11 changes: 11 additions & 0 deletions recipes/libassert/v2/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.15)

project(test_package CXX)


add_executable(${PROJECT_NAME} test_package.cpp)

find_package(libassert REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE libassert::assert)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
Loading

0 comments on commit d4f3987

Please sign in to comment.