1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-09 23:34:23 +00:00

fix installing via cmake (#374)

This commit is contained in:
Arni 2024-10-14 15:05:55 +00:00 committed by GitHub
parent 9675f2bc29
commit a72a0536c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 478 additions and 186 deletions

View file

@ -1,37 +1,85 @@
include(CheckCXXCompilerFlag)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(OPTIONS /W4 /WX)
check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG)
if(HAS_PERMISSIVE_FLAG)
set(OPTIONS ${OPTIONS} /permissive-)
if(${MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION})
find_package(magic_enum REQUIRED magic_enum)
endif()
if(${MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG})
find_package(PkgConfig)
pkg_check_modules(magic_enum magic_enum)
if(NOT magic_enum_FOUND)
message(
WARNING
"magic_enum via pkgconfig is not found. \
Next code will try check possible places for some platforms, \
but there's no guarantee. \
If you know where the magic_enum pkgconfig files (.pc) are, \
then specify yourself variable \$\{CMAKE_PREFIX_PATH\} \
with folder like /a/path/to/magic_enum (for POSIX-like pathes), \
where in the folder exists share/pkgconfig/magic_enum.pc ."
)
if(UNIX AND EXISTS "/usr/local/share/pkgconfig/magic_enum.pc")
message(DEBUG "\$\{CMAKE_PREFIX_PATH\} : ${CMAKE_PREFIX_PATH} ")
set(CMAKE_PREFIX_PATH "/usr/local")
message(DEBUG "\$\{CMAKE_PREFIX_PATH\} : ${CMAKE_PREFIX_PATH} ")
pkg_check_modules(magic_enum magic_enum)
endif()
# code place for future workarounds for other platforms...
if(NOT magic_enum_FOUND)
message(FATAL_ERROR "Could not find magic_enum's config. Read a warning above.")
endif()
endif()
message(DEBUG "magic_enum_FOUND : ${magic_enum_FOUND}")
message(DEBUG "magic_enum_LIBRARIES: ${magic_enum_LIBRARIES}")
message(DEBUG "magic_enum_LINK_LIBRARIES: ${magic_enum_LINK_LIBRARIES}")
message(DEBUG "magic_enum_LIBRARY_DIRS: ${magic_enum_LIBRARY_DIRS}")
message(DEBUG "magic_enum_INCLUDE_DIRS: ${magic_enum_INCLUDE_DIRS}")
message(DEBUG "magic_enum_INCLUDE_DIR: ${magic_enum_INCLUDE_DIR}")
message(DEBUG "magic_enum_LDFLAGS: ${magic_enum_LDFLAGS}")
message(DEBUG "magic_enum_LDFLAGS_OTHER: ${magic_enum_LDFLAGS_OTHER}")
message(DEBUG "magic_enum_CFLAGS: ${magic_enum_CFLAGS}")
message(DEBUG "magic_enum_CFLAGS_OTHER: ${magic_enum_CFLAGS_OTHER}")
message(DEBUG "magic_enum_INCLUDEDIR: ${magic_enum_INCLUDEDIR}")
message(DEBUG "magic_enum_LIBDIR: ${magic_enum_LIBDIR}")
message(DEBUG "magic_enum_PREFIX: ${magic_enum_PREFIX}")
endif()
check_cxx_compiler_flag(/std:c++20 HAS_CPP20_FLAG)
check_cxx_compiler_flag(/std:c++23 HAS_CPP23_FLAG)
check_cxx_compiler_flag(/std:c++latest HAS_CPPLATEST_FLAG)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(OPTIONS /W4 /WX)
check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG)
if(HAS_PERMISSIVE_FLAG)
set(OPTIONS ${OPTIONS} /permissive-)
endif()
check_cxx_compiler_flag(/std:c++20 HAS_CPP20_FLAG)
check_cxx_compiler_flag(/std:c++23 HAS_CPP23_FLAG)
check_cxx_compiler_flag(/std:c++latest HAS_CPPLATEST_FLAG)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(OPTIONS -Wall -Wextra -Wshadow -pedantic-errors -Werror)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(OPTIONS -Wall -Wextra -Wshadow -pedantic-errors -Werror)
check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG)
check_cxx_compiler_flag(-std=c++23 HAS_CPP23_FLAG)
check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG)
check_cxx_compiler_flag(-std=c++23 HAS_CPP23_FLAG)
endif()
function(make_test src target std)
add_executable(${target} ${src})
target_compile_options(${target} PRIVATE ${OPTIONS})
target_include_directories(${target} PRIVATE 3rdparty/Catch2/include)
target_link_libraries(${target} PRIVATE ${CMAKE_PROJECT_NAME})
set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF)
if(std)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(${target} PRIVATE /std:${std})
else()
target_compile_options(${target} PRIVATE -std=${std})
endif()
add_executable(${target} ${src})
target_compile_options(${target} PRIVATE ${OPTIONS})
target_include_directories(${target} PRIVATE 3rdparty/Catch2/include)
if(${MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG})
target_include_directories(${target} PRIVATE ${magic_enum_INCLUDE_DIRS})
else()
target_link_libraries(${target} PRIVATE magic_enum::magic_enum)
endif()
set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF)
if(std)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(${target} PRIVATE /std:${std})
else()
target_compile_options(${target} PRIVATE -std=${std})
endif()
add_test(NAME ${target} COMMAND ${target})
endif()
add_test(NAME ${target} COMMAND ${target})
endfunction()
make_test(test.cpp test-cpp17 c++17)
@ -41,38 +89,38 @@ make_test(test_containers.cpp test_containers-cpp17 c++17)
make_test(test_wchar_t.cpp test_wchar_t-cpp17 c++17)
if(MAGIC_ENUM_OPT_ENABLE_NONASCII)
make_test(test_nonascii.cpp test_nonascii-cpp17 c++17)
make_test(test_nonascii.cpp test_nonascii-cpp17 c++17)
endif()
if(HAS_CPP20_FLAG)
make_test(test.cpp test-cpp20 c++20)
make_test(test_flags.cpp test_flags-cpp20 c++20)
make_test(test_aliases.cpp test_aliases-cpp20 c++20)
make_test(test_containers.cpp test_containers-cpp20 c++20)
make_test(test_wchar_t.cpp test_wchar_t-cpp20 c++20)
if(MAGIC_ENUM_OPT_ENABLE_NONASCII)
make_test(test_nonascii.cpp test_nonascii-cpp20 c++20)
endif()
make_test(test.cpp test-cpp20 c++20)
make_test(test_flags.cpp test_flags-cpp20 c++20)
make_test(test_aliases.cpp test_aliases-cpp20 c++20)
make_test(test_containers.cpp test_containers-cpp20 c++20)
make_test(test_wchar_t.cpp test_wchar_t-cpp20 c++20)
if(MAGIC_ENUM_OPT_ENABLE_NONASCII)
make_test(test_nonascii.cpp test_nonascii-cpp20 c++20)
endif()
endif()
if(HAS_CPP23_FLAG)
make_test(test.cpp test-cpp23 c++23)
make_test(test_flags.cpp test_flags-cpp23 c++23)
make_test(test_aliases.cpp test_aliases-cpp23 c++23)
make_test(test_containers.cpp test_containers-cpp23 c++23)
make_test(test_wchar_t.cpp test_wchar_t-cpp23 c++23)
if(MAGIC_ENUM_OPT_ENABLE_NONASCII)
make_test(test_nonascii.cpp test_nonascii-cpp23 c++23)
endif()
make_test(test.cpp test-cpp23 c++23)
make_test(test_flags.cpp test_flags-cpp23 c++23)
make_test(test_aliases.cpp test_aliases-cpp23 c++23)
make_test(test_containers.cpp test_containers-cpp23 c++23)
make_test(test_wchar_t.cpp test_wchar_t-cpp23 c++23)
if(MAGIC_ENUM_OPT_ENABLE_NONASCII)
make_test(test_nonascii.cpp test_nonascii-cpp23 c++23)
endif()
endif()
if(HAS_CPPLATEST_FLAG)
make_test(test.cpp test-cpplatest c++latest)
make_test(test_flags.cpp test_flags-cpplatest c++latest)
make_test(test_aliases.cpp test_aliases-cpplatest c++latest)
make_test(test_containers.cpp test_containers-cpplatest c++latest)
make_test(test_wchar_t.cpp test_wchar_t-cpplatest c++latest)
if(MAGIC_ENUM_OPT_ENABLE_NONASCII)
make_test(test_nonascii.cpp test_nonascii-cpplatest c++latest)
endif()
make_test(test.cpp test-cpplatest c++latest)
make_test(test_flags.cpp test_flags-cpplatest c++latest)
make_test(test_aliases.cpp test_aliases-cpplatest c++latest)
make_test(test_containers.cpp test_containers-cpplatest c++latest)
make_test(test_wchar_t.cpp test_wchar_t-cpplatest c++latest)
if(MAGIC_ENUM_OPT_ENABLE_NONASCII)
make_test(test_nonascii.cpp test_nonascii-cpplatest c++latest)
endif()
endif()

View file

@ -26,10 +26,10 @@
#define MAGIC_ENUM_NO_CHECK_REFLECTED_ENUM
#define MAGIC_ENUM_RANGE_MIN -120
#define MAGIC_ENUM_RANGE_MAX 120
#include <magic_enum.hpp>
#include <magic_enum_fuse.hpp>
#include <magic_enum_iostream.hpp>
#include <magic_enum_utility.hpp>
#include <magic_enum/magic_enum.hpp>
#include <magic_enum/magic_enum_fuse.hpp>
#include <magic_enum/magic_enum_iostream.hpp>
#include <magic_enum/magic_enum_utility.hpp>
#include <array>
#include <cctype>
@ -1176,7 +1176,7 @@ TEST_CASE("multdimensional-switch-case") {
#if defined(__cpp_lib_format)
#include <magic_enum_format.hpp>
#include <magic_enum/magic_enum_format.hpp>
TEST_CASE("format-base") {
REQUIRE(std::format("{}", Color::RED) == "red");

View file

@ -96,8 +96,8 @@ constexpr bool operator==(MyStringView lhs, MyStringView rhs) {
#define MAGIC_ENUM_USING_ALIAS_STRING using string = MyString;
#define MAGIC_ENUM_USING_ALIAS_STRING_VIEW using string_view = MyStringView;
#include <magic_enum.hpp>
#include <magic_enum_flags.hpp>
#include <magic_enum/magic_enum.hpp>
#include <magic_enum/magic_enum_flags.hpp>
using namespace magic_enum;
using namespace magic_enum::bitwise_operators;

View file

@ -33,8 +33,8 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <magic_enum_containers.hpp>
#include <magic_enum_iostream.hpp>
#include <magic_enum/magic_enum_containers.hpp>
#include <magic_enum/magic_enum_iostream.hpp>
#include <functional>

View file

@ -32,11 +32,11 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <magic_enum.hpp>
#include <magic_enum_flags.hpp>
#include <magic_enum_fuse.hpp>
#include <magic_enum_iostream.hpp>
#include <magic_enum_utility.hpp>
#include <magic_enum/magic_enum.hpp>
#include <magic_enum/magic_enum_flags.hpp>
#include <magic_enum/magic_enum_fuse.hpp>
#include <magic_enum/magic_enum_iostream.hpp>
#include <magic_enum/magic_enum_utility.hpp>
#include <array>
#include <cctype>
@ -91,8 +91,8 @@ struct magic_enum::customize::enum_range<number> {
static constexpr bool is_flags = true;
};
#include <magic_enum.hpp>
#include <magic_enum_fuse.hpp>
#include <magic_enum/magic_enum.hpp>
#include <magic_enum/magic_enum_fuse.hpp>
using namespace magic_enum;
using namespace magic_enum::bitwise_operators;
@ -720,7 +720,7 @@ TEST_CASE("constexpr_for") {
#if defined(__cpp_lib_format)
#include <magic_enum_format.hpp>
#include <magic_enum/magic_enum_format.hpp>
TEST_CASE("format-base") {
REQUIRE(std::format("Test-{:~^11}.", Color::RED | Color::GREEN) == "Test-~RED|GREEN~.");

View file

@ -27,9 +27,9 @@
#define MAGIC_ENUM_RANGE_MIN -120
#undef MAGIC_ENUM_RANGE_MAX
#define MAGIC_ENUM_RANGE_MAX 120
#include <magic_enum.hpp>
#include <magic_enum_fuse.hpp>
#include <magic_enum_iostream.hpp>
#include <magic_enum/magic_enum.hpp>
#include <magic_enum/magic_enum_fuse.hpp>
#include <magic_enum/magic_enum_iostream.hpp>
#include <array>
#include <cctype>

View file

@ -25,8 +25,8 @@
#define MAGIC_ENUM_USING_ALIAS_STRING_VIEW using string_view = std::wstring_view;
#define MAGIC_ENUM_USING_ALIAS_STRING using string = std::wstring;
#include <magic_enum.hpp>
#include <magic_enum_iostream.hpp>
#include <magic_enum/magic_enum.hpp>
#include <magic_enum/magic_enum_iostream.hpp>
#include <array>
#include <cctype>