Questions/comments about CMake on Windows

57 views
Skip to first unread message

Daniel Harding

unread,
Feb 18, 2024, 10:27:53 PM2/18/24
to fltk.general
I didn't want to clutter any existing CMake threads with my questions, so making this short thread.

I tried out CMake with Visual Studio to build and test my app with FLTK 1.4 and I have 2 observations/questions.

1. Visual Studio only generated the "x64-Debug" configuration by default, and I had to create x64-Release, x86-Debug, and x86-Release myself.
Can all 4 of these configurations come preconfigured by default?

2. I had to add a new Windows dependency in order to get my application to link: Ws2_32.lib
Is this expected?

Thanks

pvr...@btinternet.com

unread,
Feb 19, 2024, 3:50:20 AM2/19/24
to fltkg...@googlegroups.com

My comments +

From: fltkg...@googlegroups.com <fltkg...@googlegroups.com> on behalf of Daniel Harding <33da...@gmail.com>
Sent: Sunday, February 18, 2024 7:27 PM
To: fltk.general <fltkg...@googlegroups.com>
Subject: [fltk.general] Questions/comments about CMake on Windows
 
I didn't want to clutter any existing CMake threads with my questions, so making this short thread.

I tried out CMake with Visual Studio to build and test my app with FLTK 1.4 and I have 2 observations/questions.

1. Visual Studio only generated the "x64-Debug" configuration by default, and I had to create x64-Release, x86-Debug, and x86-Release myself.
Can all 4 of these configurations come preconfigured by default?

+  I've only got x64 options available on my machine anyway. Or maybe that's all I wanted. I've got Debug, MinSizeRel, Release and RelWithDebInfo available and I am sure these weren't there before the latest update I took. I only generated the Release one. VS can only generate one version at a time, I thought. 

2. I had to add a new Windows dependency in order to get my application to link: Ws2_32.lib
Is this expected?

+  The dependencies in my W11 VS  demo build are:
..\lib\Release\fltk.lib
comctl32.lib
ws2_32.lib
gdiplus.lib
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib

I don't know if this is what the CMake generated or has accumulated over the years from a previous .sln based version.

Phil

Thanks
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/66d1331c-f652-4476-bf14-4e1ff76c8f36n%40googlegroups.com.

Daniel Harding

unread,
Feb 19, 2024, 8:18:28 AM2/19/24
to fltk.general
On Monday, February 19, 2024 at 2:50:20 AM UTC-6 pvr...@btinternet.com wrote:
+  I've only got x64 options available on my machine anyway. Or maybe that's all I wanted. I've got Debug, MinSizeRel, Release and RelWithDebInfo available

A 64-bit Windows machine can build an x86 CMake target by setting the "Toolset" to msvc_x86_x64. I believe this option would be available on all 64-bit Windows machines. 

VS can only generate one version at a time, I thought.

I would be shocked if that were the case. I'm referring to when the CMake project is first opened by Visual Studio.

Albrecht Schlosser

unread,
Feb 19, 2024, 11:32:31 AM2/19/24
to fltkg...@googlegroups.com
On 2/19/24 14:18 Daniel Harding wrote:
On Monday, February 19, 2024 at 2:50:20 AM UTC-6 pvr...@btinternet.com wrote:
+  I've only got x64 options available on my machine anyway. Or maybe that's all I wanted. I've got Debug, MinSizeRel, Release and RelWithDebInfo available

- It depends AFAICT on the CMake generator you choose when you initialize the IDE project. If you run the CMake GUI you can check and see what CMake offers.

- I assume that you can use CMake to generate an IDE project only for one target type, either x86_64 (64-bit) or I686-something (32-bit) at a time, no matter what Visual Studio *can* do. If you want both in one IDE project, then you can supposedly use the built-in configuration editor to generate other build options (but you know that). This may not be accurate because I'm not a Windows/VS user, I'm only using it for testing FLTK. If there are other options then I would like to hear of them and I'd be happy to add them to the docs. That said, this is more a CMake than a FLTK question, you should better ask there.

- As Phil wrote, you should get all four build options (Debug, MinSizeRel, Release and RelWithDebInfo) by default unless you set a CMake variable to prohibit this. In FLTK we're using the default that CMake offers. Again, if this is not what you want, or you don't get this in your environment, this may be a question to ask in the CMake forums (CMake discourse IIRC), or RTFM.


A 64-bit Windows machine can build an x86 CMake target by setting the "Toolset" to msvc_x86_x64. I believe this option would be available on all 64-bit Windows machines.

There are, AFAICT, CMake variables you can set when generating the IDE project, either by the commandline or in the CMake GUI. Whatever you get w/o extra options is what CMake + Visual Studio "think" you want to get. There's one variable CMAKE_BUILD_TYPE for the current build configuration but this one is ignored by CMake's VS generator (a "multi configuration generator"). There are other CMake variables you can use to select the generated build configurations, the toolset, and more. Again, RTFM.


VS can only generate one version at a time, I thought.

I would be shocked if that were the case. I'm referring to when the CMake project is first opened by Visual Studio.

The drop-down menu of the four build configurations should be populated but there's only one choice for 32-bit or 64-bit preset. But what Phil likely meant was that you can only *build* one version at a time. Then you can switch to another configuration and build that one. All - up to four, or even more - versions would be generated in distinct subfolders as is usual (default) for VS builds. There's nothing we do to change that.

That all said, disclaimer: this is all off the top of my head to avoid starting my Windows VM. Sorry if anything is not correct.

Daniel Harding

unread,
Feb 19, 2024, 12:14:36 PM2/19/24
to fltk.general
On Monday, February 19, 2024 at 10:32:31 AM UTC-6 Albrecht Schlosser wrote:
- As Phil wrote, you should get all four build options (Debug, MinSizeRel, Release and RelWithDebInfo) by default unless you set a CMake variable to prohibit this.

Hm, I have a feeling we're not really talking about the same thing. There was no CMake generator GUI. I did exactly what Matthias suggested here: https://groups.google.com/g/fltkgeneral/c/fR5sOPaP8VE/m/s9DySw_CAgAJ

Opening the CMake project in Visual Studio does not present any opportunity to change configuration options beforehand; it immediately generates the CMake project. It does not create 4 build options called Debug, MinSizeRel, Release and RelWithDebInfo; it creates exactly 1 build option named specifically "x64-Debug".

This isn't a huge deal. It's okay if I have to create x64-Release, x86-Debug, and x86-Release manually after-the-fact. I was simply asking if it's possible for these to be created by default. If it isn't that simple and it isn't possible, that's okay. It's only a minor inconvenience.

I'm still curious about the necessity of the new Windows dependency: Ws2_32.lib
This lib was not required with FLTK 1.3 + the old .sln file.

Thanks.

Albrecht Schlosser

unread,
Feb 19, 2024, 12:26:35 PM2/19/24
to fltkg...@googlegroups.com
On 2/19/24 18:14 Daniel Harding wrote:
On Monday, February 19, 2024 at 10:32:31 AM UTC-6 Albrecht Schlosser wrote:
- As Phil wrote, you should get all four build options (Debug, MinSizeRel, Release and RelWithDebInfo) by default unless you set a CMake variable to prohibit this.

Hm, I have a feeling we're not really talking about the same thing. There was no CMake generator GUI. I did exactly what Matthias suggested here: https://groups.google.com/g/fltkgeneral/c/fR5sOPaP8VE/m/s9DySw_CAgAJ

Ah, OK, I see. Matthias mentioned this as "very easy" or whatever. Fact is, there are tons of ways to create the CMake project with CMake, either by using the 'cmake' commandline or by using 'cmake-gui' which would be the "natural" way to use it. This is - more or less - what is described in our README.CMake.txt docs (or maybe not that easy?).

Hint: install CMake from and use their GUI, select the source and build folders, then hit Configure, Generate, and Open Project - in that order - and you should see what we're talking about. Sorry for the confusion.

It's obvious that Microsoft thought (once again) that they can do better. They offer this "Open File/Directory" menu (or whatever it's called) to generate their own IDE from "our" CMakeLists.txt file. However, as you reported, they do it *worse* than it would be done using CMake directly.

I'll answer your other questions later if nobody beats me to it. I ran out of time, sorry.

Albrecht Schlosser

unread,
Feb 19, 2024, 7:37:10 PM2/19/24
to fltkg...@googlegroups.com
On 2/19/24 18:14 Daniel Harding wrote:
> I'm still curious about the necessity of the new Windows dependency:
> Ws2_32.lib

FLTK always depended on the winsock library, in the past on winsock.lib
(or maybe another name, I can't remember), but since FLTK 1.3.x we were
using winsock2, i.e. ws2_32.lib. It's possible that this library was
loaded dynamically though only on demand so you didn't have to link to
it explicitly. I can't tell exactly when or if this was changed w/o
longer investigation.

The libraries you need to link to with FLTK 1.4 and VS are documented here:
https://www.fltk.org/doc-1.4/basics.html#basics_visual_cpp

> This lib was not required with FLTK 1.3 + the old .sln file.

Comparing the 1.4 docs with the 1.3 docs shows indeed that ws2_32.lib
was not explicitly mentioned in 1.3. As I wrote above, it's possible
that it was linked (loaded) dynamically. But now it's obviously required.

How do you build your project? Do you have your own "hand-made" Visual
Studio project and link to the FLTK libs built by the Visual Studio
project created using CMake? If this is true, then you will very likely
have to add ws2_32.lib (and comctl32.lib) to your linker setup (see the
docs mentioned above).

The other way would be to create your own project with CMake as well. I
know, you're not familiar with CMake, but let's think about it anyway.
If you build your own project with CMake then CMake gets all necessary
informations from the FLTK build by its FLTKConfig.cmake file. This
includes all required libraries and link directories. I can really
recommend this if you are not bound by an existing build system. If you
are interested, I recommend to read our README.CMake.txt file which is
still work in progress.

Matthias Melcher

unread,
Feb 20, 2024, 6:23:05 AM2/20/24
to fltk.general
Albrecht Schlosser schrieb am Montag, 19. Februar 2024 um 18:26:35 UTC+1:
On 2/19/24 18:14 Daniel Harding wrote:
On Monday, February 19, 2024 at 10:32:31 AM UTC-6 Albrecht Schlosser wrote:
- As Phil wrote, you should get all four build options (Debug, MinSizeRel, Release and RelWithDebInfo) by default unless you set a CMake variable to prohibit this.

Hm, I have a feeling we're not really talking about the same thing. There was no CMake generator GUI. I did exactly what Matthias suggested here: https://groups.google.com/g/fltkgeneral/c/fR5sOPaP8VE/m/s9DySw_CAgAJ

Ah, OK, I see. Matthias mentioned this as "very easy" or whatever. Fact is, there are tons of ways to create the CMake project with CMake, either by using the 'cmake' commandline or by using 'cmake-gui' which would be the "natural" way to use it. This is - more or less - what is described in our README.CMake.txt docs (or maybe not that easy?).

As I mentioned, VisualStudio (I use 17.9.0) can open CMake based projects including FLTK by choosing the menu [ File > Open > CMake... ]. This creates a Debug project for whatever CPU you have. 
If you want to generate Release build or build for other CPUs, you go to the menu [ Project > CMake Settings for FLTK ] which opens the file "CMakeSettings.json". Here you can simply duplicate existing configurations and change the "Configuration Type" to "Release" or choose a different compiler to generate 32 bit, 64 bit, Intel, or ARM code.

We could publish a "CMakeSettings.json" file with FLTK, but the whole idea of CMake is, to not publish IDE specific files. We used to have Visual Studio .sln ("Solution") files as part of the archive, but it was sometimes more work to maintain those, than to maintain FLTK itself.

Hope that helps.

 Matthias
 

Daniel Harding

unread,
Feb 20, 2024, 3:01:14 PM2/20/24
to fltk.general
On Monday, February 19, 2024 at 6:37:10 PM UTC-6 Albrecht Schlosser wrote:
How do you build your project? Do you have your own "hand-made" Visual
Studio project and link to the FLTK libs built by the Visual Studio
project created using CMake? If this is true, then you will very likely
have to add ws2_32.lib (and comctl32.lib) to your linker setup (see the
docs mentioned above). 

Yes exactly, I have a hand-made .vcxproj file with explicit linker options. Until now, the only system libs that I needed to link to have been: opengl32.lib, glu32.lib, and comctl32.lib
So I was just curious about Ws2_32.lib. (I rather not blindly add new dependencies without understanding why.) Obviously not a big deal. Thanks for the details and the background.

On Tuesday, February 20, 2024 at 5:23:05 AM UTC-6 Matthias Melcher wrote:
As I mentioned, VisualStudio (I use 17.9.0) can open CMake based projects including FLTK by choosing the menu [ File > Open > CMake... ]. This creates a Debug project for whatever CPU you have. 
If you want to generate Release build or build for other CPUs, you go to the menu [ Project > CMake Settings for FLTK ] which opens the file "CMakeSettings.json". Here you can simply duplicate existing configurations and change the "Configuration Type" to "Release" or choose a different compiler to generate 32 bit, 64 bit, Intel, or ARM code.

It wasn't too much of a hassle to duplicate the debug config 3 times and set the right name/Configuration Type/Toolset. I was simply asking out of curiosity if that could be done automatically by default, but it's not a problem. I may try the CMake GUI approach as well, to compare. But the VS approach is also straightforward and sufficient.

Thanks
Reply all
Reply to author
Forward
0 new messages