I know this has been asked before, but I'm not satisfied with the answers I'm finding online, so hopefully someone can provide me with the right insights.
I'm trying to configure SDL2 with CLion on Windows and I'm having some problems. I downloaded the SDL2 sources on linux before, built them succesfully and installed them, so I know it works. However, I don't have access to that computer now and I'm trying to set things up on Windows.
I downloaded http://libsdl.org/release/SDL2-devel-2.0.7-mingw.tar.gz and extracted its contents to E:\SDL2\SDL2-2.0.7
(with E:\SDL2\SDL2-2.0.7\x86_64-w64-mingw32\bin
containing SDL2.dll
). None of the guides I've found say anything about running configure, cmake, make or whatever and since it contains a DLL, I assume everything is pre-built (?)
This is my CMakeList.txt
in my CLion project (named SDL_Project
) in E:\repository\SDL_Project
:
cmake_minimum_required(VERSION 3.6)
project(SDL_Project)
set(CMAKE_CXX_STANDARD 14)
add_executable(SDL_Project src/main.cpp)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
include_directories(${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIR})
target_link_libraries(SDL_Project ${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARIES}
${SDL2_TTF_LIBRARIES})
This alone does not work since CMake does not know where to look for SDL2 (which differs from my Linux experience.)
I've found several versions of FindSDL2.cmake
online, which are enormous scripts that search for SDL2 in various locations, apparently.
Adding this script next to CMakeList.txt
does not work for me:
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "FindSDL2.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SDL2", but
CMake did not find one.
[...]
I have also added the SDL2 directory to PATH
in Windows system environment variables through the control panel.
Here is my compiler message (when I comment out the SDL2 lines in CMakeList.txt
which cause errors):
E:\repository\SDL_Project\src\main.cpp:1:17: fatal error: SDL.h: No such file or directory
#include <SDL.h>
^
compilation terminated.
I know this error is obvious, but I'm including it here anyway for completeness.
I have the following questions:
- How do I properly set this up for Windows in a clean way (adding SDL2 to System32 doesn't seem nice to me..)
- I would like to use the exact same CMakeList.txt file for building from multiple machines (linux, Windows..), so ideally this does not contain hardcoded paths or OS-specific code or configuration.
- Using a massive
FindSDL2.cmake
file with a large list of hardcoded locations to search, doesn't seem nice to me either.. - Ideally there's minimal configuration required to set up the build environment; a) clone repository, b) download/unzip SDL2, c) somehow tell the compiler where SDL2 is located.
So in other words; what is a nice, portable, minimal solution to this problem? Please motivate the answer where possible, I like to learn why this is a good solution as well as how to do it. Thanks!!