Manually add include path for header files. CMakeLists.txt don't work but cmake works fine.
Hi,
After some fiddling with SDL2 I have finally been able to compile an example using cmake and make under mingw32 with msys.
Unfortunately CLion does not sees sdl2 header files that are being loaded correctly by the cmake itself.
In my github repository there is forked and little tweeked version of FindSDL2.cmake https://github.com/tarach/sdl2-cmake-scripts
It works fine when used with commands:
mkdir build
cd build
cmake .. -G"MSYS Makefiles"
make
For CMakeLists.txt like the fallowing:
project(simple-timeline-recorder)
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_
#include <iostream>
#include <SDL.h>
int main(int, char**)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
} else
{
std::cout << "OMG it finally works..." << std::endl;
}
SDL_Quit();
return 0;
}
But CLion fails to load header files from it.
tarach@tarach-win7-pc-mingw build
cmake .. -G"MSYS Makefiles"
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: D:/apps/MinGW/bin/gcc.exe
-- Check for working C compiler: D:/apps/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/apps/MinGW/bin/g++.exe
-- Check for working CXX compiler: D:/apps/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
<FindSDL2.cmake>
-- Looking for include file pthread.h
-- Looking for include file pthread.h - not found
-- Found Threads: TRUE
</FindSDL2.cmake>
-- Found SDL2: mingw32;D:/apps/SDL2/i686-w64-mingw32/lib/libSDL2main.a;d:/apps/MinGW_dev/bin/SDL2.dll
-- Configuring done
-- Generating done
-- Build files have been written to: D:/projects/simple-timeline-recorder/build
tarach@tarach-win7-pc-mingw build
make
Scanning dependencies of target simple-timeline-recorder
[100%] Building CXX object CMakeFiles/simple-timeline-recorder.dir/src/main.cpp.obj
Linking CXX executable simple-timeline-recorder.exe
[100%] Built target simple-timeline-recorder
tarach@tarach-win7-pc-mingw build
./simple-timeline-recorder.exe
OMG it finally works...
请先登录再写评论。
Hi Sebastian,
Got it running with only one small change:
changed to:
I used the posted files as well as the FindSDL2.cmake from your Github account
To be sure I attached all the files I used, hope this helps!
Kind regards,
Viktor
Attachment(s):
simple-timeline-recorder_allfiles.zip
And by the way: With using your approach (find_package instead of PkgConfig) I also solved my SDL Issues (https://devnet.jetbrains.com/thread/465255) ;-)
Yet there some tweaks to do (copying required dlls, getting rid of console window).