I would like to create an installer for my program, which uses OpenCV and some Qt libraries. I also want to make sure that all dependencies are included in the installer so that anyone could easily install my program without installing OpenCV and/or Qt.
I did some research and it seems that the easiest way to do so would be using Qt Installer Framework. I have the following CMakeLists.txt file:
cmake_minimum_required(VERSION 3.0)
# Add folder where are supportive functions
set(CMAKE_AUTOMOC ON)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
# Include qt basic functions
include(QtCommon)
# Include qt current directories in order to use promoted objects
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules/app)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules/cores)
# Basic info about project
project(SSAT VERSION 1.0)
# Set PROJECT_VERSION_PATCH and PROJECT_VERSION_TWEAK to 0 if not present, needed by add_project_meta
fix_project_version()
file(GLOB APP_GUI_FILES "modules/app/*.ui")
file(GLOB APP_SOURCE_FILES "modules/app/*.cpp")
file(GLOB CORE_SOURCE_FILES "modules/core/*.cpp")
file(GLOB CORE_INCLUDE_FILES "modules/core/*.h")
file(GLOB CMT_SOURCE_FILES "modules/tracker/*.cpp")
file(GLOB CMT_INCLUDE_FILES "modules/tracker/*.h")
add_project_meta(META_FILES_TO_INCLUDE)
set(RESOURCE_FILES ssat.qrc)
find_package( OpenCV REQUIRED )
find_package(Qt5Widgets REQUIRED)
find_package(OpenCV COMPONENTS opencv_core opencv_imgproc opencv_imgcodecs opencv_highgui REQUIRED)
find_path(OpenCV_INCLUDE_DIR "opencv/cv.h" PATHS "${OpenCV_DIR}" PATH_SUFFIXES "include" DOC "")
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# source_group("UI Files" FILES ${UI_FILES})
add_library(${PROJECT_NAME}_CORE ${CORE_SOURCE_FILES} ${CORE_INCLUDE_FILES})
target_link_libraries(${PROJECT_NAME}_CORE ${OpenCV_LIBS})
target_include_directories(${PROJECT_NAME}_CORE PUBLIC modules/core/)
add_library(${PROJECT_NAME}_CMT ${CMT_SOURCE_FILES} ${CMT_INCLUDE_FILES})
target_link_libraries(${PROJECT_NAME}_CMT ${OpenCV_LIBS})
target_include_directories(${PROJECT_NAME}_CMT PUBLIC modules/tracker/)
add_executable(${PROJECT_NAME} ${OS_BUNDLE} # Expands to WIN32 or MACOS_BUNDLE depending on OS
${APP_GUI_FILES} ${APP_SOURCE_FILES} ${META_FILES_TO_INCLUDE} ${RESOURCE_FILES}
)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_CORE)
target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_CMT)
target_link_libraries(${PROJECT_NAME} pthread)
target_include_directories(${PROJECT_NAME} PUBLIC ${OpenCV_INCLUDE_DIR})
qt5_use_modules(${PROJECT_NAME} Widgets)
Since Qt Installer Framework demonstrates how to create an an installer from a Qt Project (.pro) instead of a CMake file, I would like to know if it is possible to create an installer from a CMake project in such a way that all its dependencies are included.
Related
When I execute my CMakelists.txt the target executable is not packaged with neither the autogenerated .zip or the installer, it is located in the root of the build directory. All that is included within the .zip and the installer is the appropriate .dlls, etc. Can someone explain what I'm doing wrong?
cmake_minimum_required(VERSION 3.10.0)
project(TranslationVerification VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5 5.15 COMPONENTS Widgets REQUIRED)
if(Qt5Widgets_FOUND)
if(${Qt5Widgets_VERSION} VERSION_LESS 5.15)
message(FATAL_ERROR "Minimum supported Qt5 version is 5.15!")
endif()
endif()
include(FetchContent)
FetchContent_Declare(qonlinetranslator
GIT_REPOSITORY https://github.com/crow-translate/QOnlineTranslator.git
)
FetchContent_GetProperties(qonlinetranslator)
if(NOT qonlinetranslator_POPULATED)
FetchContent_Populate(qonlinetranslator)
add_subdirectory(${qonlinetranslator_SOURCE_DIR} ${qonlinetranslator_BINARY_DIR})
endif()
set(PROJECT_SOURCES
src/main.cpp
src/addlanguagedialog.cpp
src/addlanguagedialog.ui
src/verification.cpp
src/widgetwindow.ui
src/widgetwindow.cpp
)
if(QT_VERSION_MAJOR GREATER_EQUAL 5)
qt_add_executable(translationVerification
MANUAL_FINALIZATION
${PROJECT_SOURCES})
else()
add_executable(translationVerification
${PROJECT_SOURCES})
endif()
target_include_directories(translationVerification PUBLIC
"${qonlinetranslator_BINARY_DIR}/src"
"${qonlinetranslator_SOURCE_DIR}/src")
target_link_libraries(translationVerification PUBLIC QOnlineTranslator PRIVATE Qt5::Widgets)
if(QT_VERSION_MAJOR EQUAL 5)
qt_finalize_executable(translationVerification)
endif()
##CPack
get_target_property(_qmake_executable Qt5::qmake IMPORTED_LOCATION)
get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY)
set(CPACK_PACKAGE_NAME "Translation Verification")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Translation Verification Installation")
set(CPACK_PACKAGE_VERSION "1.0.0") # Version of installer
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "TranslationVerification")
set(CPACK_NSIS_DISPLAY_NAME ${CMAKE_PACKAGE_NAME})
set(CPACK_NSIS_COMPRESSOR lzma)
set(CPACK_NSIS_INSTALLED_ICON_NAME TranslationVerification.exe)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
include(InstallRequiredSystemLibraries)
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}")
add_custom_command(TARGET translationVerification POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/qtDeploy/"
COMMAND "${CMAKE_COMMAND}" -E
env PATH="${_qt_bin_dir}" "${WINDEPLOYQT_EXECUTABLE}"
--verbose 0
--no-compiler-runtime
--no-angle
--no-webkit2
--no-quick-import
--no-translations
--dir "${CMAKE_CURRENT_BINARY_DIR}/qtDeploy/" $<TARGET_FILE:translationVerification>
COMMENT "Deploying Qt..."
)
install(
DIRECTORY "${CMAKE_BINARY_DIR}/qtDeploy/"
DESTINATION .
)
set(CPACK_GENERATOR "ZIP;NSIS")
endif()
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-src")
set(CPACK_SOURCE_GENERATOR "ZIP;TGZ")
include(CPack)
The windeployqt copies only the executable's dependencies, so you need to add the executable's installation. Note that if you use DESTINATION . for the destination folder of the binary, this can cause problems when porting the project to other platforms. In such cases it is better to use TYPE BIN instead of DESTINATION .
if(QT_VERSION_MAJOR EQUAL 5)
qt_finalize_executable(translationVerification)
endif()
install(PROGRAMS
$<TARGET_FILE:translationVerification>
DESTINATION .)
##CPack
You can also add include(GNUInstallDirs) before the first install() for portability purposes.
if(QT_VERSION_MAJOR EQUAL 5)
qt_finalize_executable(translationVerification)
endif()
include(GNUInstallDirs)
install(PROGRAMS
$<TARGET_FILE:translationVerification>
TYPE BIN)
##CPack
.
.
.
install(
DIRECTORY "${CMAKE_BINARY_DIR}/qtDeploy/"
TYPE BIN
)
set(CPACK_GENERATOR "ZIP;NSIS")
endif()
I have a Qt/QML project using CMake, which contains a sub-directory for the tests.
But every-time I build the project on QtCreator (ctrl+b, or "build project "), every test have is run. My problem is that some of them are linked to graphic event and thus show a windows that will flash on the screen. I would like to run these tests only when I explicitly want.
Is there a way to build without specific tests?
Edit:
Top CmakeList:
cmake_minimum_required(VERSION 3.16)
project(Projet 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)
find_package(Qt6 COMPONENTS Core Quick Quick3D REQUIRED)
set(MAIN_FILE src/main.cpp)
set(SOURCE_FILES
[...]
)
set(HEADER_FILES
[...]
)
set(QRC_FILES
[...]
)
# Compile everything except main.cpp in a separate library (needed for unit testing)
set(LIB_NAME ${PROJECT_NAME}_LIB)
add_library(${LIB_NAME} STATIC ${SOURCE_FILES} ${HEADER_FILES} ${QRC_FILES})
target_link_libraries(${LIB_NAME} Qt6::Core Qt6::Quick Qt6::Quick3D)
target_include_directories(${LIB_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/)
# Link the library to the executable
add_executable(${PROJECT_NAME} ${MAIN_FILE})
target_link_libraries(${PROJECT_NAME} ${LIB_NAME})
add_subdirectory(test)
The main folder contains a subfolder test, containing the Test CMakeList:
cmake_minimum_required(VERSION 3.1)
project(Projet_Test)
set(CMAKE_AUTOMOC ON)
set(SOURCE_FILES
[...]
)
set(HEADER_FILES
[...])
set(QML_TESTCASES
[...]
)
find_package(Qt6 COMPONENTS Quick Qml QuickTest REQUIRED)
set(QML_IMPORT_PATH "${QML_IMPORT_PATH};${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "Standard Qt variable")
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES} ${QML_TESTCASES})
# Qt macro where all qml testcase are located
target_compile_definitions(${PROJECT_NAME} PRIVATE -DQUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_definitions(-DQML_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Quick Qt6::Quick3D Qt6::QuickTest PRIVATE Projet_LIB)
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
I have a QLM project MyProject compiled with CMake, for which I wanted to add tests.
I figured I would create another project MyProject_tests, and a top level CMakeLists containing both :
MetaMyProject
|-CMakeLists.txt (1)
|-MyProject
| |-CMakeLists.txt (2)
|-MyProject_test
| |-CMakeLists.txt (3)
First CMakeLists contains
cmake_minimum_required(VERSION 3.3)
project(MetaMyProject CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
add_subdirectory(MyProject)
add_subdirectory(MyProject_Test)
Second CMakeLists is not changed, except I added set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS 1) at the end.
Third CMakeLists contains
cmake_minimum_required(VERSION 3.1)
project(MyProject_ContraintsTest)
find_package(Qt6 COMPONENTS QuickTest REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(SOURCE_FILES
main.cpp
)
set(HEADER_FILES
)
set(QML_TESTCASE_FILES
testcases/tst_test.qml
)
add_definitions(-DQUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/testcases")
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES} ${QML_TESTCASE_FILES})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::QuickTest)
Now for the component defined in MyProject to be available in MyProject_test, I wanted to add on the last line a PIVATE MyProject. It does not raise warning, but import MyProject does not work then.
What is the correct way to link my test project to the base project in order for all the components to be available in the test project?
ENABLE_EXPORTS enables symbol exports from an executable, these symbols can be used in another library or executable. To be able to use a symbol in your qml, you would need to re-register the exported Qt Class in your MyProject_test/main.cpp using:
qmlRegisterType<MyExportedClass>("MyExportedClass", 1, 0, "MyExportedClass");
Then you would be able to use it with import MyExportedClass 1.0
I'm trying to compile qtserialport to my project in QtCreator4.9.2 with ROS plugin in.
Of course, I had follow the doc to install qtserialport to my Ubuntu16.04. And then, I had do some tests like this:
#include "QtSerialPort/qserialport.h"
#include "QtSerialPort/qserialportinfo.h"
...
Q_FOREACH(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
ROS_INFO("Name: %s", info.portName().toStdString().c_str());
ROS_INFO("Description: %s", info.description().toStdString().c_str());
ROS_INFO("Manufacturer: %s", info.manufacturer().toStdString().c_str());
...
}
But, get erros:
undefined reference to 'QSerialPortInfo::availablePorts()'
undefined reference to 'QSerialPortInfo::portName() const'
undefined reference to 'QSerialPortInfo::description() const'
...
undefined reference to 'QSerialPortInfo::~QSerialPortInfo()'
You know, I'm working with CMake, so the official docs about qmake or .pro introductions is useless to me. And I had find some suggestions like this, however, I'm confused with this: how to make the qtserialport as a module?
Anyway, all I want to say is that: how can I compile qtserialport with my ros CMake project? And certainly, it should also work with my QtCreator.
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.0)
project(xxx)
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS qt_build roscpp)
include_directories(${catkin_INCLUDE_DIRS})
catkin_package()
rosbuild_prepare_qt4(QtCore QtGui QtOpenGL)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} rsources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/xxx/*.hpp)
QT4_ADD_RESOURCES(QT_RSOURCES_CPP ${QT_RESOURCES})
QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})
set(QT_SOURCES ...)
if(MSVC)
set(...)
endif(MSVC)
add_definitions(...)
include_directories(...)
set(EXTERNAL_LIBRARIES OpenThreads osg osgDB osgViewer osgUtil osgText osgGA pthread lz4 bz2)
add_executable(... ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_MOC_HPP})
target_link_libraries(xxx ${QT_LIBRARIES} ${EXTERNAL_LIBRARIES} ${catkin_LIBRARIES})
install(TARGETS xxx RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
Help!
QtCreator4.9.2 is your IDE's version, not the framework's version you probably are using Qt 5.1x.x version.
If you want to compile out of your IDE this line is essential
set(CMAKE_PREFIX_PATH your/qt/path/which/can/be/obtained)
check this path from QT Creator > Open a Qt Project > Projects option on Left bar > Project Build Option, on CMake settings check cmake_prefix_path
# Before add_executable
find_package(Qt5 COMPONENTS Core SerialPort REQUIRED)
# After add_executable
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt5::Core Qt5::SerialPort)
You also can learn package names under CMake folder of your Qt path.
/your/sys/path/Qt5/lib/cmake
I am trying to run a Qt project in CMake environment. After solving compiling errors I have been trying to solve a CMake error that I am quoting below:
Target "ColorCorrector" links to target "Qt5::Quick" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
Target "ColorCorrector_lib" links to target "Qt5::Quick" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
The same errors I am getting for the following targets:
"Qt5::Sql", "Qt5::XmaPatterns" as shown also in the attached print screen:
Below the CMakeList.txt file I am working on:
cmake_minimum_required (VERSION 3.1)
project(colorCorrector)
find_package( OpenCV REQUIRED )
find_package( Boost COMPONENTS system thread filesystem REQUIRED)
find_package ( Qt5 REQUIRED COMPONENTS Quick Sql XmlPatterns Xml )
###
### make sure we use c++11
###
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
###
###boost include stuff (required for all libcam)
###
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
###
### QT stuff (required if you want a GUI)
###
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Widgets)
find_package(Qt5PrintSupport)
#find all the qt UI stuff
file(GLOB UI
"ui/*.ui"
)
#make them into headers
qt5_wrap_ui (UI_HDRS ${UI})
###
### add all your non QT sources
###
# find all non ui sources
file(GLOB SRCS
"src/*.h"
"src/*.cpp"
"src/*.hpp"
)
# find all ui related sources
file(GLOB UI_SRCS
"ui/*.h"
"ui/*.cpp"
"ui/*.hpp"
)
###
### Add executables
###
add_executable(colorCorrector main/main.cpp ui/qdarkstyle/style.qrc ${SRCS} ${UI_HDRS})
target_link_libraries (colorCorrector libCam Qt5::Widgets Qt5::Quick Qt5::Sql Qt5::XmlPatterns Qt5::Xml ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport)
###
### Add Library
###
add_library(colorCorrector_lib SHARED ui/qdarkstyle/style.qrc ${SRCS} ${UI_HDRS})
target_include_directories (colorCorrector_lib PUBLIC "src/" "ui/")
target_link_libraries (colorCorrector_lib libCam Qt5::Widgets Qt5::PrintSupport ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::Quick Qt5::Sql Qt5::XmlPatterns Qt5::Xml)
I am looking at different possible solutions such as here's a link I looked and this link is also useful but still didn't solve my problem.
Additionally I tried to add the following according to CMake documentation to the CMakeList.txt file mentioned above:
find_package(Qt5Sql)
find_package(Qt5XmlPatterns)
find_package(Qt5Quick)
find_package(Qt5Widgets)
find_package(Qt5PrintSupport)
Any idea on what the problem could be?