Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if(MAGIC_ENUM_OPT_VERIFY_INTERFACE_HEADER_SETS)
if(CMAKE_VERSION VERSION_LESS "3.24")
message(FATAL_ERROR "MAGIC_ENUM_OPT_VERIFY_INTERFACE_HEADER_SETS requires CMake >= 3.24")
endif()
set_property(TARGET ${PROJECT_NAME} PROPERTY VERIFY_INTERFACE_HEADER_SETS ON)
set_property(TARGET ${PROJECT_NAME} PROPERTY VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL})

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this too: normally not needed if not top level project!

endif()

set(MAGIC_ENUM_MODULE_FMT_TARGET)
Expand Down Expand Up @@ -192,7 +192,7 @@ function(magic_enum_make_module_library name)
endif()
message(STATUS "${name}: using import std")
set_property(TARGET ${name} PROPERTY CXX_MODULE_STD ON)
target_compile_definitions(${name} PRIVATE MAGIC_ENUM_USE_STD_MODULE)
target_compile_definitions(${name} PUBLIC MAGIC_ENUM_USE_STD_MODULE)
elseif(CMAKE_VERSION VERSION_GREATER_EQUAL "3.31")
set_property(TARGET ${name} PROPERTY CXX_MODULE_STD OFF)
endif()
Expand Down
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ if(MAGIC_ENUM_USE_MODULES)
set_target_properties(example_module_usage PROPERTIES CXX_SCAN_FOR_MODULES ON)
if(MAGIC_ENUM_MODULE_IMPORT_STD)
set_property(TARGET example_module_usage PROPERTY CXX_MODULE_STD ON)
target_compile_definitions(example_module_usage PRIVATE MAGIC_ENUM_TEST_IMPORT_STD)
# XXX target_compile_definitions(example_module_usage PRIVATE MAGIC_ENUM_TEST_IMPORT_STD)
endif()
endif()
7 changes: 4 additions & 3 deletions module/magic_enum.cppm
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module;

#include <version>
#ifdef MAGIC_ENUM_USE_FMT_HEADER
# include <fmt/format.h>
#endif

#ifndef MAGIC_ENUM_USE_STD_MODULE

# ifdef MAGIC_ENUM_USE_FMT_HEADER
# include <fmt/format.h>
# endif

# include <compare>
# include <cstdlib>
# if __has_include(<format>)
Expand Down
41 changes: 40 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function(magic_enum_make_module_test src target module_target)
CXX_SCAN_FOR_MODULES ON
)
if(MAGIC_ENUM_MODULE_IMPORT_STD)
target_compile_definitions(${target} PRIVATE MAGIC_ENUM_TEST_IMPORT_STD)
# XXX target_compile_definitions(${target} PRIVATE MAGIC_ENUM_TEST_IMPORT_STD)
set_property(TARGET ${target} PROPERTY CXX_MODULE_STD ON)
endif()
add_test(NAME ${target} COMMAND ${target})
Expand Down Expand Up @@ -259,3 +259,42 @@ if(MAGIC_ENUM_USE_MODULES AND MAGIC_ENUM_OPT_INSTALL AND
)
set_tests_properties(installed-module-consumer PROPERTIES FIXTURES_REQUIRED magic_enum_installed_module)
endif()

if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
return()
endif()

#======================================================================
# NOTE: Only for Release build with enabled install rules useful! CK
#======================================================================
if(MAGIC_ENUM_MODULE_IMPORT_STD AND MAGIC_ENUM_OPT_INSTALL AND NOT CMAKE_SKIP_INSTALL_RULES)
# test if the targets are usable from the install directory
add_test(
NAME install-to-stagedir
COMMAND
${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --prefix
${CMAKE_CURRENT_BINARY_DIR}/stagedir --config $<CONFIG>
)
add_test(
NAME find-package-test
COMMAND
${CMAKE_CTEST_COMMAND} # --verbose
--output-on-failure -C $<CONFIG> #
--build-and-test "${CMAKE_SOURCE_DIR}/test/installed_module"
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test" #
--build-generator ${CMAKE_GENERATOR} #
--build-makeprogram ${CMAKE_MAKE_PROGRAM} #
--build-options #
"-D MAGIC_ENUM_EXPECT_FMT=${MAGIC_ENUM_MODULE_WITH_FMT}"
"-D MAGIC_ENUM_EXPECT_FMT_MODULE=${MAGIC_ENUM_MODULE_USES_FMT_MODULE}"
"-D MAGIC_ENUM_EXPECT_IMPORT_STD=${MAGIC_ENUM_MODULE_IMPORT_STD}"
"-D CMAKE_BUILD_TYPE=$<CONFIG>"
"-D CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-D CMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}"
"-D CMAKE_CXX_MODULE_STD=${CMAKE_CXX_MODULE_STD}"
"-D CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-D CMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}"
"-D CMAKE_PREFIX_PATH=${CMAKE_CURRENT_BINARY_DIR}/stagedir"
"-D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD=${CMAKE_EXPERIMENTAL_CXX_IMPORT_STD}"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this import std; is not possible today (CMake v4.4.2)

)
endif()
2 changes: 1 addition & 1 deletion test/installed_module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.28)
cmake_minimum_required(VERSION 3.30...4.4)

project(magic_enum_installed_module_test LANGUAGES CXX)

Expand Down
67 changes: 67 additions & 0 deletions test_installed_version.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
set -euo pipefail

repo_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
build_root="${repo_root}/build"
source_build_dir="${build_root}/source"
configured_install_dir="${build_root}/configured-install"
install_dir="${build_root}/install"
consumer_prefix="${build_root}/relocated-install"
cmake_consumer_build_dir="${build_root}/cmake-consumer"
pkgconfig_consumer_build_dir="${build_root}/pkgconfig-consumer"
cxx_modules_consumer_build_dir="${build_root}/cxx_modules-consumer"

test_installed_consumer() {
local build_dir="$1"
shift

CMAKE_PREFIX_PATH="${consumer_prefix}" cmake -S "${repo_root}" -B "${build_dir}" \
-G Ninja \
-D CMAKE_BUILD_TYPE=Debug \
"$@"
cmake --build "${build_dir}" --parallel
ctest --test-dir "${build_dir}" --output-on-failure --no-tests=error
}

cmake --version
cmake -E remove_directory "${build_root}"

cmake -S "${repo_root}" -B "${source_build_dir}" -G Ninja \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_CXX_STANDARD=23 \
-D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD=f35a9ac6-8463-4d38-8eec-5d6008153e7d \
-D CMAKE_INSTALL_PREFIX="${configured_install_dir}" \
-D MAGIC_ENUM_MODULE_IMPORT_STD=YES \
-D MAGIC_ENUM_MODULE_WITH_FMT=NO \
-D MAGIC_ENUM_OPT_BUILD_EXAMPLES=OFF \
-D MAGIC_ENUM_OPT_BUILD_TESTS=YES \
-D MAGIC_ENUM_OPT_INSTALL=ON \
-D MAGIC_ENUM_OPT_VERIFY_INTERFACE_HEADER_SETS=ON \
-D MAGIC_ENUM_USE_MODULES=YES -Wdev --log-level=VERBOSE # XXX --fresh
cmake --build "${source_build_dir}" \
--target magic_enum_verify_interface_header_sets \
--parallel
cmake --build "${source_build_dir}" \
--target all \
--parallel
ctest --test-dir "${source_build_dir}" --output-on-failure --no-tests=error

# cmake --install "${source_build_dir}" --prefix "${install_dir}"
# cmake -E copy_directory "${install_dir}" "${consumer_prefix}"

# test_installed_consumer "${cxx_modules_consumer_build_dir}" \
# -D CMAKE_CXX_STANDARD=23 \
# -D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD=f35a9ac6-8463-4d38-8eec-5d6008153e7d \
# -D MAGIC_ENUM_MODULE_IMPORT_STD=YES \
# -D MAGIC_ENUM_MODULE_WITH_FMT=NO \
# -D MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION=ON \
# -D MAGIC_ENUM_USE_MODULES=YES \
# -D PKG_CONFIG_USE_CMAKE_PREFIX_PATH=YES --fresh

# test_installed_consumer "${cmake_consumer_build_dir}" \
# -D MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION=ON

# test_installed_consumer "${pkgconfig_consumer_build_dir}" \
# -D MAGIC_ENUM_OPT_TEST_INSTALLED_VERSION_PKGCONFIG=ON \
# -D PKG_CONFIG_USE_CMAKE_PREFIX_PATH=ON