Skip to content

Commit

Permalink
(#23117) libassert: add 2.0.0
Browse files Browse the repository at this point in the history
* Add libassert 2.0.0

* Fixes/improvements

* Try to fix conan v1 conanfile

* Again

* Printbug

* Fix?

* Revert "Fix?"

This reverts commit ab47df7.

* Silly me

* Remove erlier setting of LIBASSERT2 in the main conanfile

* Use better way to detect version in test package, and fix Windows shared copy

* Add LIBASSERT_STATIC_DEFINE

* Fix Conan v1 test package

* Fix versions checks

* generate cmake target for Conan 1.x

Signed-off-by: Uilian Ries <[email protected]>

* Update recipes/libassert/all/conanfile.py

* Fix

* Update patch

* Export definition via component only

* Review comments

---------

Signed-off-by: Uilian Ries <[email protected]>
Co-authored-by: Rubén Rincón Blanco <[email protected]>
Co-authored-by: Uilian Ries <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2024
1 parent cd5d269 commit d1523f9
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 22 deletions.
9 changes: 9 additions & 0 deletions recipes/libassert/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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 @@ -18,6 +22,11 @@ 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
62 changes: 48 additions & 14 deletions recipes/libassert/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand Down Expand Up @@ -52,14 +53,17 @@ def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if Version(self.version) >= Version("1.2.2"):
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":
self.requires("cpptrace/0.3.1")
elif Version(self.version) >= Version("1.2.1"):
elif Version(self.version) >= "1.2.1":
self.requires("cpptrace/0.2.1")

def validate(self):
if self.settings.compiler == "apple-clang":
raise ConanInvalidConfiguration("apple-clang not supported")
if Version(self.version) <= "2.0.0" and 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:
check_min_cppstd(self, self._min_cppstd)
Expand All @@ -82,7 +86,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) >= Version("1.2.1"):
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
Expand Down Expand Up @@ -124,22 +132,48 @@ def package(self):
def package_info(self):
self.cpp_info.libs = ["assert"]

self.cpp_info.set_property("cmake_file_name", "assert")
self.cpp_info.set_property("cmake_target_name", "assert::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")

# 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", "assert"))
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"))

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
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 Version(self.version) < Version("1.2.1"):
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"

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"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/include/libassert/assert-gtest.hpp b/include/libassert/assert-gtest.hpp
index 912da40..57dbc91 100644
--- a/include/libassert/assert-gtest.hpp
+++ b/include/libassert/assert-gtest.hpp
@@ -6,8 +6,6 @@
#define LIBASSERT_PREFIX_ASSERTIONS
#include <libassert/assert.hpp>

-#include "tokenizer.hpp"
-
#if defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL != 0
#error "Libassert integration does not work with MSVC's non-conformant preprocessor. /Zc:preprocessor must be used."
#endif
17 changes: 12 additions & 5 deletions recipes/libassert/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)

project(test_package CXX)

find_package(assert REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
# don't link to ${CONAN_LIBS} or CONAN_PKG::package
target_link_libraries(${PROJECT_NAME} PRIVATE assert::assert)
# In case the target project need a specific C++ standard

if(LIBASSERT2)
find_package(libassert REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE libassert::assert)
target_compile_definitions(${PROJECT_NAME} PRIVATE LIBASSERT2)
else()
find_package(assert REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE assert::assert)
endif()


target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
10 changes: 8 additions & 2 deletions recipes/libassert/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
import os


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

def requirements(self):
Expand All @@ -14,6 +15,11 @@ def requirements(self):
def layout(self):
cmake_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):
cmake = CMake(self)
cmake.configure()
Expand Down
16 changes: 16 additions & 0 deletions recipes/libassert/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
#include <cstdlib>
#include <iostream>
#ifdef LIBASSERT2
#include <libassert/assert.hpp>
#else
#include <assert/assert.hpp>
#endif

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

#ifdef LIBASSERT2
libassert::set_failure_handler([](const libassert::assertion_info& info) {
std::cerr<<info.to_string();
throw std::runtime_error("Assertion failed");
});
#endif

try{
#ifdef LIBASSERT2
DEBUG_ASSERT(1 != 1);
ASSERT(1 != 1);
#else
VERIFY(1 != 1);
#endif
}
catch (...){
return EXIT_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion recipes/libassert/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
Expand Down
2 changes: 2 additions & 0 deletions recipes/libassert/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
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.definitions["LIBASSERT2"] = "ON" if self.deps_cpp_info["libassert"].version >= "2.0.0" else "OFF"
cmake.configure()
cmake.build()

Expand Down
2 changes: 2 additions & 0 deletions recipes/libassert/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
versions:
# Newer versions at the top
"2.0.0":
folder: all
"1.2.2":
folder: all
"1.2.1":
Expand Down

0 comments on commit d1523f9

Please sign in to comment.