Search code examples
cmakemingw-w64

CMAKE build gui application with MinGW


I want to build gui application with SDL2. I link SDL2 libraries(libSDL2.dll.a and libSDL2main.a) but I don't know how a can apply -mwindows flag to my application. Without him .exe file of my application doesn't show window (executing have not any effect). I use MinGW-w64 my OS is Windows 10. In command line I can do this like here (see section B). How I can apply this flag with usage cmake? Console application works fine.

I try next variant but it doesn't work.

cmake -G "MinGW Makefiles" -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ -D CMAKE_EXE_LINKER_FLAGS="-mwindows"
cmake -G "MinGW Makefiles" -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ -D CMAKE_CXX_FLAGS="-mwindows"

Also in CMakeLists.txt I try do like this

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows")

Solution

  • You can pass WIN32 argument to add_executable and CMake will do this for you:

    add_executable(target_name WIN32 ${sources})