I am currently trying to create a CMake-based build system for my application that uses SDL2 for its graphical output. But when using MSYS to build for Mingw32-w64, I get very strange error messages.
Consider the following example project. It uses findSDL2.cmake found here on github . ( main.cxx is just an empty main function and #include <SDL2.h> )
# Version requirement and project info cmake_minimum_required(VERSION 3.1.3) project(app) # Try to find libsdl2 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) find_package(SDL2 REQUIRED) message(STATUS "Include directory: " ${SDL2_INCLUDE_DIR}) message(STATUS "Libraries: " ${SDL2_LIBRARY}) # Define target as executable add_executable(app main.cxx) # Include own include files target_include_directories(app PUBLIC ${SDL2_INCLUDE_DIR}) # Link to libraries target_link_libraries(app ${SDL2_LIBRARY}) # Require support for at least C++14. set_property(TARGET app PROPERTY CXX_STANDARD 14) set_property(TARGET app PROPERTY CXX_STANDARD_REQUIRED ON)
On my test system, using MSYS to build for Mingw64, SDL2 is installed:
katharina@k-pc MINGW64 /d/app $ pkg-config --cflags sdl2 -Dmain=SDL_main -I/mingw64/include/SDL2
And creating a project manually also works just fine:
Katharina@k-pc MINGW64 /d/app $ clang++ -I/mingw64/include/SDL2 -lmingw32 -lSDL2main -lSDL2 main.cxx Katharina@k-pc MINGW64 /d/app $
But when using the CMake project to create make files, a strange error appears:
Katharina@k-pc MINGW64 /d/app/build $ cmake "MSYS Makefiles" ./.. -- The C compiler identification is Clang 3.8.0 -- The CXX compiler identification is Clang 3.8.0 /* ... */ -- Found SDL2: mingw32;/mingw64/lib/libSDL2main.a;/mingw64/lib/libSDL2.a /* My debug output. Note that all paths are correct! */ -- Include directory: /mingw64/include/SDL2 -- Libraries: mingw32/mingw64/lib/libSDL2main.a/mingw64/lib/libSDL2.a /* */ -- Configuring done -- Generating done -- Build files have been written to: /d/app/build Katharina@k-pc MINGW64 /d/app/build $ make -j Scanning dependencies of target app make[2]: *** No rule to make target '/mingw64/include/SDL2/SDL.h', needed by 'CMakeFiles/app.dir/main.cxx.obj'. Stop. CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/app.dir/all' failed make[1]: *** [CMakeFiles/app.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2 Katharina@k-pc MINGW64 /d/app/build $
CMake can really find the same compiler flags that I use for my manual compilation! So what is wrong here? Do I have an error in the project file? This is just weird!
source share