Skip to content

Conversation

@FtZPetruska
Copy link
Contributor

Description

This PR adds support CMake, based on SDL2_image's CMakeLists.

This is a follow-up to #37 which was lacking many features (incomplete Config file, missing FindSDL2 helpers, etc.).

Additionally, the showinterfaces program is supported.

Existing issues

Addresses #33.

Implementation is based off SDL2_Image.
@slouken slouken requested a review from madebr May 29, 2022 07:34
Copy link
Contributor

@madebr madebr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you intend to add CMake to the GitHub workflows?

FtZPetruska and others added 2 commits May 29, 2022 16:14
Changes link flags to fix mingw builds. `showinterfaces` is disabled on MSVC workflow as the minimum version of SDL is too old for current MSVCRT and gives linker errors even when linking `legacy_stdio_definitions.lib`
@FtZPetruska
Copy link
Contributor Author

Thank you for your review!

Do you intend to add CMake to the GitHub workflows?

I went ahead and added them in 553058d.

@madebr
Copy link
Contributor

madebr commented May 29, 2022

Thank you for adding them!
Weird that legacy_stdio_definitions.libdoes not fix the MSVC link error.
It looks very similar (if not the same) as the one I was seeing.

@FtZPetruska
Copy link
Contributor Author

I was testing with SDL2.0.0 as it is the minimum compatible version. The two errors I was getting were undefined references in SDL2main.lib(SDL_windows_main.obj) within the ShowError function to:

  • __imp_fprintf
  • __imp___iob_func

Linking to legacy_sdtio_definitions.lib would only fixes the fprintf issue.

On the other hand, bumping the version to SDL2.0.4 fixes this issue altogether.

@madebr
Copy link
Contributor

madebr commented May 29, 2022

That sounds credible.
I only had to go back to SDL2.0.9, so you were seeing "bigger" issues.
It looks like we're seeing the same issue as this stackoverflow question.

This is what msdn has to say about this:

If your project links with static libraries that were compiled with a release of Visual Studio earlier than 2015, the linker might report an unresolved external symbol. These errors might reference internal definitions for _iob, _iob_func, or related imports for certain <stdio.h> functions in the form of imp*. Microsoft recommends that you recompile all static libraries with the latest version of the C++ compiler and libraries when you upgrade a project. If the library is a third-party library for which source isn't available, you should either request an updated binary from the third party or encapsulate your usage of that library into a separate DLL that you compile with the older version of the compiler and libraries.

So yeah, good call to just ignore the problem until we update the minimum required SDL version (which is unlikely to happen anytime soon).

@sezero
Copy link
Contributor

sezero commented May 29, 2022

I was testing with SDL2.0.0 as it is the minimum compatible version. The two errors I was getting were undefined references in SDL2main.lib(SDL_windows_main.obj) within the ShowError function to:

* `__imp_fprintf` * `__imp___iob_func` 

Linking to legacy_sdtio_definitions.lib would only fixes the fprintf issue.

On the other hand, bumping the version to SDL2.0.4 fixes this issue altogether.

Is this issue with linkage of showinterfaces test program? AFAIK, it is a console-only
program, so, does defining SDL_MAIN_HANDLED in its CFLAGS fix things?

 Only set `Compatible Interface Properties` for shared libraries. Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
Copy link
Contributor

@madebr madebr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for investing your time into this!

This removes the need for SDL2main as it is a console-only application. MSVC workflow now builds showinterfaces.
@FtZPetruska
Copy link
Contributor Author

I was testing with SDL2.0.0 as it is the minimum compatible version. The two errors I was getting were undefined references in SDL2main.lib(SDL_windows_main.obj) within the ShowError function to:

* `__imp_fprintf` * `__imp___iob_func` 

Linking to legacy_sdtio_definitions.lib would only fixes the fprintf issue.
On the other hand, bumping the version to SDL2.0.4 fixes this issue altogether.

Is this issue with linkage of showinterfaces test program? AFAIK, it is a console-only program, so, does defining SDL_MAIN_HANDLED in its CFLAGS fix things?

Thank you for the suggestion, it worked like a charm!

FtZPetruska and others added 2 commits May 29, 2022 19:34
 The `mingw32` library is no longer needed as `showinterfaces` is a console app. Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
Applied review suggestion to use `target_compile_options`. Replaced `/wd4996` as `_WINSOCK_DEPRECATED_NO_WARNINGS` is enough. Raise the warning level to `/W3` to be consistent with the solution in `VisualC/`.
@slouken
Copy link
Collaborator

slouken commented May 30, 2022

On the other hand, bumping the version to SDL2.0.4 fixes this issue altogether.

This is the right solution here. SDL_net shouldn't be held back to SDL 2.0.0.

FtZPetruska and others added 2 commits May 30, 2022 12:14
 - Set a different output name for static libraries on MSVC and WATCOM (cf. libsdl-org/SDL_image#275 and libsdl-org/SDL#5727) - Fix `PKG_PREFIX` on Windows (cf. libsdl-org/SDL_image#274) Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
@slouken
Copy link
Collaborator

slouken commented May 30, 2022

@madebr, feel free to merge this and/or incorporate the changes into your other SDL library work.

SDL_net does not build any dependency, so we don't need to force position independent code.
@madebr
Copy link
Contributor

madebr commented Jun 11, 2022

Thus far, this PR looks very good!
I'm currently also working on similar changes for SDL_ttf and SDL_mixer (=in progress).

What is missing here is generation of cmake config scripts by the autotools toolchain.
Also addition of cmake scripts that will get bundled into the release for the Xcode framework, the MinGW and VC SDK is missing.
In the PR mentioned above, I also added a mini CMake integration test to the GitHub CI.

The SDL_ttf pr has the missing bits I mentioned above that you would need to adapt to SDL_net.

Are you willing to look into this, or do you prefer to merge and let me finish it?
You doing the port would also mean my SDL_ttf pr getting a review by you.

Thanks!

@FtZPetruska
Copy link
Contributor Author

Thank you for your comment!

I'm going to look into it and I'll let you know how it goes.

I'm away from my main machine currently, so I can only really test autotools and Apple's Framework integration. I'll try to grab mingw binaries when I get the opportunity to test it out.

@FtZPetruska FtZPetruska requested a review from madebr June 11, 2022 21:38
Copy link
Contributor

@madebr madebr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created FtZPetruska#2 with fixes to the build.

FtZPetruska and others added 2 commits June 12, 2022 08:48
 Fix option de-duplication issues when linking with SDL2 framework. Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
This is necessary if the framework has a space in its path.
FtZPetruska added a commit to FtZPetruska/SDL that referenced this pull request Jun 12, 2022
As mentionned in libsdl-org/SDL_net#48 and libsdl-org/SDL_ttf#213: - Options needs to use `SHELL:` to avoid aggressive option de-duplication - Framework path needs to be quoted to support paths with spaces.
madebr pushed a commit to libsdl-org/SDL that referenced this pull request Jun 12, 2022
As mentionned in libsdl-org/SDL_net#48 and libsdl-org/SDL_ttf#213: - Options needs to use `SHELL:` to avoid aggressive option de-duplication - Framework path needs to be quoted to support paths with spaces.
 Fix name mismatch between the bundled CMake config file for mingw and the generated config. Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
 Fix regex match. Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
@slouken
Copy link
Collaborator

slouken commented Jun 13, 2022

@madebr, feel free to merge this when ready.

 No longer set PKG_PREFIX on macOS. Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
@madebr madebr merged commit 20f3329 into libsdl-org:main Jun 14, 2022
@madebr
Copy link
Contributor

madebr commented Jun 14, 2022

Thanks @FtZPetruska !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants