Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. How to change CMake version and Include SDL2?
Forum Updated to NodeBB v4.3 + New Features

How to change CMake version and Include SDL2?

Scheduled Pinned Locked Moved Solved Installation and Deployment
10 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BDC_PatrickB Offline
    BDC_PatrickB Offline
    BDC_Patrick
    wrote on last edited by
    #1

    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
    A.jpg

    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..
    A2.jpg

    So..

    find_package(SDL2 REQUIRED)
    

    Is not working in the CmakeList...
    This is my current CMakeList.txt

    cmake_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

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You have to select the cmake version you want to use in the Kit settings.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      BDC_PatrickB 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        You have to select the cmake version you want to use in the Kit settings.

        BDC_PatrickB Offline
        BDC_PatrickB Offline
        BDC_Patrick
        wrote on last edited by
        #3

        @Christian-Ehrlicher Thank you.. now is just the SDL2 Part missing..

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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())

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          BDC_PatrickB 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            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())

            BDC_PatrickB Offline
            BDC_PatrickB Offline
            BDC_Patrick
            wrote on last edited by
            #5

            @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..

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by Christian Ehrlicher
              #6

              @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...

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              BDC_PatrickB 1 Reply Last reply
              0
              • Christian EhrlicherC 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_PatrickB Offline
                BDC_PatrickB Offline
                BDC_Patrick
                wrote on last edited by
                #7

                @Christian-Ehrlicher That´s why i posted a Screenshot of the occuring Error in the OP ^^

                1 Reply Last reply
                0
                • BDC_PatrickB Offline
                  BDC_PatrickB Offline
                  BDC_Patrick
                  wrote on last edited by
                  #8

                  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..

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @BDC_Patrick said in How to change CMake version and Include SDL2?:

                    int WinMain(int argc, char *argv[])

                    Why? Is this needed by SDL?

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    BDC_PatrickB 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @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_PatrickB Offline
                      BDC_PatrickB Offline
                      BDC_Patrick
                      wrote on last edited by
                      #10

                      @Christian-Ehrlicher I changed it back to main..

                      SDL complains missing references to WinMain.. undefining it, before including SDL, works.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved