How to Use CMake to Get Binaries from Source Code

Method 1 of 3:

Installing CMake

  1. How to Use CMake to Get Binaries from Source Code Picture 1
    Highlight what you expect to do. For example see picture above.
  2. How to Use CMake to Get Binaries from Source Code Picture 2
    Download CMake. Right-click on following address and select Open Link in New Window https://cmake.org/download/. Scroll down the page (see image above). Under "Latest Release (today is 3.16.2)" on the second "Platform" list, find "Windows win64-x64.ZIP" and click the beside entry (today is cmake-3.16.2-win64-x64.zip > in opening wizard select Save file.
  3. Copy and unzip the zip folder.
    1. In downloading window, click folder > right click > in drop-down menu select Copy.
    2. Navigate to directory C: > right click > select Paste.
    3. When copying and unzipping (extracting files) is finished, double click unzip folder cmake-3.16.2-win64-x64 (or latest version) > 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.
    4. Each time you need CMake, navigate to C: > cmake-3.16.2-win64-x64 (or latest version) > bin > double click file cmake-gui (the one with CMake's logo).
Method 2 of 3:

Processing Source Code

  1. In directory C, create folder GL. In Windows File Explorer navigate to C: > inside, right click > select New > Folder > type: GL > hit Enter.
  2. Download source code.
    1. 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.
  3. Copy and unzip folder.
    1. In downloading window click zip folder glfw-3.3 (or latest version) > right click > select Copy.
    2. Navigate to C: > GL > right click > select Paste.
    3. Now in directory C:GL, you have unzip folder glfw-3.3. Click twice on its name > delete name > type: glfw > hit Enter.
  4. How to Use CMake to Get Binaries from Source Code Picture 3
    Where is the source code. In CMake GUI first text field. Copy C:/GL/glfw and paste.
  5. Where to build the binaries. In second text field. Copy C:/GL/glfw/build and paste.
  6. Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > select Visual Studio 16 2019 > click Finish.
    1. When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
    2. Close CMake GUI.
  7. Build your solution.
    1. Navigate to C: > GL > glfw > build. 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".
    2. Wait till you read the last line in "Output" window: ========== Build: XX succeeded, 0 failed, 0 up-to-date, 2 skipped" ==========
      1. Number XX of "succeeded" changes in glfw versions. Today (31-12-2019) is 32.
    3. Navigate to C: > GL > glfw > build > src > Debug. Inside you should see file glfw3.lib.
Method 3 of 3:

Testing Binaries

  1. Create empty project. In V.S. main menu click File > New > Project… > Create a new project > Empty project > Next.
    1. In Project name text box type: Project-0.
    2. Next to Location text box, click ....
    3. Navigate to C: > GL > Click Select a folder. The Location is C:GL.
    4. Check box Place solution and project in the same directory.
    5. Click Create.
  2. Add your source file to the Project. In Solution Explorer wizard, right click the Source Files folder (the last one) > click Add > New Item…
    1. In the Add New Item - Project-0 window, click C++ File (.cpp) (the first one) from the middle of the window. In the Name text box, type Main.cpp.
    2. The Location is C:GLProject-0.
    3. Click the Add button. The file will open in the main text editor but leave it blank for now.
  3. Configure project's Properties. In Solution Explorer wizard, right click Project's name that is Project-0 > select Properties.
    1. (1) Project-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
      1. In Active solution platform: select x64.
      2. In Platform entry, x64 is automatically selected.
      3. Click Close.
    2. (2) Additional Include Directories. Click C/C++ > General > In beside menu select the first one, Additional Include Directories > click the down arrow at the end of the field > click Edit... > first icon > three dots ...
      1. Navigate to C: > GL > glfw > include > click include > click Select a folder > click OK.
    3. (3) Additional Library Directories. Double click Linker > click General > Additional Library Directories > click the down arrow at the end of the field > click Edit... > first icon > three dots ....
      1. Navigate to C: > GL > glfw > build > src > Debug > click Select a folder > click OK.
    4. (4) Additional Dependencies. In Linker drop-down menu select Input > in beside menu select the first one, Additional Dependencies > click the down arrow at the end of the field > Edit... > copy opengl32.lib; glfw3.lib and paste in Additional Dependencies wizard's upper-most text box > click OK.
    5. (5) Set System to SubSystem CONSOLE. In Linker drop-down menu select System > in beside menu select the first one, SubSystem > click the down arrow at the end of the field > select Console (/SUBSYSTEM:CONSOLE). Click Apply and OK.
  4. Test code. Right-click on following address and select Open Link in New Window https://www.glfw.org/docs/3.0/quick.html > scroll down the page to last section: Putting it together: A small GLFW application, and copy code > go to Visual studio and paste it 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.
  5. Correct any errors. In "Error List" if you see error about
    1. file with extension .h go to Method 3, step 3, sub-step (2) and follow instructions.
    2. file with extension .lib go Method 3, step 3, sub-step (3), and follow instructions. Also to sub-step (4).
    3. "entry point must be defined" go to Method 3, step 3, sub-step (5), Set "SubSystem" to "CONSOLE", and follow instructions.
    4. For other errors, if you can't correct them, close Visual Studio > delete project folder Project-0 which lives in C:GL > open Visual Studio > repeat set up from part Method 2.
4 ★ | 1 Vote

May be interested

  • How to Quick Sort an Array in C++Photo of How to Quick Sort an Array in C++
    sorting is a very useful tool in programming. it is often necessary to arrange the members of a list in ascending or descending order. a sorted list allows a user to search and find information very quickly. sorting a list requires the...
  • How to Program in C++ and BatchPhoto of How to Program in C++ and Batch
    c++ is a mid-level programming language—it easy to write and it runs very quickly. as a result, it is widely used to develop games, business apps, and software, such as google chrome and microsoft office suite.https://www.youtube.com/wat...
  • How to Create an Alert in CPhoto of How to Create an Alert in C
    sometimes, when writing a program, you need to create a way to get the attention of the user to bring their focus back to the program. alerts are a very useful way to do that. if you want to make alerts in c, read on! if you want your...
  • How to Calculate Your Wage in C++Photo of How to Calculate Your Wage in C++
    you may find it useful or interesting to know how much you will earn in a month or year. while it is possible to do this calculation manually or with a calculator, writing a program is useful to understand what you're doing and to repeat...
  • How to Set Up SFML in a Project on Visual StudioPhoto of How to Set Up SFML in a Project on Visual Studio
    setting up sfml in visual studio 2017 or 2019 is similar to setting up sdl, glfw, freeglut, and glew, with two peculiarities: there are 29 .lib files and 11 .dll files. it is assumed your platform is windows. highlight what you expect to...
  • How to Create Pointers in CPhoto of How to Create Pointers in C
    pointers are the nightmare of every new c programmer. however, they are also the feature that made c the widespread, powerful programming language it is until today. like many other programming features and constructs, there is a...