Using this CMAKE-file in Clion on Windows 10 (using MinGW 5.0):
cmake_minimum_required(VERSION 3.3)
project(ClionProjects)
# configure the SDL (cf. \"SDL2-2
Below is how I work with SDL2, SDL2_ttf, SDL2_mixer, etc. with CLion. This is quite different approache than what you've been doing so far, so please keep that in mind. I'll be using MSYS2 for the POSIX-like environment (instead of MINGW/MSys you are using).
First of, I would start with installing MSYS2. Grab it from http://msys2.github.io/ . Then, depends on the version you have installed, you will get 2 or 3 shortcuts in the start menu.
From now on I'd stick with MINGW-W64-x86_64
version of the toolchain. If you are using the i686
one, replace x86_64
with i686
(and mingw64
with mingw32
).
Open the MinGW-w64 Win64 shell
shortcut from the start menu. You will be welcome with a bash shell. At this point I'd start with installing the toolchain first. At the prompt, input the below command
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-pkg-config mingw-w64-x86_64-make mingw-w64-x86_64-gdb
The package manager will then install gcc, cmake, pkg-config, make and gdb for you. This includes all of the dependencies of these tool, so it would take quite a bit.
Then install the libraries by calling below commands at the prompt.:
pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_ttf mingw-w64-x86_64-SDL2_mixer mingw-w64-x86_64-SDL2_image
pacman (package manager) will download and install these 3 libraries, along with their dependencies.
The steps above is on top of my head. I haven't retested it yet (as I already have working environment). If you run into problems let me know. I might retest it later. Also the step above is applicable for the Arch Linux users too, just replace the package name and you'll be good.
Next up, open the CLion. Go to File->Settings. Choose toolchains under Build, Execution, and Deployment. Then change the MinGW home to the mingw64 under your MSYS2 installation path.
Then everything should be ready.
I will use the FindPkgConfig
module to get the linker flags and include flags of each library I use. This module replies on pkg-config command we've installed earlier. In CMakeList.txt
, add the following line :
INCLUDE(FindPkgConfig)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_IMG REQUIRED SDL2_image)
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
pkg_check_modules(SDL2_MIX REQUIRED SDL2_mixer)
include_directories(${SDL2_INCLUDE_DIRS}
${SDL2_IMG_INCLUDE_DIRS}
${SDL2_TTF_INCLUDE_DIRS}
${SDL2_MIX_INCLUDE_DIRS})
link_directories (${SDL2_LIBRARY_DIRS}
${SDL2_IMG_LIBRARY_DIRS}
${SDL2_TTF_LIBRARY_DIRS}
${SDL2_MIX_LIBRARY_DIRS})
target_link_libraries (TestSDL2
${SDL2_LIBRARIES}
${SDL2_IMG_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${SDL2_MIX_LIBRARIES})
Change the TestSDL2 to your executable. You probably have to remove the existing FindSDL or any commands that looks for SDL libraries.
This approach is much cleaner than the custom module. The downside is it is pretty much tied to the system's libraries file (especially if you are using Linux). Also if you have to package the exe file, you will have to look for the dll files inside the MSYS2/mingw64/bin manually (it's not very difficult by the way).
Another possible approach is to include the SDL as subproject. I haven't done this before so I cannot explain.
I think after you're familliar with how this work, you can applies the same approaches to other libraries as well (box2d, for example). You can see the list of available packages at https://github.com/Alexpux/MINGW-packages , the package names have to be modified a little bit by insterting the arch name just before the library names (eg. mingw-w64-x86_64-box2d
for mingw-w64-box2d
package).