getml / reflect-cpp

A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]
https://getml.github.io/reflect-cpp/
MIT License
990 stars 85 forks source link

Make library work on clang on windows #57

Closed grandseiken closed 8 months ago

grandseiken commented 8 months ago

This fixes https://github.com/getml/reflect-cpp/issues/56.

As described in that issue, the function_name() obtained from std::source_location on clang on windows does not include template parameters, which means the tricks used by the library to determine names automatically just don't work. However, __PRETTY_FUNCTION__ does contain the template parameters and gives the exact string we wanted.

This works whether running clang directly on Windows or whether via clang-cl, since both __clang__ and _MSC_VER are defined in either case.

I did a few tests of some basic functionality of the library and everything seemed to work as expected now.

grandseiken commented 8 months ago

I managed to run the tests successfully as well after installing cmake and the ClangCl build tools for Visual Studio:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DREFLECTCPP_BUILD_TESTS=ON -G"Visual Studio 17 2022" -T ClangCl
cmake --build build --config Release -j 4
./build/tests/json/Release/reflect-cpp-json-tests.exe
liuzicheng1987 commented 8 months ago

@grandseiken , thank you so much for this PR.