I have an example ROS project with 1 package dashboard. The CMakeLists.txt of this package is here:
cmake_minimum_required(VERSION 3.14)
project(dashboard VERSION 0.1 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)
set(CMAKE_VERBOSE_MAKEFILE on )
set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick QuickControls2 Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick QuickControls2 Widgets REQUIRED)
set(PROJECT_SOURCES
src/main.cpp
)
set(PROJECT_RESOURCES
qml.qrc
imports.qrc
)
list(APPEND QML_IMPORT "${CMAKE_SOURCE_DIR}/")
list(APPEND QML_IMPORT "${CMAKE_SOURCE_DIR}/imports")
list(REMOVE_DUPLICATES QML_IMPORT)
set(QML2_IMPORT_PATH "${QML_IMPORT}" CACHE STRING "" FORCE)
set(QML_IMPORT_PATH "${QML_IMPORT}" CACHE STRING "" FORCE)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(${PROJECT_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
else()
add_executable(${PROJECT_NAME}
${PROJECT_SOURCES}
${QT_RESOURCES_CPP}
${${PROJECT_NAME}_MOCS}
${${PROJECT_NAME}_QML}
${PROJECT_RESOURCES}
)
endif()
target_compile_definitions(${PROJECT_NAME} PUBLIC SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::QuickControls2
Qt${QT_VERSION_MAJOR}::Widgets
)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_import_qml_plugins(${PROJECT_NAME})
qt_finalize_executable(${PROJECT_NAME})
endif()
I have set both QML_IMPORT_PATH and QML_IMPORT_PATH, but still have an issue QML module not found (Themes.MyTheme).
Here is MyTheme qmldir:
module Themes.MyTheme
singleton Theme 1.0 Theme.qml
The project is compiled and launched, but autocomplete don't working and Theme isn't defined.
The question is: how to correctly import module in .qml file in ROS project for everything working?
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 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?
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.