SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Add examples to `SDL.sln`

Open Susko3 opened this issue 1 year ago • 8 comments

Description

Each C example from the examples/ directory is added as a Visual C++ project to SDL.sln, making it easy to test and see the examples on Windows. The projects include the .c file and README.txt. To avoid code duplication in .vcxproj files, common code is moved to Directory.Build.props.

The project files can be automatically generated with the provided generate.py python file, but they still need to be manually added to the appropriate place in the VS solution (using Add existing project).

The initial project files were made with JetBrains Rider and not Visual Studio, but they do work in VS. There might be slight differences if you compare with the test projects.

image

Existing Issue(s)

  • Resolves #11207

Susko3 avatar Oct 18 '24 00:10 Susko3

This seems reasonable to me, @icculus?

slouken avatar Oct 18 '24 00:10 slouken

I'm curious whether the examples rebuild when switching between Configuration (Release|Debug)and Platform (Win32|x64).

madebr avatar Oct 18 '24 00:10 madebr

It does rebuild, both the example and the main SDL project.

For some reason, the examples don't work when I build Win32. Runtime error about SDL3.dll missing. The tests work fine /shrug.

Susko3 avatar Oct 18 '24 00:10 Susko3

This looks fine to me as a first version.

Directory.Build.props is a user-defined file that provides customizations to projects under a directory

Our vcxproj projects contain a lot of repeated code. Perhaps we should add all common code in a shared .props. I did such a thing in https://github.com/libsdl-org/SDL/pull/7257 (for the wrong reason). The only thing we lose with such change is easy modification of target options in the Visual Studio IDE.

madebr avatar Oct 18 '24 00:10 madebr

I'm not against this, but we're absolutely going to forget to add new programs over time.

icculus avatar Oct 18 '24 00:10 icculus

I'm not against this, but we're absolutely going to forget to add new programs over time.

Probably best to add a comment to CMakeLists.txt, since new additions are likely to modify that file. (Could you please add it if you wish, I'm not familiar with the comment syntax there.)

Susko3 avatar Oct 19 '24 16:10 Susko3

Can you add text here to describe the process of adding a new examples project? We can add it to CMakeLists.txt after this is merged.

slouken avatar Oct 19 '24 17:10 slouken

Sure, here it is:

  1. Add a new example in examples/
  2. Run python VisualC/examples/generate.py
    • Take note of the newly generated .vcxproj files
  3. Modify the .vcxproj files if necessary (adding content such as BMP or WAV files)
  4. Open VisualC/SDL.sln in Visual Studio or JetBrains Rider
  5. Locate the appropriate folder in the Solution Explorer
  6. Add the newly generated projects: Right click → Add → Existing project...
  7. Test if they work
  8. Save the SDL.sln solution

Susko3 avatar Oct 19 '24 17:10 Susko3

Merged, thanks!

slouken avatar Oct 29 '24 14:10 slouken

This is causing Visual Studio warnings:

C:\projects\SDL-experimental\VisualC\examples\audio\03-load-wav\03-load-wav.vcxproj : warning  : Wildcards and/or some other MSBuild constructs used in project item definitions are not supported in VC projects. They can lead to unexpected behavior, instability or performance degradation in the Visual Studio IDE. Please refer to https://aka.ms/cpp/projectwildcards for supported options.

slouken avatar Oct 29 '24 19:10 slouken

Can you have generate.py expand the wildcards?

slouken avatar Oct 29 '24 19:10 slouken

If you mean glob-like expansion: glob.glob

madebr avatar Oct 29 '24 19:10 madebr