How to change CMake version and Include SDL2?
-
wrote on 18 Apr 2021, 11:28 last edited by
Hi there.. again..
I´ve some Problems with the QT Creator and how to change cmake Version.I´ve installed a newer version of cmake 3.20.1 on my Windows PC and want my QT cmake Project to use that version, instead of the QT internal cmake.
But in the Build&Run Option of Cmake is no add Button, as shown in the Doc .. instead, there is only a Radio Option
How can i change the cmake Version?
As second.. I created a cmake Project, not QMake.. So i´ve no *.pro File here.. just the CMakeList.txt.
I´ve downloaded the Dev Libs of SDL2 and put the needed Files into the QT Mingw 64Bit Version Subfolders (as stated in the SDL2 install Guide).
Now the compiler throws out an Error, that he can´t find SDL2..
So..
find_package(SDL2 REQUIRED)
Is not working in the CmakeList...
This is my current CMakeList.txtcmake_minimum_required(VERSION 3.5) project(TGS_Editor LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) # QtCreator supports the following variables for Android, which are identical to qmake Android variables. # Check https://doc.qt.io/qt/deployment-android.html for more information. # They need to be set before the find_package( ...) calls below. #if(ANDROID) # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") # if (ANDROID_ABI STREQUAL "armeabi-v7a") # set(ANDROID_EXTRA_LIBS # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so) # endif() #endif() find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) find_package(SDL2 REQUIRED) include_directories(${SDL_INCLUDE_DIR}) set(PROJECT_SOURCES main.cpp tgs_window_main.cpp tgs_window_main.h tgs_window_main.ui ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(TGS_Editor ${PROJECT_SOURCES} ) else() if(ANDROID) add_library(TGS_Editor SHARED ${PROJECT_SOURCES} ) else() add_executable(TGS_Editor ${PROJECT_SOURCES} ) endif() endif() target_link_libraries(TGS_Editor PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${SDL2_LIBRARIES})
Any hints on how to include SDL2 into my project
Project is freshly created with cmake and Mingw for 64Bit as Kit and Build&Run..
(QT Online Installer)
Planned to inlcude is: OpenGl ES, Angle, SDL2 -
You have to select the cmake version you want to use in the Kit settings.
-
You have to select the cmake version you want to use in the Kit settings.
wrote on 18 Apr 2021, 19:43 last edited by@Christian-Ehrlicher Thank you.. now is just the SDL2 Part missing..
-
Either SDL2 ships a proper cmake file or you have to add the include dir and library by yourself (target_include_directories() and target_link_libraries())
-
Either SDL2 ships a proper cmake file or you have to add the include dir and library by yourself (target_include_directories() and target_link_libraries())
wrote on 19 Apr 2021, 07:57 last edited by@Christian-Ehrlicher Yes.. tried target_link_libraries..
there is not much info on how to use sdl2, with cmake under QT under Windows.. so.. how to do that, cause my approach isn't working.. -
Lifetime Qt Championwrote on 19 Apr 2021, 08:24 last edited by Christian Ehrlicher
@BDC_Patrick said in How to change CMake version and Include SDL2?:
so.. how to do that,
You should ask the SDL2 guys which library you have to link to. And
isn't working
is not error description at all... -
@BDC_Patrick said in How to change CMake version and Include SDL2?:
so.. how to do that,
You should ask the SDL2 guys which library you have to link to. And
isn't working
is not error description at all...wrote on 19 Apr 2021, 09:32 last edited by@Christian-Ehrlicher That´s why i posted a Screenshot of the occuring Error in the OP ^^
-
wrote on 19 Apr 2021, 09:50 last edited by
I found a solution by myself with trial&Error.
Here is a complete CmakeList.txt for you:
cmake_minimum_required(VERSION 3.5) project(MyProgram LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) # QtCreator supports the following variables for Android, which are identical to qmake Android variables. # Check https://doc.qt.io/qt/deployment-android.html for more information. # They need to be set before the find_package( ...) calls below. #if(ANDROID) # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") # if (ANDROID_ABI STREQUAL "armeabi-v7a") # set(ANDROID_EXTRA_LIBS # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so) # endif() #endif() find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) find_package(SDL2) include_directories(${SDL2_INCLUDE_DIR}) set(PROJECT_SOURCES main.cpp mainWin.cpp mainWin.h mainWin.ui ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(MyProgram ${PROJECT_SOURCES} ) else() if(ANDROID) add_library(MyProgram SHARED ${PROJECT_SOURCES} ) else() add_executable(MyProgram ${PROJECT_SOURCES} ) endif() endif() target_link_libraries(MyProgram PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${SDL2_LIBRARIES})
include via
#include <SDL2\SDL.h>
And don´t forget to change the
int main(int argc, char *argv[])
in your main.cpp to:
int WinMain(int argc, char *argv[])
Works now without Errors..
-
@BDC_Patrick said in How to change CMake version and Include SDL2?:
int WinMain(int argc, char *argv[])
Why? Is this needed by SDL?
-
@BDC_Patrick said in How to change CMake version and Include SDL2?:
int WinMain(int argc, char *argv[])
Why? Is this needed by SDL?
wrote on 20 Apr 2021, 10:05 last edited by@Christian-Ehrlicher I changed it back to main..
SDL complains missing references to WinMain.. undefining it, before including SDL, works.
1/10