CMake normal add_library?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

CMake normal add_library?

yano
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
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: CMake normal add_library?

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



_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org