![]() |
Cesium for Unreal 2.18.0
|
Compiling Cesium for Unreal requires that the vcpkg-based third-party dependencies, the cesium-native code, and the Cesium for Unreal code itself are compiled using the same (or compatible) versions of the MSVC compiler. This is remarkably hard to achieve! This guide will hopefully help you get there.
Some important facts to understand before continuing:
The Cesium for Unreal plugin code includes and links with a great deal of Unreal Engine code. It is built by the Unreal Build Tool, even when you compile from within Visual Studio.
The MSVC compiler version that Epic used to build a release version of Unreal Engine can be found in that version's release notes. For example, the release notes for Unreal Engine 5.4 include this information:
- IDE Version the Build farm compiles against
- Visual Studio: Visual Studio 2022 17.8 14.38.33130 toolchain and Windows 10 SDK (10.0.18362.0)
For maximum compatibility, released versions of Cesium for Unreal should be built with exactly this version, v14.38.33130, and this is what we do on CI.
However, when compiling for your own development purposes, you can use this version or any compatible newer one. In general, newer compilers work just fine, but not always. A change in the v14.42 compiler (and later versions) means that some Unreal Engine 5.4 header files cannot be compiled with it. So, on development systems, we usually use the v14.38 toolchain, because this version works with all currently-supported versions of Unreal Engine: 5.4, 5.5, and 5.6. Install it from Add/Remove Programs by following the instructions in the top section.
The Unreal Build Tool will use the latest compiler version that you have installed. So even after installing v14.38, Cesium for Unreal will likely attempt to compile with a later version like v14.44, and fail. It's possible to uninstall all the newer versions, but this is a huge hassle if you need the newer compiler for other projects.
The solution is to explicitly tell the Unreal Build Tool to use v14.38. To do that, open %AppData%\Unreal Engine\UnrealBuildTool\BuildConfiguration.xml
and add this to it:
%AppData%
resolves to something like C:\Users\UserName\AppData\Roaming
. In PowerShell, use $env:AppData
instead.With that, all builds invoked by Unreal Build Tool should use the chosen compiler version. You should see a message near the start of the build log confirming this:
Using Visual Studio 2022 14.38.33144 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130) and Windows 10.0.22621.0 SDK (C:\Program Files (x86)\Windows Kits\10).
If you've followed the instructions above, and Unreal Build Tool is now building Cesium for Unreal with v14.38 of the compiler, then you will likely get linker errors because the cesium-native and third-party dependencies are both still built with the newer version of the compiler.
vcpkg has hard-coded logic to choose the very latest version of the compiler that you have installed. It completely ignores all the usual ways that different compiler versions can be selected, such as setting the defaults file ("C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.props"
), setting environment variables or running the vcvarsall
script. The only way to choose a compiler for vcpkg to use, as far as we know, is by explicitly specifying it in a vcpkg triplet file. So, to build with 14.38, edit the extern/vcpkg-overlays/triplets/x64-windows-unreal.cmake
file in the cesium-unreal
repo and add this line to the end of it:
Be careful not to commit this change!
vcpkg won't always automatically rebuild everything it needs to rebuild after making this change. To force a rebuild, delete the following:
.ezvcpkg
directory. It's usually found at c:\.ezvcpkg
or userprofile%\.ezvcpkg
. If you're not sure, look for where ezvcpkg prints local dir: d:/.ezvcpkg/dbe35ceb30c688bf72e952ab23778e009a578f18
or similar during the cesium-native CMake configure.LOCALAPPDATA%\vcpkg\archives
(or $env:LOCALAPPDATA\vcpkg\archives
in PowerShell).cesium-native chooses compilers in the normal CMake way. That means that, by default, it will use the compiler version that you installed most recently (which is not necessarily the latest). So if you installed 14.38 following the instructions above, the cesium-native build should automatically start using it. You may need to delete your build
directory.
To specify a particular compiler, you can use vcvarsall.bat
:
Note that you must do this from a CMD prompt, not from PowerShell. But you can run PowerShell afterward by invoking pwsh
or powershell
.
You can also specify the compiler version on the CMake command-line:
A common scenario is that you've followed the instructions in this document and installed v14.38, and your Cesium for Unreal build is working fine. Then, you try to compile some other CMake-based project that should be using the newer compiler, and it doesn't work anymore. The other project's build is unexpectedly using the v14.38 compiler. It makes sense that 14.38 would be the default, because that's the one you installed most recently. But even following either one or both of the suggestions above doesn't help. CMake continues to insist on using 14.38. What's the deal?
The solution here is to explicitly install the version of the build tools that you're trying to use. In "Add / Remove Programs" -> Modify "Visual Studio Professional 2022" -> "Invididual Components" tabs, you'll probably see that the box next to the "MSVC v143 - VS2022 C++ x64/x86 build tools (Latest)" is ticked. But the specific version that actually is the latest (14.44 as of this writing) is not ticked. If you install that one, you will now be able to explicitly select it in CMake builds using either of the techniques above. It is very frustating that this kind of thing is required.
You may have different projects that need to use different compiler versions. If you use Visual Studio Code, the easiest way to deal with this is to set up custom "kits" for the different versions.
Open the command palette (Ctrl-Shift-P) and choose CMake: Edit User-Local CMake Kits
. Make two copies of the JSON object for the existing amd64
kit. It will have a name similar to Visual Studio Professional 2022 Release - amd64
. Name the two copies for the compiler version you want each to use, such as 14.38 - Visual Studio Professional 2022 Release - amd64
. Then, do the following:
version=14.38
or similar to the preferredGenerator.toolset
property.VCToolsVersion
environment variable with the full three-part version. You can find the three-part version for your installed toolsets by looking in C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC
or similar.It should look like this (though your names and visualStudio
properties may be different):
You can now choose your compiler by invoking CMake: Select a kit
from the command palette.
If this doesn't work (your build uses the wrong compiler), check that you've explicitly installed both compiler versions, as described at the end of the cesium-native section above.