Creating installer using cpack and windeployqt, To contain qt and VTK libraries - c++

Trying to package an application with Microsoft Visual Studio 2022 and qt6 libraries I do not no were to start from. I've done a bit of research most people used qt5 and when I replace the text with qt6 it doesn't seem to work. I used dependency walker to find the necessary libraries and I seem to have achieved a way to add the Visual Studio libraries but not qt and VTK.
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
foreach(p
CMP0071 # 3.10: Let AUTOMOC and AUTOUIC process GENERATED files
)
if(POLICY ${p})
cmake_policy(SET ${p} NEW)
endif()
endforeach()
PROJECT( QtVTKExample )
#set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
if (MSVC_VERSION EQUAL 1930 AND MSVC_TOOLSET_VERSION EQUAL 142)
cmake_host_system_information(RESULT VS_DIR QUERY VS_17_DIR)
file(GLOB MSVC_REDIST_LIBRARIES "${VS_DIR}/VC/Redist/MSVC/*/${MSVC_C_ARCHITECTURE_ID}/Microsoft.VC143.CRT/*.dll")
list(APPEND CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS "${MSVC_REDIST_LIBRARIES}")
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS TRUE)
endif()
include(InstallRequiredSystemLibraries)
# Add to top of file CPACK stuff
include(CTest)
if(WIN32)
set(CPACK_GENERATOR "NSIS")
else()
set(CPACK_GENERATOR "ZIP")
endif()
include(CPack)
find_package(VTK COMPONENTS
vtkCommonColor
vtkCommonCore
vtkCommonDataModel
vtkInteractionStyle
vtkRenderingContextOpenGL2
vtkRenderingCore
vtkRenderingFreeType
vtkRenderingGL2PSOpenGL2
vtkRenderingOpenGL2
QUIET
)
# The CMake build process might generate some new files in the current
# directory. This makes sure they can be found.
set( CMAKE_INCLUDE_CURRENT_DIR ON )
# This allows CMake to run one of Qt's build tools called moc
# if it is needed. moc.exe can be found in Qt's bin directory.
# We'll look at what moc does later.
set( CMAKE_AUTOMOC ON )
set( CMAKE_AUTOUIC ON )
# Find the Qt widgets package. This locates the relevant include and
# lib directories, and the necessary static libraries for linking.
find_package( Qt6Widgets )
set( UIS mainwindow.ui )
qt6_wrap_ui( UI_Srcs ${UIS} )
set( ICONS Icons/icons.qrc )
qt6_add_resources( QRC_Srcs ${ICONS} )
# Also link to VTK
find_package( VTK REQUIRED )
include( ${VTK_USE_FILE} )
# Define the executable output and its sources
add_executable( QtVTKExample MACOSX_BUNDLE
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
tabcontent.cpp
tabcontent.h
tabcontent.ui
currentstl.cpp
currentstl.h
recentstl.cpp
recentstl.h
${UI_Srcs}
${QRC_Srcs}
)
# Tell CMake that the executable depends on the Qt::Widget libraries.
target_link_libraries( QtVTKExample Qt6::Widgets )
# Tell CMake that the executable depends on the VTK libraries
target_link_libraries( QtVTKExample ${VTK_LIBRARIES} )
# /calc_cmake/CMakeLists.txt
install(TARGETS QtVTKExample
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)

Related

How to use osgearth with vcpkg

I've installed osgearth package with vcpkg with following command:
vcpkg.exe install osgearth:x64-windows
Now in a CMake I want to use it.
cmake_minimum_required (VERSION 3.10.0)
project (osgmap)
add_definitions (-DOSGMAP_EXPORTS)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
find_package (Osg REQUIRED)
find_package(OsgEarth REQUIRED)
set (PROJECT_SRC
Dummy.cpp
)
add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
target_link_libraries (${PROJECT_NAME} mapapi)
target_compile_features (${PROJECT_NAME} PUBLIC cxx_std_17)
The problem is that I cannot find osgearth package. I've tried different options.
How can I use OsgEarth installed with vcpkg in a CMake project?
The short answer is there are findosg* modules in the cmake distribution and there are not any osgEarth modules to automatically find package paths. Package is either a config or module definition locating both the libs and includes. Vcpkg does not seem to automate package definition and it relies on the modules installed with CMake. What is possible is using find_library and find_path to locate the osgearth files.
find_library(OSGEARTH_LIBRARY osgearth)
assuming you ran vcpkg integrate and use the -DCMAKE_TOOLCHAIN_FILE with cmake. All the libs that were built with vcpkg can be found but not all as packages.
Once you have properly set up the CMAKE_TOOLCHAIN_FILE you need to provide a FindOsgEarth.cmake file. You could use:
# This module defines
# OSGEARTH_LIBRARY
# OSGEARTH_FOUND, if false, do not try to link to osg
# OSGEARTH_INCLUDE_DIRS, where to find the headers
# OSGEARTH_INCLUDE_DIR, where to find the source headers
# to use this module, set variables to point to the osg build
# directory, and source directory, respectively
# OSGEARTHDIR or OSGEARTH_SOURCE_DIR: osg source directory, typically OpenSceneGraph
# OSGEARTH_DIR or OSGEARTH_BUILD_DIR: osg build directory, place in which you've
# built osg via cmake
###### headers ######
MACRO( FIND_OSGEARTH_INCLUDE THIS_OSGEARTH_INCLUDE_DIR THIS_OSGEARTH_INCLUDE_FILE )
FIND_PATH( ${THIS_OSGEARTH_INCLUDE_DIR} ${THIS_OSGEARTH_INCLUDE_FILE}
PATHS
${OSGEARTH_DIR}
$ENV{OSGEARTH_SOURCE_DIR}
$ENV{OSGEARTHDIR}
$ENV{OSGEARTH_DIR}
/usr/local/
/usr/
/sw/ # Fink
/opt/local/ # DarwinPorts
/opt/csw/ # Blastwave
/opt/
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSGEARTH_ROOT]/
~/Library/Frameworks
/Library/Frameworks
PATH_SUFFIXES
/include/
)
ENDMACRO( FIND_OSGEARTH_INCLUDE THIS_OSGEARTH_INCLUDE_DIR THIS_OSGEARTH_INCLUDE_FILE )
FIND_OSGEARTH_INCLUDE( OSGEARTH_INCLUDE_DIR osgEarth/Version )
###### libraries ######
MACRO( FIND_OSGEARTH_LIBRARY MYLIBRARY MYLIBRARYNAME )
FIND_LIBRARY(${MYLIBRARY}
NAMES
${MYLIBRARYNAME}
PATHS
${OSGEARTH_DIR}
$ENV{OSGEARTH_BUILD_DIR}
$ENV{OSGEARTH_DIR}
$ENV{OSGEARTHDIR}
$ENV{OSG_ROOT}
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSGEARTH_ROOT]/lib
/usr/freeware
PATH_SUFFIXES
/lib/
/lib64/
/build/lib/
/build/lib64/
/Build/lib/
/Build/lib64/
)
ENDMACRO(FIND_OSGEARTH_LIBRARY LIBRARY LIBRARYNAME)
FIND_OSGEARTH_LIBRARY( OSGEARTH_LIBRARY osgEarth)
FIND_OSGEARTH_LIBRARY( OSGEARTHFEATURES_LIBRARY osgEarthFeatures)
FIND_OSGEARTH_LIBRARY( OSGEARTHUTIL_LIBRARY osgEarthUtil )
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY osgEarthQt )
FIND_OSGEARTH_LIBRARY( OSGEARTHSYMBOLOGY_LIBRARY osgEarthSymbology )
FIND_OSGEARTH_LIBRARY( OSGEARTHANNOTATION_LIBRARY osgEarthAnnotation )
SET( OSGEARTH_FOUND "NO" )
IF( OSGEARTH_LIBRARY AND OSGEARTH_INCLUDE_DIR )
SET( OSGEARTH_FOUND "YES" )
SET( OSGEARTH_INCLUDE_DIRS ${OSGEARTH_INCLUDE_DIR})
GET_FILENAME_COMPONENT( OSGEARTH_LIBRARIES_DIR ${OSGEARTH_LIBRARY} PATH )
ENDIF( OSGEARTH_LIBRARY AND OSGEARTH_INCLUDE_DIR )
Then add it to your CMakeModules folder and in your CMakeLists.txt:
LIST(APPEND CMAKE_MODULE_PATH "${${PROJECT_NAME}_SOURCE_DIR}/CMakeModules")
FIND_PACKAGE(OsgEarth REQUIRED)
IF(OSGEARTH_FOUND)
MESSAGE(STATUS "OsgEarth found")
ELSE()
MESSAGE(STATUS "OsgEarth NOT found")
ENDIF()
INCLUDE_DIRECTORIES(${OSGEARTH_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OSGEARTH_LIBRARY} ${OSGEARTHFEATURES_LIBRARY}
${OSGEARTHUTIL_LIBRARY} ${OSGEARTHSYMBOLOGY_LIBRARY}
${OSGEARTHANNOTATION_LIBRARY} ...)

Trying to use VTK-6.3.0 and Qt-4.8.5 with QtCreator-4.1 on Windows 10

For a project I need to use VTK and Qt (with QtCreator on C++) on Windows 10 but I have an issue.
Let me explain what I've done before going further:
I Install QtCreator-4.1 with MinGW 32bit and Qt-5.7
I download and install Qt-4.8.5 in the Qt directory (It isn't proposed in the QtCreator's MaintenanceTool)
I download VTK-6.3.0
I compile VTK with QtCreator (and a kit with Qt4) on Release with BUILD_SHARED_LIBS = True and VTK_Group_Qt = True
Then, I use an example and the CMakeLists.txt my teacher gave me, using Qt and VTK, but I have an error:
cannot find -lQVTK
In this code we use:
#include <QVTKWidget.h>
In my build directory I find : "libQVTKWidgetPlugin.dll.a" and "libQVTKWidgetPlugin.dll".
Here is the CMakeLists.txt I used (it was written for Linux user, but I'm not enough experienced to change it...):
project(foot)
cmake_minimum_required(VERSION 2.8)
# Where I built VTK
set(VTK_DIR "C:/Lib/VTK/build-VTK-6.3.0-Desktop_Qt_4_8_5_MinGW_32bit-Release")
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
set( Srcs main.cpp mainwindow.cpp )
set( Hdrs mainwindow.h )
set( MOC_Hdrs mainwindow.h )
# Use the include path and library for Qt that is used by VTK.
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
if(VTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5Widgets)
qt5_wrap_ui(UI_Srcs)
add_executable(qtevents
MACOSX_BUNDLE ${Srcs} ${Hdrs} ${MOC_Hdrs})
qt5_use_modules(qtevents Core Gui Widgets)
target_link_libraries(qtevents ${VTK_LIBRARIES})
else()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
# Use what VTK built with
set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")
qt4_wrap_cpp(MOCSrcs ${MOC_Hdrs})
add_executable(foot ${Srcs} ${Hdrs} ${MOC_Hdrs})
target_link_libraries(foot ${VTK_LIBRARIES} QVTK)
endif()
I really don't understand what I've done wrong and my teacher can't help me...
If you have any idea...
I would be glad to give you more info if needed!

How to create a CMakeLists.txt for a project containing CGAL and VTK libraries

I've written a small programm for evaluating sientific data (3D surface mesh). I do all the geometric calculations with functions provided by the vtk library. The vtkBooleanOperationPolyDataFilter is no robust and crashes randomly. So i decided to performe the boolean operations with functions of the cgal library (tested with some sample data -> no stability problems).
Now I want to merge this two projects together.
The vtk project CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
PROJECT(calcporosity)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(calcporosity MACOSX_BUNDLE calcporosity)
if(VTK_LIBRARIES)
target_link_libraries(calcporosity ${VTK_LIBRARIES})
else()
target_link_libraries(calcporosity vtkHybrid vtkWidgets)
endif()
The cgal project CMakeLists.txt:
project( cgal_test )
cmake_minimum_required(VERSION 2.6.2)
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER
2.6) if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}"
VERSION_GREATER 2.8.3)
cmake_policy(VERSION 2.8.4) else()
cmake_policy(VERSION 2.6) endif() endif()
find_package(CGAL QUIET COMPONENTS Core )
if ( CGAL_FOUND )
include( ${CGAL_USE_FILE} )
include( CGAL_CreateSingleSourceCGALProgram )
include_directories (BEFORE "../../include")
include_directories (BEFORE "include")
create_single_source_cgal_program( "cgaltest.cpp" ) else()
message(STATUS "This program requires the CGAL library, and will not be compiled.")
endif()
I tried to merge this to files but I've failed. Could some give me a hint how to create a proper CMakeLists.txt for a project which utilizes both libraries.
Thanks in advance and best regards!
P.s.: I'm working on a Windows plattform
Basically what needs to happen is that you need to provide include directories and link libraries from both of your dependencies to your executable.
cmake_minimum_required(VERSION 2.8.4)
project( cgal_vtk_test )
# Find CGAL
find_package(CGAL REQUIRED COMPONENTS Core) # If the dependency is required, use REQUIRED option - if it's not found CMake will issue an error
include( ${CGAL_USE_FILE} )
# Find VTK
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
# Setup your executable
include_directories (BEFORE "../../include")
include_directories (BEFORE "include")
include( CGAL_CreateSingleSourceCGALProgram )
create_single_source_cgal_program( "cgal_vtk_test.cpp" ) # This will create an executable target with name 'cgal_vtk_test'
# Add VTK link libraries to your executable target
target_link_libraries(cgal_vtk_test ${VTK_LIBRARIES})

including external libraries in cmakelists.txt file

I'm using cmake to build an executable to run on an Intel Galileo board.
My question is how do I include the external mraa library in the build process.
Mraa library
When I download the library from git (1) do I need to build it as described here
Mraa compiling instructions
What do I need to put in my CMakeLists.txt file to pick up the library?
This is what I have thus far in my CMakeLists.txt file but I believe it is incorrect.
### MRAA ###
add_subdirectory(mraa-master/src)
file(GLOB mraa_SRC
"mraa-master/src/*.c"
)
include_directories( "${PROJECT_SOURCE_DIR}/mraa-master/include" )
add_library( ${MRAA_LIBRARY_NAME} SHARED ${mraa_SRC} )
Thank you
cmake_minimum_required(VERSION 2.8)
MESSAGE( STATUS "Starting build process")
SET( CMAKE_VERBOSE_MAKEFILE on )
if (CMAKE_BUILD_TYPE EQUAL "Debug")
MESSAGE(STATUS "Building in debug mode")
elseif (CMAKE_BUILD_TYPE EQUAL "Release")
MESSAGE(STATUS "Building in release mode")
endif()
SET(PROJECT_NAME "TestProject")
SET(APPLICATION_NAME "TestApplication")
SET(SAFE_STRING_LIBRARY "SafeString")
SET(APPLICATION_LIBRARY "Applibrary")
PROJECT( ${PROJECT_NAME} )
MESSAGE( STATUS "PROJECT: " ${PROJECT_NAME} )
SET(WRSDK_PATH "$ENV{WINDRIVER_SDK_DIR}")
IF (WRSDK_PATH)
else()
SET(WRSDK_PATH /opt/windriver/wrlinux/5.0-intel-quark/)
endif()
SET(APPLIBRARY_NAME ${APPLICATION_LIBRARY} )
SET(SAFE_STRING_LIBRARY_NAME ${SAFE_STRING_LIBRARY} )
### SAFE STRING ###
add_subdirectory(SafeStringStaticLibrary/safeclib)
file(GLOB safestring_SRC
"SafeStringStaticLibrary/safeclib/*.c"
)
include_directories( "${PROJECT_SOURCE_DIR}/SafeStringStaticLibrary /safeclib" )
add_library( ${SAFE_STRING_LIBRARY_NAME} SHARED ${safestring_SRC} )
include(ExternalProject)
ExternalProject_Add(mraa
GIT_REPOSITORY https://github.com/intel-iot-devkit/mraa.git
GIT_TAG v0.8.0
UPDATE_COMMAND ""
INSTALL_COMMAND "" )
file(GLOB app_SRC
"classes/*.cpp"
"Logger.cpp"
"sqlite3.c"
"shell.c"
)
add_library( ${APPLIBRARY_NAME} SHARED ${app_SRC})
include_directories( "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/SafeStringStaticLibrary/include" )
add_executable( ${APPLICATION_NAME} ${APPLICATION_NAME}.cpp
include_directories( "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/SafeStringStaticLibrary/include" "${CMAKE_SOURCE_DIR}/classes")
TARGET_LINK_LIBRARIES( ${APPLICATION_NAME} ${APPLIBRARY_NAME} ${SAFE_STRING_LIBRARY_NAME} -lrt -lpthread -lgcov -ldl)
The simplest way for build your project alongside with 3d party project is add_subdirectory() that subproject. Approach below implies that you (manually) download(git clone) sources of mraa project into mraa-lib subdirectory of your project's sources.
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
MESSAGE( STATUS "Starting build process")
# Configure subproject before definition of variables for main project.
#
# Subproject defines *mraa* library target.
add_subdirectory(mraa-lib)
# Before installation, public mraa headers are contained under *api* subdirectory.
include_directories(mraa-lib/api)
... # create executable ${APPLICATION_NAME}
# Linking with mraa library is straightforward.
target_link_libraries(${APPLICATION_NAME} mraa)
That way mraa subproject will be configured, built and installed alongside with your project. So, if you cross-compile your project(using toolchain file, or inside IDE), the subproject will also be cross-compiled.

SVG icons dont show up in Qt5

I am using SVG icons in my application from the ressource file, but when I run the app the icons are just not displayed. Using jpg icons in the same way works pretty fine.
Problem
Since Qt5.1 the framework has been modularized.
Most likely you are missing the svg module. The application will still compile without complaining.
Solution
Make sure the SVG module is installed on your system and linked (with qmake (Howto), cmake (Howto) or plain make). If it was linked successfully QImageReader::supportedImageFormats() will list SVG.
If you're using cmake, you need something like this to link Svg Qt libraries.
find_package(Qt5Svg REQUIRED)
target_link_libraries( ${APP_NAME} Qt5::Svg )
A full example (sorry ManuelSchneid3r) could be the following one.
## application name
set( APP_NAME "myapp" )
## project name
project( ${APP_NAME} )
## require a minimum version of CMake
CMAKE_MINIMUM_REQUIRED ( VERSION 2.6 FATAL_ERROR )
## add definitions, compiler switches, etc.
ADD_DEFINITIONS( -Wall -O2 )
SET( CMAKE_CXX_FLAGS -g )
## include (or not) the full compiler output
SET( CMAKE_VERBOSE_MAKEFILE OFF )
# find Qt
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Svg REQUIRED)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
include_directories(${Qt5Core_INCLUDE_DIRS})
include_directories(${Qt5Gui_INCLUDE_DIRS})
include_directories(${Qt5Svg_INCLUDE_DIRS})
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# The AUTOUIC target property controls whether cmake(1) inspects the
# C++ files in the target to determine if they require uic to be run,
# and to create rules to execute uic at the appropriate time.
set(CMAKE_AUTOUIC ON)
## sources
file( GLOB MAIN_SRC *.cpp )
set( SOURCES ${MAIN_SRC} )
## executable
add_executable( ${APP_NAME} ${SOURCES} )
## link
target_link_libraries( ${APP_NAME} Qt5::Widgets Qt5::Svg )