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. Change build directory with cmake

Change build directory with cmake

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 2 Posters 1.2k 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.
  • M Offline
    M Offline
    Mark81
    wrote on 29 Nov 2024, 09:41 last edited by Mark81
    #1

    I'm making the first project using cmake instead of qmake.
    I noticed it placed the build directory in my documents folder, instead of the source directory as cmake usually does.

    So I just changed it using the Project > Build directory parameter.

    Now the project does not build anymore. I still have my CMakeLists.txt file but here the errors:

    /home/user/<source-path-directory>/CMakeLists.txt:15: error: Found package configuration file:
    
      /usr/lib/x86_64-linux-gnu/cmake/Qt6/Qt6Config.cmake
    
    but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
    FOUND.  Reason given by package:
    
    Failed to find required Qt component "SerialPort".
    
    Expected Config file at
    "/usr/lib/x86_64-linux-gnu/cmake/Qt6SerialPort/Qt6SerialPortConfig.cmake"
    does NOT exist
    :-1: error: The command "/home/user/Qt/Tools/CMake/bin/cmake -S /home/user/<source-path-directory> -B /home/user/<source-path-directory>" terminated with exit code 1.
    :-1: error: CMake project configuration failed. No CMake configuration for build type "Debug" found. Check General Messages for more information.
    

    It seems it switched to the system-wide Qt6 libraries and now it ignores the actual Qt6 installation (in /home/user/Qt/...).

    Did I do something wrong? Is it not possible to change the build directory while using cmake?
    And, of course, how to fix it?

    This is my CMakeLists.txt file:

    cmake_minimum_required(VERSION 3.5)
    
    project(BRM VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    set(CMAKE_PREFIX_PATH "/home/user/<path-to-sources>/lib/cmake/QtModelUtilities/" ${CMAKE_MODULE_PATH})
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Sql SerialPort)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Sql SerialPort)
    find_package(QtModelUtilities)
    
    set(PROJECT_SOURCES
            main.cpp
            mainwindow.cpp
            mainwindow.h
            mainwindow.ui
    )
    
    qt_add_executable(BRM
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        resources.qrc
        formbouquets.h formbouquets.cpp formbouquets.ui
        formsongs.h formsongs.cpp formsongs.ui
        formalarms.h formalarms.cpp formalarms.ui
        formsessions.h formsessions.cpp formsessions.ui
        formprotocols.h formprotocols.cpp formprotocols.ui
        formpackages.h formpackages.cpp formpackages.ui
        tableengine.h tableengine.cpp
        formcolors.h formcolors.cpp formcolors.ui
        delegatereal.h
        formtranslations.h formtranslations.cpp formtranslations.ui
        dialoglanguages.h dialoglanguages.cpp dialoglanguages.ui
        dialogcolorpicker.h dialogcolorpicker.cpp dialogcolorpicker.ui
        femtoserial2.cpp femtoserial2.h
    )
    
    target_link_libraries(BRM PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
    target_link_libraries(BRM PRIVATE Qt${QT_VERSION_MAJOR}::Sql)
    target_link_libraries(BRM PRIVATE Qt${QT_VERSION_MAJOR}::SerialPort)
    target_link_libraries(BRM PRIVATE QtModelUtilities::QtModelUtilities)
    
    set_target_properties(BRM PROPERTIES
        ${BUNDLE_ID_OPTION}
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    include(GNUInstallDirs)
    install(TARGETS BRM
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    
    if(QT_VERSION_MAJOR EQUAL 6)
        qt_finalize_executable(BRM)
    endif()
    

    By the way, the "Current configuration" still reports che correct path:

    -DCMAKE_PREFIX_PATH:PATH=/home/user/Qt/6.8.0/gcc_64
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 29 Nov 2024, 10:01 last edited by
      #2

      Don't do in-source builds. Use a clean source and build dir and start over.

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

      M 1 Reply Last reply 29 Nov 2024, 10:05
      0
      • C Christian Ehrlicher
        29 Nov 2024, 10:01

        Don't do in-source builds. Use a clean source and build dir and start over.

        M Offline
        M Offline
        Mark81
        wrote on 29 Nov 2024, 10:05 last edited by
        #3

        @Christian-Ehrlicher said in Change build directory with cmake:

        Don't do in-source builds. Use a clean source and build dir and start over.

        Sorry, I explained it wrong. I didn't mean to build under the source directory, but in a sibling one.
        Usually I set it up like this:

        /home/user/dev/my-project-source-dir
        /home/user/dev/build-my-project-...
        

        But cmake placed the build directory under /home/user/Documents/... without any question.
        I don't like to spread over my hard-drive the build directories... so I just set the build directory to /home/user/dev/build-my-project-... NOT below the source folder.

        Is it wrong?
        Are you saying I have to throw away all the stuff, create a new project from scratch? But it would change nothing: it will place again the build directory under Documents and I need to change the path....

        C 1 Reply Last reply 29 Nov 2024, 10:10
        0
        • M Mark81
          29 Nov 2024, 10:05

          @Christian-Ehrlicher said in Change build directory with cmake:

          Don't do in-source builds. Use a clean source and build dir and start over.

          Sorry, I explained it wrong. I didn't mean to build under the source directory, but in a sibling one.
          Usually I set it up like this:

          /home/user/dev/my-project-source-dir
          /home/user/dev/build-my-project-...
          

          But cmake placed the build directory under /home/user/Documents/... without any question.
          I don't like to spread over my hard-drive the build directories... so I just set the build directory to /home/user/dev/build-my-project-... NOT below the source folder.

          Is it wrong?
          Are you saying I have to throw away all the stuff, create a new project from scratch? But it would change nothing: it will place again the build directory under Documents and I need to change the path....

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 29 Nov 2024, 10:10 last edited by
          #4

          @Mark81 said in Change build directory with cmake:

          But cmake placed the build directory under /home/user/Documents/... without any question.

          cmake does not place anything anywhere without question. It does what it gets told. Maybe you configured QtCreator (you did not tell us what you're using as IDE) so that the build dir is somewhere else, I don't know.
          If you're using QtCreator, make sure the kit is configured correctly and you're using the correct kit.
          https://doc.qt.io/qtcreator/creator-targets.html

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

          M 1 Reply Last reply 29 Nov 2024, 10:33
          1
          • C Christian Ehrlicher
            29 Nov 2024, 10:10

            @Mark81 said in Change build directory with cmake:

            But cmake placed the build directory under /home/user/Documents/... without any question.

            cmake does not place anything anywhere without question. It does what it gets told. Maybe you configured QtCreator (you did not tell us what you're using as IDE) so that the build dir is somewhere else, I don't know.
            If you're using QtCreator, make sure the kit is configured correctly and you're using the correct kit.
            https://doc.qt.io/qtcreator/creator-targets.html

            M Offline
            M Offline
            Mark81
            wrote on 29 Nov 2024, 10:33 last edited by
            #5

            @Christian-Ehrlicher said in Change build directory with cmake:

            cmake does not place anything anywhere without question. It does what it gets told. Maybe you configured QtCreator (you did not tell us what you're using as IDE) so that the build dir is somewhere else, I don't know.

            I'm using Qt Creator 14.0.2.
            Anyway, there is no need to restart from scratch. It was enough to remove the kit from Build&Run and select it again.
            It seems the chaning of the build directory is not working, at least on my installation.

            1 Reply Last reply
            0
            • C Christian Ehrlicher moved this topic from Installation and Deployment on 29 Nov 2024, 12:49

            3/5

            29 Nov 2024, 10:05

            • Login

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