-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[macos] SDL 2.24.2 - SDL.h #includes <SDL2/(various)> but there is no SDL2 subdirectory #6513
Comments
I have seen a similar issue that boiled down to incorrect CMake configuration. When using SDL2 as a framework, clang needs to be passed the |
You should be able to only add the headers by doing: target_include_directories(your_game PRIVATE $<TARGET_PROPERTY:SDL2::SDL2,INCLUDE_DIRECTORIES>) |
Would making available a |
The CMakeLists.txt that I've inherited, in its SDL2 related pieces, does:
where the SDL2_... appear to be provided by the SDL2 package. So that's probably just wrong for the macOS framework case. What's the right way to configure it to cope with both a typical Linux installation of SDL2 and the macOS framework case? |
I was taught the only guaranteed working way to include the SDL headers is by doing the following, without a #include "SDL.h" This is also in line with |
The above CMakeLists.txt fragments result in CMake compiling with:
and linking with:
so it's pointing at the Headers to include, and the framework to link... |
Apple's frameworks are a special case where you need to prefix the includes with If you look at the framework's #include <SDL2/SDL_main.h>
#include <SDL2/SDL_stdinc.h>
.... Whereas on a more typical release, #include "SDL_main.h"
#include "SDL_stdinc.h"
...
Not necessarily, for clang to properly include a framework (even to just get correct includes) it needs to be passed a set_target_properties(SDL2::SDL2
PROPERTIES
INTERFACE_COMPILE_OPTIONS "SHELL:-F \"${SDL2_FRAMEWORK_PARENT_PATH}\""
INTERFACE_INCLUDE_DIRECTORIES "SHELL:-F \"${SDL2_FRAMEWORK_PARENT_PATH}\";SHELL:-framework SDL2"
INTERFACE_LINK_OPTIONS "SHELL:-F \"${SDL2_FRAMEWORK_PARENT_PATH}\";SHELL:-framework SDL2"
COMPATIBLE_INTERFACE_BOOL "SDL2_SHARED"
INTERFACE_SDL2_SHARED "ON"
)
EDIT: Nevermind, that does not work. |
After further investigating, here are the findings:
Moreover, checking the pull request @nbriggs linked above, I wasn't able to reproduce the issue, building and linking just fine with the latest Framework alone. |
Thanks, I was just able to mount the I didn't know the framework's I think the following patch addresses this. Can someone check? --- a/Xcode/SDL/pkg-support/resources/CMake/sdl2-config.cmake
+++ b/Xcode/SDL/pkg-support/resources/CMake/sdl2-config.cmake
@@ -39,7 +39,7 @@ string(REGEX REPLACE "SDL2\\.framework.*" "" SDL2_FRAMEWORK_PARENT_PATH "${CMAKE
set_and_check(SDL2_PREFIX "${SDL2_FRAMEWORK_PATH}")
set_and_check(SDL2_EXEC_PREFIX "${SDL2_FRAMEWORK_PATH}")
set_and_check(SDL2_INCLUDE_DIR "${SDL2_FRAMEWORK_PATH}/Headers")
-set(SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIR}")
+set(SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIR};${SDL2_FRAMEWORK_PATH}")
set_and_check(SDL2_BINDIR "${SDL2_FRAMEWORK_PATH}")
set_and_check(SDL2_LIBDIR "${SDL2_FRAMEWORK_PATH}")
@@ -53,7 +53,7 @@ if(NOT TARGET SDL2::SDL2)
set_target_properties(SDL2::SDL2
PROPERTIES
INTERFACE_COMPILE_OPTIONS "SHELL:-F \"${SDL2_FRAMEWORK_PARENT_PATH}\""
- INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
+ INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
INTERFACE_LINK_OPTIONS "SHELL:-F \"${SDL2_FRAMEWORK_PARENT_PATH}\";SHELL:-framework SDL2"
COMPATIBLE_INTERFACE_BOOL "SDL2_SHARED"
INTERFACE_SDL2_SHARED "ON" |
That seems to do it -- I applied that patch, removed my symlink SDL2 => . from the Headers, reconfigured, and recompiled. Typical compile step now looks like:
So, +1 for that. Thanks! |
Applied in e6c4db8 Can this issue be considered fixed? |
I'm good with that, perhaps @FtZPetruska will also have an opinion. |
Tried the framework with the patch, it compiles my projects with no issues. So I'm good with it too! |
Good to hear! Strange to see the compile command in #6513 (comment) not containing
|
@madebr not so strange, I think -- it has |
But my patch was adding the framework root folder, e.g. |
Without the patch it does:
and what's missing here is the BUT... I'm really confused - I put the sdl2-config.cmake back to the way it was, cleared everything redid the "cmake ..", and I can't reproduce the original problem! |
Closing this issue as the original issue has been resolved. |
For example:
but, all the include files are at the same level in
Headers/
One fix to enable compilation is to symlink
SDL2 -> .
The text was updated successfully, but these errors were encountered: