The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
[SDL2, MinGW, CMake] feedback and compile steps
DarioOO


Joined: 27 Dec 2014
Posts: 15
[quote="DarioOO"]Actually I'm pretty satisfied by SDL2 supporting partially CMake, here's my feedback so that users could compile SDL2 in a very easy way and so developers could help. I was able to configure and compile it in 5 minutes (compile time included).

I'm interested in helping there with Cmake (I'm still learning it, but already have my cross platform toolchain setted up) but seems internally SDL is really complicated, so for now I won't touch it Very Happy


1) Download SDL2 source release and unzip somewhere.

2) Use a simple script to call CMake (I know bash and batch are not portable, but the steps are so simple that I guess any shell environment can do that)

In my case I have the whole toolchaing on windows so here's a batch snapshot, but if you need it I can provide bash or sh versions (you can easily do that yourself):

I'm calling the script inside the SDL2 folder (i double click it)

Code:

set PATH=F:/Git/_Toolchains/GCC_492_posix_dwarf2/mingw32/bin;C:/Program Files/CMake/bin/
set CC=F:/Git/_Toolchains/GCC_492_posix_dwarf2/mingw32/bin/gcc
set CXX=F:/Git/_Toolchains/GCC_492_posix_dwarf2/mingw32/bin/g++
set DXSDK_DIR=F:\Git\_Toolchains\GCC_492_posix_dwarf2\mingw32\i686-w64-mingw32\include\ddk

mkdir build
cd build
mkdir GCC_492_posix_dwarf2
cd GCC_492_posix_dwarf2

cmake ../../ -G "CodeBlocks - MinGW Makefiles"
mingw32-make all


3) you have the dll, just link it in your application.

I tried (with success) following compilers:
GCC 4.8.x (sjlj)
GCC 4.9.x (dwarf2)

However, indipendently of wich compiler flags I force from outside (CMAKE_BUILD_TYPE := Release/Debug etc.), SDL will try its own compiler flags wich results in a rather big executable (4 Mb instead of 300kb): there's some room for improvement.

This is not an issue for me, but


Here's what the above script does:

Quote:

set up PATH, we need only 2 folders. the "bin" folder of choosen compiler, and the folder in wich you installed CMAKE.
set up CC, the path to the C compiler
set up CXX, the path to the C++ compiler
set up DXSDK_DIR, the folder in wich we can find DX headers (usually packed with GCC releases)

As you see I keep everything ordered, so I have a folder "/_Toolchains/X" where I unzip the compiler(or cross compiler) and I use a "build/X" folder to create the binary for SDL using the X compiler (so I have N different versions of the SDL.dll).

the PATH variable is more important than it seems because you need it to run your application because (dependeing on the compiler version) you need some of the DLLs that are in there.

Using shell script is also very good, because instead of polluting your global environment permanently you just specify the few variables you need and when the script ends you didn't changed anything globally at system level: you could theorically (and pratically) put your whole tool chain on a USB stick (or submit to subversion server allowing other people with different operative system to compile and run tests you cross-compiled) and compile stuff on friend's computers.



How to build SDL dll directly inside your project (using CMAKE):


Code:

#let users select where SDL is located when calling cmake-gui (I never use cmake-gui by the way)
set(SDL2_DIRECTORY ".." CACHE PATH
    "Directory in wich SDL2/CMakeLists.txt file is found")

#if you build your project in "build" folder, then SDL will be in "build/SDL2" folder
#however note that the DLL needs to be in same executable folder,
#but usually I copy EXEs and DLLS with a Post build command.
add_subdirectory( ${SDL2_DIRECTORY} ${CMAKE_BINARY_DIR}/SDL2)

[/code]