Configure / Build Qt Project (cmake) from batch script on Windows
-
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?
-
@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.
-
@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