Using cmake with Visual Studio - pure command line

42 views
Skip to first unread message

Greg Ercolano

unread,
Mar 12, 2022, 3:50:47 AM3/12/22
to fltkc...@googlegroups.com
    This seems to work for building FLTK with VS purely from the command line,
    without the VS IDE GUI ever being involved at all:

mkdir test && pushd test
make -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" ..
nmake all
:
: Colorful percentage output crawl similar to what we see with unix 'make'
:

    This seemed to work for me building FLTK on Windows 10 using the
    "x64 Native Tools Command Line" with VS 2019. Since Win10 DOS windows
    now support colored text (just like the old DOS days with ANSI).

    If this, or something like it, is a valid and supportable way to build FLTK
    going forward, can this recipe be mentioned in the README.CMAKE.txt?

    I've always hated bringing up the IDE in the middle of my otherwise
    automated build pipeline.. this is quite a breath of fresh air..!

melcher....@googlemail.com

unread,
Mar 12, 2022, 6:38:13 AM3/12/22
to fltk.coredev
I use the following command sequence with VisualC 2021. The `CMAKE_BUILD_TYPE` doesn't really do anything according to the CMake documentation for building with IDEs (VC, Xcode). Instead, a Debug and a Release subdirectory are generated, and the `--config Release` option must be used. There is no need to redefine the compiler flags.

Also, explicitly calling NMake is not wrong, but cmake has its ow `--build` option that uses the correct build app for your configuration.

```

cmake -S fltk -B fltk/build -A x64 -D OPTION_USE_SYSTEM_LIBJPEG=Off -D OPTION_USE_SYSTEM_ZLIB=Off -D OPTION_USE_SYSTEM_LIBPNG=Off -D CMAKE_BUILD_TYPE=Release

cmake --build fltk/build --config Release

```

Albrecht Schlosser

unread,
Mar 12, 2022, 10:16:44 AM3/12/22
to fltkc...@googlegroups.com
On 3/12/22 09:50 Greg Ercolano wrote:
    This seems to work for building FLTK with VS purely from the command line,
    without the VS IDE GUI ever being involved at all:

mkdir test && pushd test

cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" ..


nmake all
:
: Colorful percentage output crawl similar to what we see with unix 'make'
:

    This seemed to work for me building FLTK on Windows 10 using the
    "x64 Native Tools Command Line" with VS 2019. Since Win10 DOS windows
    now support colored text (just like the old DOS days with ANSI).

    If this, or something like it, is a valid and supportable way to build FLTK
    going forward, can this recipe be mentioned in the README.CMAKE.txt?

Yes, I think it can be useful to mention this in the README file. There are some details that should be mentioned though, particularly that setting the C and CXX flags is not required but still interesting if you want to set special flags for your build.

I can add a paragraph to README.CMake.txt if you don't mind.


Note that (as Matt mentioned) you could run `cmake --build .` rather than executing `nmake' explicitly. But that's a matter of taste (cmake --build is generic and works "always", no matter what generator you used).

Combining this reply with a reply to Matt's statement:


On 3/12/22 12:38  'melcher....@googlemail.com' wrote:
I use the following command sequence with VisualC 2021. The `CMAKE_BUILD_TYPE` doesn't really do anything according to the CMake documentation for building with IDEs (VC, Xcode).

That's true, but the command Greg used created 'NMake" files (AFAICT) and no IDE, whereas yours creates a full IDE which you can use if you like. The difference is that any kind of Makefile generators are "single config" generators whereas some IDE generators (notably VS) create multiple configs.

Instead, a Debug and a Release subdirectory are generated, and the `--config Release` option must be used. ...

```

cmake -S fltk -B fltk/build -A x64 -D OPTION_USE_SYSTEM_LIBJPEG=Off -D OPTION_USE_SYSTEM_ZLIB=Off -D OPTION_USE_SYSTEM_LIBPNG=Off -D CMAKE_BUILD_TYPE=Release

cmake --build fltk/build --config Release

```


I didn't try/test this yet but it looks plausible as well.

Under "normal" circumstances on Windows using all the "OPTION_USE_SYSTEM_*" flags is redundant unless you installed image libraries on your system and don't want to use those.

Mo_Al_

unread,
Mar 12, 2022, 11:01:02 AM3/12/22
to fltk.coredev
I also prefer Ninja via CMake's Ninja generator, it automatically parallelizes the build and is generally much faster than either nmake or msbuild. It also detects the architecture from the environment (whether it's run from the x64 native tools command prompt or the x86 one).

Albrecht Schlosser

unread,
Mar 12, 2022, 5:07:20 PM3/12/22
to fltkc...@googlegroups.com
On 3/12/22 17:01 Mo_Al_ wrote:
> I also prefer Ninja via CMake's Ninja generator, it automatically
> parallelizes the build and is generally much faster than either nmake
> or msbuild.

So do I but I used Ninja (hint: OS package "ninja-build") only on macOS
and Linux. I didn't bother yet to (try to) install it on Windows.

> It also detects the architecture from the environment (whether it's
> run from the x64 native tools command prompt or the x86 one).

This detection is obviously done by CMake because I noticed this as well
with the "NMake Makefiles" generator: I used both shell environments and
the build created 32-bit or 64-bit executables depending on the environment.


Reply all
Reply to author
Forward
0 new messages