jeremy-rifkin / libassert

The most over-engineered C++ assertion library
MIT License
547 stars 37 forks source link

use FetchContent for magic_enum #69

Closed flagarde closed 1 year ago

flagarde commented 1 year ago

@jeremy-rifkin Hi, thx for this nice library. As now libassert Fetch cpptrace I use FetchContent to fetch magic_enum too.

Please note :

jeremy-rifkin commented 1 year ago

The other open PR at the moment, #68, is a very substantial overhaul of the library's cmake. I think it makes sense to try to merge that one first and then this one. I'm happy to help with resolving the merge conflict. I am planning on doing so in the morning.

jeremy-rifkin commented 1 year ago

Ope... Well crap. I messed up.

jeremy-rifkin commented 1 year ago

My apologies! 😅 I unfortunately can't seem to re-open. Would you be able to re-create this on the dev branch?

The changes you had before I messed everything up were

+option(ASSERT_USE_EXTERNAL_MAGIC_ENUM "Controls whether magic_enum is gathered with FetchContent or find_package" OFF)
+option(ASSERT_USE_EXTERNAL_CPPTRACE "Controls whether cpptrace is gathered with FetchContent or find_package" OFF)
+set(ASSERT_MAGIC_ENUM_REPO "https://github.com/Neargye/magic_enum.git")
+set(ASSERT_MAGIC_ENUM_TAG "v0.9.4")
+
+set(ASSERT_CPPTRACE_REPO "https://github.com/jeremy-rifkin/cpptrace.git")
+set(ASSERT_CPPTRACE_TAG "v0.2.1")
  FetchContent_Declare(
    cpptrace
+    GIT_REPOSITORY "${ASSERT_CPPTRACE_REPO}"
+    GIT_TAG        "${ASSERT_CPPTRACE_TAG}"
  )
if(ASSERT_USE_MAGIC_ENUM)
+ if(ASSERT_USE_EXTERNAL_MAGIC_ENUM)
+   find_package(magic_enum REQUIRED)
+ else()
+   FetchContent_Declare(magic_enum
+     GIT_REPOSITORY "${ASSERT_MAGIC_ENUM_REPO}"
+     GIT_TAG        "${ASSERT_MAGIC_ENUM_TAG}")
+   FetchContent_MakeAvailable(magic_enum)
+ endif()
+ target_link_libraries(assert PRIVATE magic_enum::magic_enum)
  target_compile_definitions(assert PUBLIC ASSERT_USE_MAGIC_ENUM)
endif()
#ifdef ASSERT_USE_MAGIC_ENUM
+#if __has_include("magic_enum/magic_enum.hpp")
+   #include "magic_enum/magic_enum.hpp"
+#else
+   #include "magic_enum.hpp"
+#endif
#endif
jeremy-rifkin commented 1 year ago

I think what went wrong is I pushed the wrong main branch to your main branch. I haven't tried editing a PR quite like this before.

flagarde commented 1 year ago

@jeremy-rifkin I PR it to dev.

jeremy-rifkin commented 1 year ago

Thank you!