Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Configure / Build Qt Project (cmake) from batch script on Windows
Forum Updated to NodeBB v4.3 + New Features

Configure / Build Qt Project (cmake) from batch script on Windows

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
buildcmakecommand line
3 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    Hello,

    I want to automatically build a cmake Qt project with several version that are defined by bools in cmake.
    My idea is something like this:

    build_all.bat

    @echo off
    cmake -DBUILD_TYPE_1:BOOL=TRUE 
    cmake --build C:/Build/myQtApp/build_r --target all
    xcopy C:\Build\myQtApp\build_r\bin\myQtApp.exe C:\Build\BuildFolder1 /Y
    
    cmake -DBUILD_TYPE_1:BOOL=FALSE 
    cmake --build C:/Build/myQtApp/build_r --target all
    xcopy C:\Build\myQtApp\build_r\bin\myQtApp.exe C:\Build\BuildFolder2 /Y
    

    However I'm getting the error:

    CMake Error at myQtApp/CMakeLists.txt:602 (add_executable): Target "myQtApp" links to target "Qt5::Core" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?

    So my Questions is what else do I need to put inside the batch file so I can compile as from within QtCreator. Is there some example somewhere that shows how to do this?

    Or is the whole idea silly and there is some better way to achieve what I want?

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

      @gde23 said in Configure / Build Qt Project (cmake) from batch script on Windows:

      -DBUILD_TYPE_1:BOOL=TRUE

      What should this do? Did you define / use it in your CMakeLists.txt somehwere? If so please post your CMakeLists.txt

      If Qt5::Core was not find then you either did not call FIND_PACKAGE(Qt5 REQUIRED Core) or this call failed because cmake can not find your Qt installation.

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

      gde23G 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @gde23 said in Configure / Build Qt Project (cmake) from batch script on Windows:

        -DBUILD_TYPE_1:BOOL=TRUE

        What should this do? Did you define / use it in your CMakeLists.txt somehwere? If so please post your CMakeLists.txt

        If Qt5::Core was not find then you either did not call FIND_PACKAGE(Qt5 REQUIRED Core) or this call failed because cmake can not find your Qt installation.

        gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        Got it working by myself now, but thanks anyhow for the quick reply.

        The problem was that i called cmake from within the source not the build dir so it ran cmake for a fresh new build that wasn't already setup from within Qtcreator and did not know where to search for Qt stuff.

        This is my script now:

        cd C:\Build\myQtApp\build_r
        
        cmake -S Y:/ -B C:/Build/myQtApp/build_r "-DBUILD_TYPE_1:BOOL=ON" "-DBUILD_TYPE_2:BOOL=ON"
        cmake --build C:/Build/myQtApp/build_r --target all -j2
        ...
        cmake -S Y:/ -B C:/Build/myQtApp/build_r "-DBUILD_TYPE_1:BOOL=OFF" "-DBUILD_TYPE_2:BOOL=ON"
        cmake --build C:/Build/myQtApp/build_r --target all -j2
        

        The boolean parameters BUILD_TYPE_1 and so on are used inside cmake to add a preprocessor defines that are then used to switch between different build configurations just in case anybody wants to know.

        In cmake:

        if(BUILD_TYPE_1)
            message(STATUS "Build Type: Type 1")
            add_definitions(-DBUILD_TYPE_1)
        endif()
        

        in c++

        #ifdef BUILD_TYPE_1
        ...
        #endif
        
        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