Re: CMake normal add_library?

OKUMURA Yuki <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <CAG1-Us0iohwpDmdix7BjP2ery5AkAB+iRGRU1vMsFqxOY=UECQ@mail.gmail.com>
> 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
https://github.com/tcbrindle/sdl2-cmake-scripts

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:
https://github.com/okuoku/grpcore0/blob/9ed5eb89fc62f3d9271d5ac88b2592195888cc28/sdl2-srcs.cmake

Copy/Paste SDL_config.h from existing install:
https://github.com/okuoku/grpcore0/blob/9ed5eb89fc62f3d9271d5ac88b2592195888cc28/include_sdl/emscripten/SDL_config.h

Add include path:
https://github.com/okuoku/grpcore0/blob/9ed5eb89fc62f3d9271d5ac88b2592195888cc28/CMakeLists.txt#L47

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 <[email protected]>:

> 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
> [email protected]
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.