|
2 | 2 |
|
3 | 3 | > **Ensure you are on a Windows machine before attempting to compile!** |
4 | 4 |
|
5 | | -## 1) Installing gcc |
| 5 | +## 1) Installing CMake |
6 | 6 |
|
7 | | -You'll need a C++ compiler that supports C++20 in order to compile DieKnow's C++ functions. DieKnow has been developed on Microsoft Visual Studio using the `gcc` compiler, but it can be developed on Visual Studio Code or any text editor with the following compilers: |
| 7 | +### CMake |
8 | 8 |
|
9 | | -* Microsoft Visual Studio C++ (MSVC) |
10 | | -* GNU Compiler Collection (gcc) |
11 | | -* Clang |
| 9 | +1. Navigate to the [CMake downloads page](https://cmake.org/download/) and download the latest **Windows x64 Installer**. |
| 10 | +2. Run the installer according to the instructions on-screen. Make sure you click the checkbox "Add CMake to the PATH environment variable". |
12 | 11 |
|
13 | | -1. Download the [MSYS2 installer](https://github.com/msys2/msys2-installer/releases/download/2024-07-27/msys2-x86_64-20240727.exe) |
| 12 | +## 2) Installing a Compiler |
| 13 | + |
| 14 | +The compilers MSVC, Clang, and GCC are all supported. |
| 15 | + |
| 16 | +### MSVC |
| 17 | + |
| 18 | +> [!NOTE] |
| 19 | +> Although it is the recommended and best-supported way to build DieKnow, installing MSVC requires administrator privileges. Choose GCC or Clang instead if you do not have them. |
| 20 | +
|
| 21 | +1. Download the [Visual Studio Build Tools](https://aka.ms/vs/stable/vs_BuildTools.exe). |
| 22 | +2. Ensure that "Desktop development with C++" is checked and press "Install" |
| 23 | +  |
| 24 | + |
| 25 | +### GCC/Clang |
| 26 | + |
| 27 | +GCC and Clang can be used on Windows with MSYS2 |
| 28 | + |
| 29 | +1. Download the [MSYS2 installer](https://github.com/msys2/msys2-installer/releases/download/2024-07-27/msys2-x86_64-20240727.exe). |
14 | 30 | 2. Open the MSYS2 installer and follow the instructions to install MSYS2. Copy the path that you inputted when asked. You'll need it later. |
15 | 31 | 3. Once it has finished installing, open up the newly installed app "MSYS2 UCRT64", found by typing the name after pressing the Windows key. |
16 | 32 | 4. Type the following command to synchronize the MSYS2 package database. The terminal will close, and you'll have to reopen it again. |
17 | 33 |
|
18 | 34 | ```bash |
19 | 35 | pacman -Syu |
20 | 36 | ``` |
21 | | -5. Once the terminal reopens, type the following command to install `g++` |
| 37 | +5. Once the terminal reopens, type the following command to install Clang or GCC, depending on your choice. |
22 | 38 |
|
23 | 39 | ```bash |
24 | | - pacman -S mingw-w64-x86_64-gcc |
| 40 | + pacman -S mingw-w64-x86_64-clang |
25 | 41 | ``` |
26 | | -6. Congratulations! You should have gcc installed on your machine. However, you'll need to add it to your system's PATH environment variable for it to be accessible. |
27 | 42 |
|
28 | | -### Adding to PATH |
| 43 | + OR |
29 | 44 |
|
30 | | -1. Press the Windows key and type "Edit environment variables for your account". |
31 | | -2. On the top half of the screen, go to "Path". |
32 | | -3. Press Alt-E and then Alt-N |
33 | | -4. Paste the installation directory of MSYS2 you copied when installing MSYS2 and then type `mingw64\bin` to complete the path. |
34 | | -5. To check if it works, open up a Command Prompt window and type `g++`. If it says "no input files", you have successfully added g++ to your path. |
| 45 | + ```bash |
| 46 | + pacman -S mingw-w64-x86_64-gcc |
| 47 | + ``` |
35 | 48 |
|
36 | | -## 2) Using the compilation command |
| 49 | +6. Press the Windows key and type "Edit environment variables for your account". |
| 50 | +7. On the top half of the screen, go to "Path". |
| 51 | +8. Press Alt-E and then Alt-N |
| 52 | +9. Paste the installation directory of MSYS2 you copied when installing MSYS2 and then type `mingw64\bin` to complete the path. |
| 53 | +10. To check if it works, open up a Command Prompt window and type `g++` or `clang++`, depending on what compiler you chose. If it says something like "No input files" they have been added to PATH. |
37 | 54 |
|
38 | | -1. Use `cd` to cd to the directory where you downloaded DieKnow. |
39 | | -2. Open up a Command Prompt or Powershell window and type the following command to compile `api.cpp` into a DLL. |
| 55 | +## 3) Compiling |
40 | 56 |
|
| 57 | +1. Open up a terminal in Command Prompt or PowerShell. |
| 58 | +2. Type the following command to configure CMake: |
41 | 59 | ```bash |
42 | | - g++ -Ofast -Wall -shared -std=c++20 -static -o src/dlls/api.dll src/api.cpp -lgdi32 |
| 60 | + cmake -S . -B build |
43 | 61 | ``` |
44 | | - |
45 | | -3. If it works, type the following command to compile the GUI: |
46 | | - |
| 62 | +3. You can build the configured CMake files with the following command: |
47 | 63 | ```bash |
48 | | - g++ -Ofast -Wall -shared -std=c++20 -static -o src/dlls/gui.dll src/gui.cpp -lgdi32 -lcomctl32 |
| 64 | + cmake --build build --config <Config> |
49 | 65 | ``` |
50 | | - |
51 | | -Note that if you use another compiler such as MSVC or CL, you will need to link additional libraries such as `user32` or `shell32` or even `advapi32`. |
52 | | - |
53 | | -Several options are used: |
54 | | - |
55 | | -* `-Ofast` compiles into the FASTEST DLL as it possibly can. |
56 | | -* `-Wall` enables all compile warnings. |
57 | | -* `-std=c++20` sets the C++ standard to C++20. |
58 | | -* `-static` links the DLL dependencies statically. |
59 | | -* `-lgdi32`, `-lcomctl32` link the needed libraries for Graphics Driver Interface and Windows Common Controls, respectively. |
| 66 | + Where `<Config>` is the preset; one of either `Debug` or `Release`. `Release` enables optimizations but removes binary information useful for debugging and takes longer to compile. Make sure to remove the brackets ()`<>`). |
| 67 | +4. If the command succeeds a `dieknow.dll` should be placed in the `src/dlls` directory. |
0 commit comments