Change build directory with cmake
-
I'm making the first project using
cmake
instead ofqmake
.
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
-
Don't do in-source builds. Use a clean source and build dir and start over.
-
@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.... -
@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 -
@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. -