GothicKit / ZenKit

A re-implementation of file formats used by the early 2000's ZenGin
http://zk.gothickit.dev/
MIT License
44 stars 10 forks source link

Building with MSVC / Visual Studio 2019 (compile errors) #8

Closed Katharsas closed 1 year ago

Katharsas commented 1 year ago

Hi,

i tried building this with CMake 3.24.1 Visual Studio 2019 project generator. Cmake Output:

Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
The C compiler identification is MSVC 19.29.30146.0
The CXX compiler identification is MSVC 19.29.30146.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
GLM: Version 0.9.9.9
Module support is disabled.
Version: 9.1.1
Build type: 
CXX_STANDARD: 20
Required features: cxx_variadic_templates
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1264 (message):
  The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
  not set.  The policy's OLD behavior will be used.  When using a URL
  download, the timestamps of extracted files should preferably be that of
  the time of extraction, otherwise code that depends on the extracted
  contents might not be rebuilt if the URL changes.  The OLD behavior
  preserves the timestamps from the archive instead, but this is usually not
  what you want.  Update your project to the NEW behavior or specify the
  DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
  robustness issue.
Call Stack (most recent call first):
  vendor/CMakeLists.txt:12 (FetchContent_Declare)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at build/_deps/libsquish-src/CMakeLists.txt:14 (CMAKE_MINIMUM_REQUIRED):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

Configuring done
Generating done
CMake Error: Cannot open file for write: C:/Users/User/Eigene Repositories/Renderer/phoenix/build/tools/zdump/phoenix::tools::zinfo.sln.tmp77450
CMake Error: : System Error: Invalid argument
CMake Error: Cannot open file for write: C:/Users/User/Eigene Repositories/Renderer/phoenix/build/tools/zmodel/phoenix::tools::zmodel.sln.tmp07b13
CMake Error: : System Error: Invalid argument
CMake Error: Cannot open file for write: C:/Users/User/Eigene Repositories/Renderer/phoenix/build/tools/zscript/phoenix::tools::zscript.sln.tmp17120
CMake Error: : System Error: Invalid argument
CMake Error: Cannot open file for write: C:/Users/User/Eigene Repositories/Renderer/phoenix/build/tools/ztex/phoenix::tools::ztex.sln.tmp44674
CMake Error: : System Error: Invalid argument
CMake Error: Cannot open file for write: C:/Users/User/Eigene Repositories/Renderer/phoenix/build/tools/zvdfs/phoenix::tools::zvdfs.sln.tmpdf74c
CMake Error: : System Error: Invalid argument

No idea whats up with the CMake errors at the end there, i ignored them. Then to fix project setup i needed to change:

Properties (all configurations) -> C++/Command Line/Additional Options:

I think these flags do only apply to certain compilers and should not be set if MSVC is used. After that i can build much more than before, however I still get a lot of compile errors (Debug x64):

Severity Code Description Project File Line
Error C2665 'std::from_chars': none of the 14 overloads could convert all the argument types phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\source\archive\archive_ascii.cc 146
Error C2039 'base': is not a member of 'std::_String_iterator<std::_String_val<std::_Simple_types<_Elem>>>' phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\source\archive\archive_ascii.cc 140
Error C3536 'beg_it': cannot be used before it is initialized phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\source\archive\archive_ascii.cc 146
Error C2665 'std::from_chars': none of the 14 overloads could convert all the argument types phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\source\archive\archive_ascii.cc 147
Error C2665 'std::from_chars': none of the 14 overloads could convert all the argument types phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\source\archive\archive_ascii.cc 148
Error C2665 'std::from_chars': none of the 14 overloads could convert all the argument types phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\source\archive\archive_ascii.cc 149
Error C2039 'base': is not a member of 'std::_String_iterator<std::_String_val<std::_Simple_types<_Elem>>>' phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\source\archive\archive_ascii.cc 163
Error C3536 'beg_it': cannot be used before it is initialized phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\source\archive\archive_ascii.cc 166
Error C2665 'std::from_chars': none of the 14 overloads could convert all the argument types phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\source\archive\archive_ascii.cc 166
Error C2440 'initializing': cannot convert from 'int' to 'phoenix::alpha_function' phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\include\phoenix\material.hh 87
Error C2440 'initializing': cannot convert from 'int' to 'phoenix::alpha_function' phoenix C:\Users\User\Eigene Repositories\Renderer\phoenix\include\phoenix\material.hh 87
Error LNK1104 cannot open file '....\lib\Debug\phoenix.lib' zscript C:\Users\User\Eigene Repositories\Renderer\phoenix\build\tools\zscript\LINK 1
Error LNK1104 cannot open file '....\lib\Debug\phoenix.lib' zmodel C:\Users\User\Eigene Repositories\Renderer\phoenix\build\tools\zmodel\LINK 1
Error LNK1104 cannot open file '....\lib\Debug\phoenix.lib' zdump C:\Users\User\Eigene Repositories\Renderer\phoenix\build\tools\zdump\LINK 1
Error LNK1104 cannot open file '....\lib\Debug\phoenix.lib' zvdfs C:\Users\User\Eigene Repositories\Renderer\phoenix\build\tools\zvdfs\LINK 1
Error LNK1104 cannot open file '....\lib\Debug\phoenix.lib' ztex C:\Users\User\Eigene Repositories\Renderer\phoenix\build\tools\ztex\LINK 1
Error C2079 'array' uses undefined class 'std::array<std::byte,2>' phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 259
Error C2666 'phoenix::buffer::get': 3 overloads have similar conversions phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 260
Error C2672 'std::equal': no matching overloaded function found phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 264
Error C2780 'bool std::equal(_ExPo &&,const _FwdIt1,const _FwdIt1,const _FwdIt2,const _FwdIt2) noexcept': expects 5 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 264
Error C2780 'bool std::equal(const _InIt1,const _InIt1,const _InIt2,const _InIt2)': expects 4 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 264
Error C2780 'bool std::equal(_ExPo &&,const _FwdIt1,const _FwdIt1,const _FwdIt2,const _FwdIt2,_Pr) noexcept': expects 6 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 264
Error C2780 'bool std::equal(const _InIt1,const _InIt1,const _InIt2,const _InIt2,_Pr)': expects 5 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 264
Error C2780 'bool std::equal(_ExPo &&,const _FwdIt1,const _FwdIt1,const _FwdIt2) noexcept': expects 4 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 264
Error C2780 'bool std::equal(const _InIt1,const _InIt1,const _InIt2)': expects 3 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 264
Error C2780 'bool std::equal(_ExPo &&,const _FwdIt1,const _FwdIt1,const _FwdIt2,_Pr) noexcept': expects 5 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 264
Error C2780 'bool std::equal(const _InIt1,const _InIt1,const _InIt2,_Pr)': expects 4 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 264
Error C2079 'array' uses undefined class 'std::array<std::byte,2>' phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 274
Error C2664 'void phoenix::buffer::get(uint64_t,std::span<std::byte,18446744073709551615>) const': cannot convert argument 2 from 'int' to 'std::span<std::byte,18446744073709551615>' phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 275
Error C2672 'std::equal': no matching overloaded function found phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 278
Error C2780 'bool std::equal(_ExPo &&,const _FwdIt1,const _FwdIt1,const _FwdIt2,const _FwdIt2) noexcept': expects 5 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 278
Error C2780 'bool std::equal(const _InIt1,const _InIt1,const _InIt2,const _InIt2)': expects 4 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 278
Error C2780 'bool std::equal(_ExPo &&,const _FwdIt1,const _FwdIt1,const _FwdIt2,const _FwdIt2,_Pr) noexcept': expects 6 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 278
Error C2780 'bool std::equal(const _InIt1,const _InIt1,const _InIt2,const _InIt2,_Pr)': expects 5 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 278
Error C2780 'bool std::equal(_ExPo &&,const _FwdIt1,const _FwdIt1,const _FwdIt2) noexcept': expects 4 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 278
Error C2780 'bool std::equal(const _InIt1,const _InIt1,const _InIt2)': expects 3 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 278
Error C2780 'bool std::equal(_ExPo &&,const _FwdIt1,const _FwdIt1,const _FwdIt2,_Pr) noexcept': expects 5 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 278
Error C2780 'bool std::equal(const _InIt1,const _InIt1,const _InIt2,_Pr)': expects 4 arguments - 2 provided phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 278
Error C2664 'void phoenix::buffer::get(uint64_t,std::span<std::byte,18446744073709551615>) const': cannot convert argument 2 from 'int' to 'std::span<std::byte,18446744073709551615>' phoenix-tests C:\Users\User\Eigene Repositories\Renderer\phoenix\tests\test_buffer.cc 281

Looks similar when building in release mode. The projects are configured with ISO C++20 Standard (/std:c++20).

I might try again with a later version of Visual Studio, but for Visual Studio 19 it seems to much work to get it running. Maybe not all used C++ 20 features are supported by MSVC, i don't know.

lmichaelis commented 1 year ago

Hi there! Thanks for the detailed report :) From what I can gather right now, it looks like you're right about the compiler flags at least. Those should be an easy fix and I'll look into them later.

As for all the other compilation errors, I'll have to set up a Windows VM to test MSVC so that might take a bit I've set up a VM to test. As far as I know, MSVC does support all features of C++20 so these errors must be something else.

Problems:

I'll fix these once I get home :)

lmichaelis commented 1 year ago

I've fixed the issues I can see right now in the platforms/support-msvc branch and phoenix now builds with Visual Studio 2019 :slightly_smiling_face: @Katharsas can you clone that branch and check that everything works as intended?

Katharsas commented 1 year ago

========== Build: 13 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== Thanks, it works for me! This is great (I have not tested actually running anything, but might try that soonish). This can be closed i would say.

One small annoyance, not important though for now: Header files are not shown nicely by Visual Studio, they are lying around with system headers in external section: image It seems to be this problem: https://stackoverflow.com/questions/32584319/display-include-directory-as-separate-part-of-project-in-visual-studio-using-cma

If I have the need to make some changes, i might look into improving that, but maybe it will not be necessary.

lmichaelis commented 1 year ago

That's cool! I'm happy it wasn't anything too big :D As for the weird placement of header files, that doesn't seem to be a difficult thing to solve too. I'll implement a basic workaround since it seems to be just a few lines of CMake. I would expect config.hh to appear there, however, since it is generated from config.hh.in.

lmichaelis commented 1 year ago

@Katharsas MSVC/Visual Studio support is now merged into main :tada: All project and header files of the phoenix target should now show up correctly in the project view. If you intend to use the phoenix library itself for a project, just be aware that it is changing rapidly at the moment and you will have to make changes to your code when you update. I'm hoping to have a stable API by the end of September or in early to mid October.