Issue with cmake on msys64 + mingw64

I recently ran into an issue while attempting to build a simple cmake project on Windows 10 via msys64/mingw64. I’m not sure if I’m doing something wrong or if this is an issue with SDL’s sdl2-config.cmake file. So I’m posting here to see if anyone else has ran into the same issue.

FWIW, this builds just fine on Linux. It’s only an issue with mingw64. Below is the error message I receive:

C:/msys64/mingw64/bin/c++.exe   @CMakeFiles/app.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles/app.dir/src/app.cpp.obj -c C:/dev/sdl-test/src/app.cpp
In file included from C:/dev/sdl-test/src/app.cpp:1:0:C:/dev/sdl-test/src/app.h:3:10: fatal error: SDL.h: No such file or directory
#include <SDL.h>
               ^~~~~~~
compilation terminated.

Looking in the CMakeFiles/app.dir/includes_CXX.rsp file I have the following values used for the include directories:

-IC:/dev/sdl-test/vendor/include -I/mingw64/include/SDL2 -isystem C:/msys64/mingw64/include

That second include directory seems suspect to me since that isn’t a valid path. What I think it should be is C:/msys64/mingw64/include/SDL2 – similar to the -isystem value.

I’ve made the following change to the sdl-config.cmake file which fixed my build issue.

#set(prefix "/mingw64")
set(prefix "C:/msys64/mingw64")

Below is my test CMakeLists.txt file.

cmake_minimum_required(VERSION 3.10)
project(sdl-test)
find_package(glm REQUIRED)
find_package(SDL2 REQUIRED)
add_executable(app src/app.cpp src/main.cpp src/glad.c)
target_compile_features(app PRIVATE cxx_std_14)
target_include_directories(app PRIVATE vendor/include)
target_include_directories(app PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(app PRIVATE glm)
target_link_libraries(app PRIVATE ${SDL2_LIBRARIES})

SDL version: 2.0.8
CMake version: 3.10.2
OS: Windows 10 (64-bit)