CMake is useful in compiling source code for get binaries. Compiling a library from the source code guarantees that the resulting library is perfectly tailored for your CPU/OS, a luxury pre-compiled binaries don't always provide. It is also important that binaries you get target x64 platform. In this guide you learn how to install CMake, process source code, build a solution, get binaries, and test them. It is assumed your platform is Windows 10 or 11, and IDE Visual Studio 2022. Check the Desktop development with C++ workload box as you download it, also click Language pack" and check "English" box.

Part 1
Part 1 of 6:

Configuring Visual Studio

  1. 1
    Highlight what you expect to do. Highlight step or sub-step you expect to do and then do it. See as example picture above.
  2. 2
  3. Advertisement
Part 2
Part 2 of 6:

Installing CMake

  1. 1
    Compiling a library from the source code guarantees that the resulting library is perfectly tailored for your CPU/OS, a luxury pre-compiled binaries don't always provide. It is also important that binaries you get target x64 platform.
  2. 2
    Create folders GL and GLP. Open Windows's File Explorer > Navigate to disk (directory) C.
    • If folders GL and GLP exist it's okay.
    • If they do not, right click in empty area > select New > Folder > type GL > hit Enter. By same way create folder GLP.
  3. 3
    Download CMake. Right-click on following address and select Open Link in New Window https://cmake.org/download/. Scroll down the page and find "Latest Release (3.25.1)", (or latest). In second "Platform" list, find (see image above) "Windows x64 ZIP" and click the beside entry cmake-3.25.1-windows-x86_64.zip (or latest) > in opening wizard select Save file.
  4. 4
    Copy and unzip the zip folder.
    • If the downloaded folder doesn't contain line with stripes (unzipped folder) click it > right click > Copy.
    • If downloaded folder's icon contains vertical line with stripes (zipped folder), double click it for get unzipped folder, (or alternatively, click folder > right click > in drop-down menu select Extract all).
      • When unzipping (extracting files) is finished, click unzip folder cmake-3.25.1-windows-x86_64.zip (or latest) > right click > Copy.
    • Go to drive (directory) C: > GL > right click > Paste.
    • (Alternatively click folder "cmake-3.25.1-windows-x86_64" and drag into folder "GL").
    • When copying is finished click folder "cmake-3.25.1-windows-x86_64" > right click > select "Rename" > type CMake > hit Enter > double click it > double click folder bin > inside you should see CMake's logo next to file name cmake-gui > double click this file. If wizard "Windows protect your PC" appears, click More information > Run anyway. Now on your screen you have CMake GUI.
    • Each time you need CMake, navigate to C:\ > GL > double click folder CMake > double click "bin" > double click file cmake-gui (the one with CMake's logo).
  5. Advertisement
Part 3
Part 3 of 6:

Processing Source Code

  1. 1
    Download source code. As an example we use GLFW. Right-click on following address and select Open Link in New Window https://www.glfw.org/download.html. Select "Source package". In opened wizard select Save File.
  2. 2
    Unzip and copy folder.
    • In downloading window click zip folder glfw-3.3.8 (or latest) > if you get no stripped (unzipped) icon, it's okay. If not, right click > select Extract all.
    • Copy unzip folder and paste in C:\GL.
    • (Alternatively click downloaded folder and drag into folder C:\GL).
    • Now in directory C:\GL, you have unzip folder glfw-3.3.8 (or latest). Click on its name > delete name > type: GLFWsrc > hit Enter > close downloading window.
  3. 3
    Compile source code. See above image.
    • Where is the source code. Copy (attention: do not copy any space)C:\GL\GLFWsrc and paste in CMake GUI first text field.
    • Where to build the binaries. Copy (attention: do not copy any space)C:\GL\GLFWsrc\build an paste in second text field.
    • Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes. Be sure you have downloaded Visual Studio 2022 > in wizard "Specify the generator for this project" , check whether visual studio version is 17 2022 > click Finish.
    • When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
      • If, instead, wizard "Error" is thrown, click OK > check whether you have downloaded visual studio 2022. If you have, in CMake GUI click "File" > click "Delete Cache" > in thrown wizard "Delete Cache", click Yes > close CMake GUI > open it again > repeat this step.
  4. 4
    Build your solution.
    • Copy C:\GL\GLFWsrc\build and paste in File Explorer Address Bar > hit Enter > Double click "GLFW.sln", or "GLFW", or "ALL_BUILD.vcxproj". An instance of Visual Studio appears. Wait until in main menu Build entry appears. Click it > "Build Solution".
    • Wait till you read the last line in "Output" window: ========== Build: 32 succeeded, 0 failed, 0 up-to-date, 3 skipped" ==========
      • Numbers of "succeeded" and "skipped" change in glfw versions. Today (12-Nov-2022) is 32 and 3 respectively.
    • Copy C:\GL\GLFWsrc\build\src\Debug and paste in File Explorer Address Bar > hit Enter. You should see file glfw3.lib.
    • Close cmake GUI.
  5. Advertisement
Part 4
Part 4 of 6:

Creating Project with compiled Binaries

  1. 1
    Create empty project. See above image. Title "Visual Studio 2019" doesn't matter. .
    • In Visual Studio main menu click File > New > Project… .
    • In Create a new project wizard, select Empty Project> click Next.
    • In Configure your new project wizard,
      • In Project name text box type (or copy and paste): GLFWsrc-0
      • Copy C:\GLP and paste in Location text box .
      • Check box Place solution and project in the same directory.
      • Click Create.
  2. 2
    Add your source file to the Project. See above image. Project's name in it is "SDLproject", but it doesn't matter.
    • In Solution Explorer wizard, right click the Source Files folder (the last one) > click Add > New Item…
    • In the Add New Item - GLFWsrc-0 wizard, click C++ File (.cpp) (the first one) from the middle of the window. In the Name text box, type Main.cpp.
    • The Location should be C:\GLP\GLFWsrc-0. If it's not, copy C:\GLP\GLFWsrc-0 and paste.
    • Click the Add button. The file will open in the text editor but leave it blank for now.
  3. Advertisement
Part 5
Part 5 of 6:

Setting Up GLFWsrc In Project

  1. 1
    Configure project's Properties. See above image. Project's name in it is "SDLproject", but it doesn't matter. In Solution Explorer wizard, right click Project's name that is GLFWsrc-0 > select Properties. In GLFWsrc-0 Property Pages wizard,
Part 6
Part 6 of 6:

Testing project GLFWsrc-0 and Correcting errors

  1. 1
    Test code. Right-click on following address and select Open Link in New Window https://www.glfw.org/docs/3.0/quick.html#quick_example > copy code > go to Visual Studio GUI and paste in Main.cpp code area. Hit Ctrl+F5. If everything gone well two windows appear: one black and other with a rotating colored triangle in black background. Good job.
  2. 2
    Correct errors if any. Files are missing. Copy C:\GLP\GLFWsrc-0 and paste in File Explorer Address Bar. You should see file you added Main.cpp, and 4 other files added by Visual Studio. If they are missing you missed add file Main.cpp. Go to Part 3, step 2, and add it now.
  3. Advertisement

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 13 people, some anonymous, worked to edit and improve it over time. This article has been viewed 12,674 times.
How helpful is this?
Co-authors: 13
Updated: December 9, 2022
Views: 12,674
Advertisement