-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use <mpark/variant.hpp> indiscriminately #1121
Conversation
I think we might want to store the mpark-variant choice used at openPMD-api compile time in our |
This PR is only going to be a workaround until we switch to C++17 and can use std::optional instead of mpark::optional entirely. So I'm not sure it's worth the effort for that? |
The problem is that our variant is part of the public API, thus it needs to be installed as well. |
Just for the record: For the reproducer above: which compiler did you use and what's the error message? |
I tried this with several compilers, and with different results:
My guess is that
Ok, so memorizing the chosen version with |
I think I see the same problem on Windows with C++17 builds:
ECP-WarpX/WarpX#1776 (comment)
|
Is there even a way to use
I think that's currently only a todo, # C++11 std::variant (C++17 stdlib preview)
# TODO not needed with C++17 compiler
add_library(openPMD::thirdparty::mpark_variant INTERFACE IMPORTED)
set(openPMD_PC_EXTRA_INCLUDE "")
if(openPMD_USE_INTERNAL_VARIANT)
target_include_directories(openPMD::thirdparty::mpark_variant SYSTEM INTERFACE
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/variant/include>
)
message(STATUS "MPark.Variant: Using INTERNAL version '1.4.0'")
else()
find_package(mpark_variant 1.3.0 REQUIRED) # TODO: we want 1.4.1+
target_link_libraries(openPMD::thirdparty::mpark_variant
INTERFACE mpark_variant)
get_target_property(EXTERNAL_MPARK_INCLUDE mpark_variant INTERFACE_INCLUDE_DIRECTORIES)
if(openPMD_HAVE_PKGCONFIG AND EXTERNAL_MPARK_INCLUDE)
set(openPMD_PC_EXTRA_INCLUDE "-I${EXTERNAL_MPARK_INCLUDE}")
endif()
message(STATUS "MPark.Variant: Found version '${mpark_variant_VERSION}'")
endif()
target_link_libraries(openPMD PUBLIC openPMD::thirdparty::mpark_variant) |
I'll propose something based on |
Our header
include/openPMD/auxiliary/VariantSrc.hpp
currently inspects the C++ version with a macro and uses eitherstd::variant
ormpark::variant
depending on the found version. In a public header, that can lead to trouble if the user code uses a different C++ version compared to openPMD-api.Bug can be reproduced with the following writer: