|
| 1 | +# Building and Compiling C&C Generals & Zero Hour on Visual Studio 2022 |
| 2 | + |
| 3 | +This guide will walk you through the process of basic setup and compilation of the C&C Generals and Zero Hour source |
| 4 | +code using Visual Studio 2022. |
| 5 | +For build using solutions and more advanced build configurations, see below. |
| 6 | + |
| 7 | +- [Prerequisites](#prerequisites) |
| 8 | +- [Build through Visual Studio 2022](#build-through-visual-studio-2022) |
| 9 | +- [Build through CMake target view](#build-through-cmake-target-view) |
| 10 | +- [Build using command line](#build-using-command-line) |
| 11 | +- [Build using solutions](#build-with-solutions) |
| 12 | +- [Troubleshooting](#troubleshooting) |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +1. **Visual Studio 2022** |
| 17 | + |
| 18 | +- Ensure that the necessary C++ development components, **including MFC**, are installed. |
| 19 | + |
| 20 | +>[!NOTE] |
| 21 | +> You must have the MFC components installed to compile the source code. You can find it in Visual Studio Installer. |
| 22 | +> |
| 23 | +>  |
| 24 | +
|
| 25 | +<!-- markdownlint-disable-next-line --> |
| 26 | +2. **Obtain the Source Code** |
| 27 | + - Clone or download the source code |
| 28 | + repository: [TheSuperHackers - GeneralsGameCode](https://github.com/TheSuperHackers/GeneralsGameCode.git). |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Build through Visual Studio 2022 |
| 33 | + |
| 34 | +### 1. Prepare the project |
| 35 | + |
| 36 | +- Open the cloned folder in Visual Studio 2022. |
| 37 | +- Wait for Visual Studio to generate the necessary CMake files. |
| 38 | + |
| 39 | +### 2. Build the Project |
| 40 | + |
| 41 | +- Select the appropriate build configuration: |
| 42 | + - `Build Windows build` for a release build. |
| 43 | + - `Build Windows Debug build` for a debug build. |
| 44 | + - `Build Windows Internal build` for an internal build. |
| 45 | + - `Build Windows Profile build` for a profile build. |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +>[!TIP] |
| 50 | +> For more information on the different build configurations, see the [Build Configurations](build_configurations.md) |
| 51 | +page. |
| 52 | + |
| 53 | +- Select the target you want to build: |
| 54 | + - `generalsv.exe` to build the base Generals. |
| 55 | + - `generalszh.exe` to build Zero Hour. |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +- Build the project by clicking on the `Build` menu and selecting `Build`. |
| 60 | +- The compiled executable will be placed in the build folder. Example: `build/win32dgb/GeneralsMD/Debug` |
| 61 | +- Install the game executable in the game directory by clicking on the `Install` in `Build` menu. This will copy the |
| 62 | + executable to the retail game directory. |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## Build through CMake target view |
| 67 | + |
| 68 | +- In the Solution Explorer, click on 'switch view' and select 'CMake Targets View'. |
| 69 | +- Expand the 'Genzh' project and right-click on the target you want to build. |
| 70 | +- Select 'Build' to compile the target. |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +## Build using command line |
| 77 | + |
| 78 | +You need to install [CMake](https://cmake.org/download/) and [Ninja](https://github.com/ninja-build/ninja/releases) |
| 79 | +to build the project from the command line. |
| 80 | + |
| 81 | +- In the developer command prompt, open the settings to add the x86 environment terminal. |
| 82 | +- In the pop-up window, click on the 'Add' and set the following: (assuming default installation path) |
| 83 | + - Name: `x86 Native Tools Command Prompt` |
| 84 | + - Shell Location: `C:\Windows\System32\cmd.exe` |
| 85 | + - Arguments: `/k "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat"` |
| 86 | +- Now you can open the new terminal from the terminal dropdown list. |
| 87 | + |
| 88 | +>[!Tip] |
| 89 | +> Alternatively, you can skip the terminal setup and simply open the "x86 Native Tools Command Prompt for |
| 90 | +> VS 2022" from the Start menu. Once opened, navigate to the project directory in the terminal and proceed |
| 91 | +> to run the commands below. |
| 92 | +<!-- markdownlint-disable-next-line --> |
| 93 | +- #### 1. **Release Build** |
| 94 | + |
| 95 | + - **Choose the build configuration:** |
| 96 | + - `cmake --workflow --preset win32` for Release build. |
| 97 | + |
| 98 | + - **Install the game executable in the game directory (assuming the build was successful):** |
| 99 | + - `cmake --install build/win32 --config Release` |
| 100 | + |
| 101 | +- #### 2. **Development and Debug Builds** |
| 102 | + |
| 103 | + - **Choose the build configuration:** |
| 104 | + - `cmake --workflow --preset win32dgb` for Debug build. |
| 105 | + - `cmake --workflow --preset win32int` for Internal build. |
| 106 | + - `cmake --workflow --preset win32prof` for Profile build. |
| 107 | + |
| 108 | + - **Install the game executable in the game directory (assuming the build was successful):** |
| 109 | + - `cmake --install build/<preset name>` |
| 110 | + |
| 111 | +- **To build a specific target:** |
| 112 | + - Run `cmake --build build/<preset name> --target <target name>` |
| 113 | + - Example: `cmake --build build/win32dgb --target z_generals` |
| 114 | + - Or: `cmake --build build/win32int --target g_generals` |
| 115 | + |
| 116 | +For more CMake options, see the [CMake Guide](cmake_guide). |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## Build with Solutions |
| 121 | + |
| 122 | +- Generate the Visual Studio solution with the appropriate preset (see above): |
| 123 | +- Run `cmake --preset win32 -G "Visual Studio 17 2022" -A Win32` |
| 124 | +- Navigate to the `build/win32` folder and open the generated solution file. |
| 125 | +- Build the project using the Visual Studio interface. |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +## Troubleshooting |
| 130 | + |
| 131 | +- **Missing DLLs?** Ensure that all required dependencies are installed. |
| 132 | +- **Game not launching?** Verify that all necessary `.BIG` files are correctly placed. |
| 133 | +- **Build errors?** Check Visual Studio settings and dependencies for any issues or delete the `build` folder and try |
| 134 | + building again. |
0 commit comments