CMake normal add_library?

Hi all,

experimenting with the CMakeLists approach. It seems that the current CMakeLists.txt is designed to build/package/install SDL. Great, it seems to basically work, but the whole package config thing is a bit annoying on non-linux systems. I’m trying to build my project for Android, iOS, Mac, and Windows via CMake, and most libraries expose a normal library through their CMakeLists.txt, so for example, I can just do

Code:

target_link_libraries(MyAwesomeGame PUBLIC SDL2)

and that takes care of linking and headers, etc… However when I do this for SDL2, it tells me it can’t find the include path, since its trying to reference the installed location rather than the build location, or maybe its not doing anything, hard to tell.

My question is, am I missing something? Or should I work on this functionality for a pull request?

Since we’re on the topic, how do you do a pull request in mercurial? TIA

[/code]

However when I do this for SDL2, it tells me it can’t find the include
path, since its trying to reference
the installed location rather than the build location, or maybe its not
doing anything, hard to tell.

It seems SDL’s CMakeLists.txt is not written for add_subdirectory(). So,
there is no difference with other non-cmake libraries; Build/Install SDL2
separately somewhere you want, set CMAKE_PREFIX_PATH in your CMakeLists.txt
or cmake cache, then pick up some find_package module for SDL2 such as

Alternatively, there are countless “CMake-based” package managers available
e.g.) https://github.com/ruslo/hunter , https://github.com/iauns/cpm
but I’ve never tried them.

Personally, I gave up using SDL’s own CMakeLists.txt and wrote my own one
to integrate/embed SDL2 into my own game executable…
List SDL source codes as:

Copy/Paste SDL_config.h from existing install:

Add include path:

then add_executable(my_game ${my_srcs} ${sdl2_srcs}). It works well for
Win32, UWP(Xbox), Android and Emscripten which i target.

In-short: just add the sources then it should work – except on emscripten
– because SDL_config.h already includes fairly good guesstimation about
the platform so you don’t have to “configure” it. Cool.

I don’t recommend doing this though. Unfortunately, I have plenty private
patches against SDL2 to integrate several proprietary tools from GPU/OS
vendors so I have to debug my own bugs introduced into SDL…
SDL2’s own CMakeLists.txt has some pitfalls (e.g. use of GLOB which is just
plain wrong for add_library) when hacking against SDL2 itself… I guess
the CMakeLists.txt was written for one-off build/install of the library.

2016-11-15 14:01 GMT+09:00 yano <kevin.c.dixon at gmail.com>:> Hi all,

experimenting with the CMakeLists approach. It seems that the current
CMakeLists.txt is designed to build/package/install SDL. Great, it seems to
basically work, but the whole package config thing is a bit annoying on
non-linux systems. I’m trying to build my project for Android, iOS, Mac,
and Windows via CMake, and most libraries expose a normal library through
their CMakeLists.txt, so for example, I can just do

Code:

target_link_libraries(MyAwesomeGame PUBLIC SDL2)

and that takes care of linking and headers, etc… However when I do this
for SDL2, it tells me it can’t find the include path, since its trying to
reference the installed location rather than the build location, or maybe
its not doing anything, hard to tell.

My question is, am I missing something? Or should I work on this
functionality for a pull request?

Since we’re on the topic, how do you do a pull request in mercurial? TIA

[/code]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org