Day 5 : 12 June 2022 : CMake on Windows
My 100 Daze of Code
https://github.com/davidjwalling/100-days-of-code
Day 5 : 12 June 2022 : CMake on Windows
So far, we've seen using CMake on Linux and MacOS. Also, we've looked at native compilation on Windows using Visual Studio (VS). Today, we'll look at using CMake on Windows. I decided to devote an entire day (hour) to this because there are several ways to invoke CMake on Windows, using different "Generators". A generator will write the inputs to the native build tools.
But Wait, There's More ...
Before heading to CMake, I wanted to first point out that VS' native tools can build just fine without using CMake, of course. To build using "msbuild," open an x64 Native Tools Command Prompt for Visual Studio - this is provided when VS is installed. Invoke msbuild and pass the solution name and the desired platform and configuration.
msbuild ava.sln /p:Platform=x64 /p:Configuration=Debug
Repeat for Debug and Release configurations for Win32 and x64 platforms as desired. To reproduce this output, first clean the solution if you've already built with the IDE.
Updating the CMakeLists.txt
CMake with the Native Tools Generator
Using CMake, we specify the desired generator with the -G option. Here, we ask Visual Studio itself to generate the inputs for the build. This can be done from a standard command prompt as Administrator.
We'll clean and recreate the build folder, run CMake to generate input files, run CMake to build the project output and copy the compiled binaries into installation folders. We'll need to make sure our installation folder is part of our path so we can run ava.exe.
The second invocation of CMake builds and installs.
The "install" step created the "C:/Program Files/ava/bin" folder and stored ava.exe there. It also created a "lib" folder and stored the library there. However, it does not update the environment so that these binaries can be found. We have to make sure the "bin" folder is in our path and that the correct version of the library is loaded.
CMake with the "NMake Makefiles" Generator
We can also have CMake generate input for use by the "NMake" Program Maintenance Utility provided as part of Visual Studio. Here, we inform CMake of the desired platform and configuration first, then in the second step, we run nmake instead of CMake.
Here, open an x64 Native Tools Command Prompt for Visual Studio as Administrator so that it has permission to install the generated binaries.
Next we run CMake specifying the "NMake Makefiles" generator.
Next we run "nmake install". Curiously, NMake install is C:/Program Files (x86) and not C:/Program files.











Comments
Post a Comment