diff --git a/.cmake-format b/.cmake-format new file mode 100644 index 000000000..c9b4e3e86 --- /dev/null +++ b/.cmake-format @@ -0,0 +1,58 @@ +format: + tab_size: 2 + line_width: 100 + dangle_parens: true + +parse: + additional_commands: + cpmaddpackage: + pargs: + nargs: '*' + flags: [] + spelling: CPMAddPackage + kwargs: &cpmaddpackagekwargs + NAME: 1 + FORCE: 1 + VERSION: 1 + GIT_TAG: 1 + DOWNLOAD_ONLY: 1 + GITHUB_REPOSITORY: 1 + GITLAB_REPOSITORY: 1 + GIT_REPOSITORY: 1 + SVN_REPOSITORY: 1 + SVN_REVISION: 1 + SOURCE_DIR: 1 + DOWNLOAD_COMMAND: 1 + FIND_PACKAGE_ARGUMENTS: 1 + NO_CACHE: 1 + GIT_SHALLOW: 1 + URL: 1 + URL_HASH: 1 + URL_MD5: 1 + DOWNLOAD_NAME: 1 + DOWNLOAD_NO_EXTRACT: 1 + HTTP_USERNAME: 1 + HTTP_PASSWORD: 1 + OPTIONS: + + cpmfindpackage: + pargs: + nargs: '*' + flags: [] + spelling: CPMFindPackage + kwargs: *cpmaddpackagekwargs + packageproject: + pargs: + nargs: '*' + flags: [] + spelling: packageProject + kwargs: + NAME: 1 + VERSION: 1 + NAMESPACE: 1 + INCLUDE_DIR: 1 + INCLUDE_DESTINATION: 1 + BINARY_DIR: 1 + COMPATIBILITY: 1 + VERSION_HEADER: 1 + DEPENDENCIES: + + diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..381c9eb9f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +build*/ +.cache/ +.git/ +.github/ +compile_commands.json +.dockerignore +Dockerfile +install_dir/ + diff --git a/.github/workflows/ubuntu_test_installed_version.yml b/.github/workflows/ubuntu_test_installed_version.yml new file mode 100644 index 000000000..25d7b01e3 --- /dev/null +++ b/.github/workflows/ubuntu_test_installed_version.yml @@ -0,0 +1,60 @@ +name: ubuntu_test_installed_version.yml + + +on: + push: + branches: + - master + - main + pull_request: + branches: + - master + - main + +env: + CTEST_OUTPUT_ON_FAILURE: 1 + CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: actions/cache@v3 + with: + path: "**/cpm_modules" + key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} + + - name: install library + run: | + cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release --log-level=DEBUG -DCMAKE_INSTALL_PREFIX=./install_dir + cmake --build ./build -j$(nproc) + cmake --install ./build --prefix ./install_dir + rm -rf build + + - name: configure with installed version via cmake + run: CMAKE_PREFIX_PATH="./install_dir" cmake -S. -Bbuild2 -DMAGIC_ENUM_OPT_TEST_INSTALLED_VERSION=1 --log-level=DEBUG + + - name: build with installed version via cmake + run: cmake --build build2 --config Debug -j$(nproc) --verbose + + - name: test + run: | + cd build2 + ctest --build-config Debug -j$(nproc) + + - name: clear + run: rm -rf build2 + + - name: configure with installed version via pkgconfig + run: CMAKE_PREFIX_PATH="./install_dir" cmake -S. -Bbuild3 -DMAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG=1 -DPKG_CONFIG_USE_CMAKE_PREFIX_PATH=1 --log-level=DEBUG + + - name: build with installed version via pkgconfig + run: cmake --build build3 --config Debug -j$(nproc) --verbose + + - name: test + run: | + cd build3 + ctest --build-config Debug -j$(nproc) diff --git a/.gitignore b/.gitignore index 9a7b48c69..3e67509ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ -build/ +build*/ +cmake_build*/ +install_dir/ .vscode/ .vs/ diff --git a/BUILD.bazel b/BUILD.bazel index 356c09d5f..0700062b6 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -7,5 +7,5 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "magic_enum", hdrs = glob(["include/magic_enum/*.hpp"]), - includes = ["include/magic_enum"], + includes = ["include"], ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57484a67e..822b64b18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,12 @@ cmake_minimum_required(VERSION 3.14) -project(magic_enum - VERSION "0.9.6" - HOMEPAGE_URL "https://github.com/Neargye/magic_enum" - DESCRIPTION "A library that provides static reflection for enums, work with any enum type without any macro or boilerplate code." - LANGUAGES CXX +project( + magic_enum + VERSION "0.9.6" + HOMEPAGE_URL "https://github.com/Neargye/magic_enum" + DESCRIPTION + "A library that provides static reflection for enums, work with any enum type without any macro or boilerplate code." + LANGUAGES CXX ) set(CPACK_PACKAGE_VENDOR "Daniil Goncharov") @@ -14,23 +16,27 @@ set(ADDITIONAL_MODULES_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${ADDITIONAL_MODULES_DIR}") if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - set(IS_TOPLEVEL_PROJECT TRUE) + set(IS_TOPLEVEL_PROJECT TRUE) else() - set(IS_TOPLEVEL_PROJECT FALSE) + set(IS_TOPLEVEL_PROJECT FALSE) endif() option(MAGIC_ENUM_OPT_BUILD_EXAMPLES "Build magic_enum examples" ${IS_TOPLEVEL_PROJECT}) option(MAGIC_ENUM_OPT_BUILD_TESTS "Build and perform magic_enum tests" ${IS_TOPLEVEL_PROJECT}) option(MAGIC_ENUM_OPT_INSTALL "Generate and install magic_enum target" ${IS_TOPLEVEL_PROJECT}) -option(MAGIC_ENUM_OPT_INSTALL_PACKAGE_XML "Include package.xml when installing" ${MAGIC_ENUM_OPT_INSTALL}) +option(MAGIC_ENUM_OPT_INSTALL_PACKAGE_XML "Include package.xml when installing" + ${MAGIC_ENUM_OPT_INSTALL} +) +option(MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION "When configuring tests, try use +a local magic_enum." NO +) +option(MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG "When configuring tests, try use +a local magic_enum via pkgconfig" NO +) -if(MAGIC_ENUM_OPT_BUILD_EXAMPLES) - add_subdirectory(example) -endif() - -if(MAGIC_ENUM_OPT_BUILD_TESTS) - enable_testing() - add_subdirectory(test) +if(${MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION} OR ${MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG}) + add_subdirectory(test) + return() endif() set(INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include/magic_enum") @@ -38,94 +44,119 @@ set(EXPORT_NAMESPACE "${PROJECT_NAME}::") add_library(${PROJECT_NAME} INTERFACE) add_library(${EXPORT_NAMESPACE}${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -target_include_directories(${PROJECT_NAME} - INTERFACE - $ - $) - -if(MAGIC_ENUM_OPT_INSTALL) - list(APPEND CMAKE_MODULE_PATH "${ADDITIONAL_MODULES_DIR}/GenPkgConfig") - include(GenPkgConfig) - include(CPackComponent) - include(CMakePackageConfigHelpers) - - install(TARGETS "${PROJECT_NAME}" - EXPORT ${PROJECT_NAME} - INCLUDES - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - # COMPONENT "${SDK_COMPONENT_NAME}" # component is not allowed for includes! Headers are installed separately! Includes only marks the headers for export - ) - - file(GLOB_RECURSE HEADERS "${INCLUDES}/*.h" "${INCLUDES}/*.hxx" "${INCLUDES}/*.hpp") - string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}") - foreach(headerFile ${HEADERS}) - get_filename_component(headerFileParentDir "${headerFile}" DIRECTORY) - file(RELATIVE_PATH headerFileRelParentDir "${INCLUDES}" "${headerFileParentDir}") - - install(FILES "${headerFile}" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${headerFileRelParentDir}" - ) - endforeach() - - set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") - set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}") - set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all") - set(CPACK_DEBIAN_PACKAGE_NAME "libmagicenum-dev") - set(CPACK_RPM_PACKAGE_NAME "libmagicenum-devel") - set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}") - set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}") - set(CPACK_DEBIAN_PACKAGE_DEPENDS "") - set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}") - set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}") - set(CPACK_DEB_COMPONENT_INSTALL ON) - set(CPACK_RPM_COMPONENT_INSTALL ON) - set(CPACK_NSIS_COMPONENT_INSTALL ON) - set(CPACK_DEBIAN_COMPRESSION_TYPE "xz") - - set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") - set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") - - set(CMAKE_CONFIG_FILE_BASENAME "${PROJECT_NAME}Config.cmake") - set(CMAKE_EXPORT_FILE_BASENAME "${PROJECT_NAME}Export.cmake") - set(CMAKE_CONFIG_VERSION_FILE_BASENAME "${PROJECT_NAME}ConfigVersion.cmake") - set(CMAKE_CONFIG_VERSION_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CONFIG_VERSION_FILE_BASENAME}") - - export(TARGETS "${PROJECT_NAME}" - NAMESPACE "${EXPORT_NAMESPACE}" - FILE "${CMAKE_EXPORT_FILE_BASENAME}" - EXPORT_LINK_INTERFACE_LIBRARIES - ) +target_include_directories( + ${PROJECT_NAME} INTERFACE $ + $ +) - install(EXPORT "${PROJECT_NAME}" - FILE "${CMAKE_CONFIG_FILE_BASENAME}" - NAMESPACE "${EXPORT_NAMESPACE}" - DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/${PROJECT_NAME}" - ) +if(MAGIC_ENUM_OPT_BUILD_EXAMPLES) + add_subdirectory(example) +endif() - write_basic_package_version_file( - "${CMAKE_CONFIG_VERSION_FILE_NAME}" - #VERSION "100500.100500.100500" # any version of same bitness suits. CMake cannot compare to infinity, so use a large number we expect to be greater than any future version - VERSION ${_VERSION} - COMPATIBILITY AnyNewerVersion - ARCH_INDEPENDENT - ) - install(FILES "${CMAKE_CONFIG_VERSION_FILE_NAME}" - DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/${PROJECT_NAME}" - ) +if(MAGIC_ENUM_OPT_BUILD_TESTS) + enable_testing() + add_subdirectory(test) +endif() - configure_pkg_config_file("${PROJECT_NAME}" - NAME "${PROJECT_NAME}" - VERSION "${PROJECT_VERSION}" - DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}" - URL "${CPACK_PACKAGE_HOMEPAGE_URL}" - INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR_ARCHIND}" - INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" +if(MAGIC_ENUM_OPT_INSTALL) + list(APPEND CMAKE_MODULE_PATH "${ADDITIONAL_MODULES_DIR}/GenPkgConfig") + include(GenPkgConfig) + include(CPackComponent) + include(CMakePackageConfigHelpers) + + install( + TARGETS "${PROJECT_NAME}" + EXPORT ${PROJECT_NAME} + INCLUDES + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + # COMPONENT "${SDK_COMPONENT_NAME}" # component is not allowed for + # includes! + # Headers are installed separately! Includes only marks the headers for + # export + ) + + if(NOT DEFINED PROJECT_INCLUDE_HEADER_PATTERN) + set(PROJECT_INCLUDE_HEADER_PATTERN "*") + endif() + + install( + DIRECTORY ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME} + DESTINATION include + FILES_MATCHING + PATTERN "${PROJECT_INCLUDE_HEADER_PATTERN}" + ) + + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") + set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}") + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all") + set(CPACK_DEBIAN_PACKAGE_NAME "libmagicenum-dev") + set(CPACK_RPM_PACKAGE_NAME "libmagicenum-devel") + set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}") + set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}") + set(CPACK_DEBIAN_PACKAGE_DEPENDS "") + set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}") + set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}") + set(CPACK_DEB_COMPONENT_INSTALL ON) + set(CPACK_RPM_COMPONENT_INSTALL ON) + set(CPACK_NSIS_COMPONENT_INSTALL ON) + set(CPACK_DEBIAN_COMPRESSION_TYPE "xz") + + set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") + set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") + + set(CMAKE_CONFIG_FILE_BASENAME "${PROJECT_NAME}Config.cmake") + set(CMAKE_EXPORT_FILE_BASENAME "${PROJECT_NAME}Export.cmake") + set(CMAKE_CONFIG_VERSION_FILE_BASENAME "${PROJECT_NAME}ConfigVersion.cmake") + set(CMAKE_CONFIG_VERSION_FILE_NAME + "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CONFIG_VERSION_FILE_BASENAME}" + ) + + export( + TARGETS "${PROJECT_NAME}" + NAMESPACE "${EXPORT_NAMESPACE}" + FILE "${CMAKE_EXPORT_FILE_BASENAME}" + EXPORT_LINK_INTERFACE_LIBRARIES + ) + + install( + EXPORT "${PROJECT_NAME}" + FILE "${CMAKE_CONFIG_FILE_BASENAME}" + NAMESPACE "${EXPORT_NAMESPACE}" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}" + ) + + write_basic_package_version_file( + "${CMAKE_CONFIG_VERSION_FILE_NAME}" + # VERSION "100500.100500.100500" # any version of same bitness suits. CMake cannot compare to + # infinity, so use a large number we expect to be greater than any future version + VERSION ${_VERSION} + COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT + ) + install(FILES "${CMAKE_CONFIG_VERSION_FILE_NAME}" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}" + ) + + configure_pkg_config_file( + "${PROJECT_NAME}" + NAME + "${PROJECT_NAME}" + VERSION + "${PROJECT_VERSION}" + DESCRIPTION + "${CPACK_PACKAGE_DESCRIPTION}" + URL + "${CPACK_PACKAGE_HOMEPAGE_URL}" + INSTALL_LIB_DIR + "${CMAKE_INSTALL_DATAROOTDIR}" + INSTALL_INCLUDE_DIR + "${CMAKE_INSTALL_INCLUDEDIR}" + ) + + if(MAGIC_ENUM_OPT_INSTALL_PACKAGE_XML) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/package.xml + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME} ) + endif() - if (MAGIC_ENUM_OPT_INSTALL_PACKAGE_XML) - install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/package.xml - DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}) - endif() - - include(CPack) + include(CPack) endif() diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..84236d7ae --- /dev/null +++ b/Dockerfile @@ -0,0 +1,71 @@ +FROM gentoo/stage3:latest + +RUN echo "Updating Gentoo index registry..." +RUN emerge-webrsync + + +RUN echo "Setting up package manager" +# Allow emerge newer versions of cmake. We need it because vcpkg wants it. +RUN echo "dev-build/cmake ~amd64" >> /etc/portage/package.accept_keywords/unmask +# # Get some packages as binaries and don't compile them. Actually, it allows to not compile only zip :( +# RUN rm -rf /etc/portage/binrepos.conf/* +# RUN echo -e "[binhost]\npriority = 9999\nsync-uri = https://gentoo.osuosl.org/experimental/amd64/binpkg/default/linux/17.1/x86-64/" >> /etc/portage/binrepos.conf/osuosl.conf +# RUN cat /etc/portage/binrepos.conf/* +# Arguments that going to be added automatically to `emerge` command. `man emerge` in help. Or read https://wiki.gentoo.org/wiki/Binary_package_guide/en#Installing_binary_packages . +# RUN echo 'EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --binpkg-respect-use=y --getbinpkg=y --verbose --verbose-conflicts "' >> /etc/portage/make.conf + +RUN echo "Installing dependencies..." + +RUN emerge --quiet --verbose --tree --verbose-conflicts --jobs=2 dev-vcs/git dev-build/cmake zip + +# RUN echo "Installing vcpkg..." +# RUN git clone https://github.com/Microsoft/vcpkg.git && \ +# ./vcpkg/bootstrap-vcpkg.sh -disableMetrics +# +# COPY ./vcpkg.json ./vcpkg.json +# +# RUN echo "Installing dependencies using vcpkg" +# RUN ./vcpkg/vcpkg install + +WORKDIR /backend + +RUN echo "Copy sources of the project" +COPY . . +RUN ls -lah + +# expected to be mounted at runtime as volume. +# COPY resources/ ./resources/ + + +RUN echo "Configuring project..." +RUN cmake -S ./ -B ./build --log-level DEBUG + + +# RUN echo "Building project..." +# RUN cmake --build ./build --parallel $(nproc) --verbose + +RUN echo "really installing" +RUN cmake --install ./build + +RUN echo "checking cmake-cmake" +RUN cmake -S. -B build2 -DMAGIC_ENUM_OPT_TEST_INSTALLED_VERSION=1 --log-level=DEBUG +RUN cmake --build build2 -j $(nproc) --verbose + +RUN echo "checking pkgconfig-cmake" +RUN cat "/usr/local/share/pkgconfig/magic_enum.pc" +RUN cmake -S. -B build3 -DMAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG=1 --log-level=DEBUG +RUN cmake --build build3 -j $(nproc) --verbose + + + +# RUN echo "what's with linking?" +# RUN ls -lahR /usr/local/lib64 +# RUN lddtree /usr/local/lib64/libArby.so +# RUN lddtree /usr/local/bin/Arby + +# CMD ./build/Backend + + + + + diff --git a/example/enum_flag_example.cpp b/example/enum_flag_example.cpp index 0109e74c9..532780af4 100644 --- a/example/enum_flag_example.cpp +++ b/example/enum_flag_example.cpp @@ -23,8 +23,8 @@ #include #include -#include -#include +#include +#include enum class AnimalFlags : std::uint64_t { HasClaws = 1 << 10, CanFly = 1 << 20, EatsFish = 1 << 30, Endangered = std::uint64_t{1} << 40 }; // Add specialization `is_flags` to define that enum are flags. diff --git a/example/example.cpp b/example/example.cpp index 922141e4d..8d06c990a 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -22,8 +22,8 @@ #include -#include -#include +#include +#include enum class Color : int { RED = -10, BLUE = 0, GREEN = 10 }; diff --git a/example/example_containers_array.cpp b/example/example_containers_array.cpp index 70d65dc12..6f9c01c51 100644 --- a/example/example_containers_array.cpp +++ b/example/example_containers_array.cpp @@ -23,7 +23,7 @@ #include -#include +#include enum class Color { RED = 1, GREEN = 2, BLUE = 4 }; template <> diff --git a/example/example_containers_bitset.cpp b/example/example_containers_bitset.cpp index f50b6b787..3e0c86590 100644 --- a/example/example_containers_bitset.cpp +++ b/example/example_containers_bitset.cpp @@ -28,7 +28,7 @@ #include -#include +#include enum class Color { RED = 1, GREEN = 2, BLUE = 4 }; template <> diff --git a/example/example_containers_set.cpp b/example/example_containers_set.cpp index 67de9e77c..d017d09e6 100644 --- a/example/example_containers_set.cpp +++ b/example/example_containers_set.cpp @@ -28,7 +28,7 @@ #include -#include +#include enum class Color { RED = 1, GREEN = 2, BLUE = 4 }; template <> diff --git a/example/example_custom_name.cpp b/example/example_custom_name.cpp index a432c7ffc..f1e59d86c 100644 --- a/example/example_custom_name.cpp +++ b/example/example_custom_name.cpp @@ -22,7 +22,7 @@ #include -#include +#include enum class Color : int { RED = -10, BLUE = 0, GREEN = 10 }; diff --git a/example/example_nonascii_name.cpp b/example/example_nonascii_name.cpp index 4fdbcd8ee..b9741801f 100644 --- a/example/example_nonascii_name.cpp +++ b/example/example_nonascii_name.cpp @@ -23,7 +23,7 @@ #include -#include +#include enum class Language : int { 日本語 = 10, diff --git a/example/example_switch.cpp b/example/example_switch.cpp index 76645eda2..217f036fa 100644 --- a/example/example_switch.cpp +++ b/example/example_switch.cpp @@ -24,7 +24,7 @@ #include #define MAGIC_ENUM_ENABLE_HASH -#include +#include enum class Color { RED, BLUE, GREEN }; diff --git a/meson.build b/meson.build index 207c83440..a0d22b04d 100644 --- a/meson.build +++ b/meson.build @@ -4,7 +4,7 @@ project( version: '0.9.6', ) -magic_enum_include = include_directories('include/magic_enum') +magic_enum_include = include_directories('include') magic_enum_args = [] diff --git a/module/magic_enum.cppm b/module/magic_enum.cppm index db43bcbaf..e4898cbfd 100644 --- a/module/magic_enum.cppm +++ b/module/magic_enum.cppm @@ -2,7 +2,7 @@ module; #include #ifndef MAGIC_ENUM_USE_STD_MODULE -#include +#include #endif export module magic_enum; @@ -13,7 +13,7 @@ import std; extern "C++" { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Winclude-angled-in-module-purview" -#include +#include #pragma clang diagnostic pop } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d74755cf5..2ccd67b59 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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() diff --git a/test/test.cpp b/test/test.cpp index 81516fb32..ef0459dae 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -26,10 +26,10 @@ #define MAGIC_ENUM_NO_CHECK_REFLECTED_ENUM #define MAGIC_ENUM_RANGE_MIN -120 #define MAGIC_ENUM_RANGE_MAX 120 -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -1176,7 +1176,7 @@ TEST_CASE("multdimensional-switch-case") { #if defined(__cpp_lib_format) -#include +#include TEST_CASE("format-base") { REQUIRE(std::format("{}", Color::RED) == "red"); diff --git a/test/test_aliases.cpp b/test/test_aliases.cpp index 4af111ebf..2a012e704 100644 --- a/test/test_aliases.cpp +++ b/test/test_aliases.cpp @@ -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 -#include +#include +#include using namespace magic_enum; using namespace magic_enum::bitwise_operators; diff --git a/test/test_containers.cpp b/test/test_containers.cpp index b4389e4c8..33f1cd46f 100644 --- a/test/test_containers.cpp +++ b/test/test_containers.cpp @@ -33,8 +33,8 @@ #define CATCH_CONFIG_MAIN #include -#include -#include +#include +#include #include diff --git a/test/test_flags.cpp b/test/test_flags.cpp index 151659c25..d7f01ece7 100644 --- a/test/test_flags.cpp +++ b/test/test_flags.cpp @@ -32,11 +32,11 @@ #define CATCH_CONFIG_MAIN #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -91,8 +91,8 @@ struct magic_enum::customize::enum_range { static constexpr bool is_flags = true; }; -#include -#include +#include +#include using namespace magic_enum; using namespace magic_enum::bitwise_operators; @@ -720,7 +720,7 @@ TEST_CASE("constexpr_for") { #if defined(__cpp_lib_format) -#include +#include TEST_CASE("format-base") { REQUIRE(std::format("Test-{:~^11}.", Color::RED | Color::GREEN) == "Test-~RED|GREEN~."); diff --git a/test/test_nonascii.cpp b/test/test_nonascii.cpp index 66e7e5337..3f10c0035 100644 --- a/test/test_nonascii.cpp +++ b/test/test_nonascii.cpp @@ -27,9 +27,9 @@ #define MAGIC_ENUM_RANGE_MIN -120 #undef MAGIC_ENUM_RANGE_MAX #define MAGIC_ENUM_RANGE_MAX 120 -#include -#include -#include +#include +#include +#include #include #include diff --git a/test/test_wchar_t.cpp b/test/test_wchar_t.cpp index f09509894..f372627bc 100644 --- a/test/test_wchar_t.cpp +++ b/test/test_wchar_t.cpp @@ -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 -#include +#include +#include #include #include diff --git a/test_installed_version.bash b/test_installed_version.bash new file mode 100644 index 000000000..d699693bf --- /dev/null +++ b/test_installed_version.bash @@ -0,0 +1,13 @@ +#!/bin/bash +rm -rf ./build +rm -rf ./build2 +rm -rf ./build3 +rm -rf ./install_dir/ +cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release --log-level=DEBUG -DCMAKE_INSTALL_PREFIX=install_dir +cmake --build ./build -j$(nproc) +cmake --install ./build/ --prefix ./install_dir +CMAKE_PREFIX_PATH="./install_dir" cmake -S. -Bbuild2 -DMAGIC_ENUM_OPT_TEST_INSTALLED_VERSION=1 --log-level=DEBUG +cmake --build build2 --config Debug -j$(nproc) --verbose +CMAKE_PREFIX_PATH="./install_dir" cmake -S. -Bbuild3 -DMAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG=1 --log-level=DEBUG +cmake --build build3 --config Debug -j$(nproc) --verbose +