How to Find the Qt5 Cmake Module on Windows

How to find the Qt5 CMake module on Windows

After the lines

cmake_minimum_required(VERSION 2.8.9)

project(testproject)

add

set (CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.0.1\\5.0.1\\msvc2010\\")

This solves the problem.

How to set qt5 path with cmake find_package on Windows?

My workaround was to put desired QT to the top of PATH variable. It has to be in PATH if you want CMAKE to find it.

cmake does not find qt 5.1.1

You need to set the CMAKE_PREFIX_PATH to the Qt installation.

See http://doc.qt.io/qt-5/cmake-manual.html

How to list all CMake components of Qt5?

Component names are interpreted by the package (here: Qt5), not CMake itself (see). So their naming scheme is package specific. In the case of Qt5, ${QT5_DIR}/lib/cmake/Qt5/Qt5Config.cmake shows that their names are the same as the CMake module names when omitting the Qt5 prefix:

foreach(module ${Qt5_FIND_COMPONENTS})
find_package(Qt5${module} ... )
...
endforeach()

So to list all component names, just list the CMake modules (as derived from the corresponding ModuleNameConfig.cmake filenames) and omit the Qt5 prefix. Under Linux, this does the job and also sorts the output into columns:

find /path/to/your/qt5/ -name "*Config.cmake" |
sed 's/^.*\/Qt5//; s/Config.cmake$//; /^\s*$/d' |
sort | pr -t -3

As of Qt 5.12, this lists the COMPONENT names as follows:

3DAnimation             Help                    QuickWidgets
3DCore LinguistTools RemoteObjects
3DExtras Location RepParser
3DInput Multimedia Scxml
3DLogic MultimediaWidgets Sensors
3DQuick Network SerialPort
3DQuickAnimation Nfc Sql
3DQuickExtras OpenGL Svg
3DQuickInput OpenGLExtensions Test
3DQuickRender Positioning TextToSpeech
3DQuickScene2D PositioningQuick UiPlugin
3DRender PrintSupport UiTools
AndroidExtras Qml WebChannel
Bluetooth Quick WebSockets
Concurrent QuickCompiler WebView
Core QuickControls2 Widgets
Gamepad QuickTemplates2 Xml
Gui QuickTest XmlPatterns

How can I package a Qt program built with CMake on Windows?

If you already have in your ${CMAKE_SOURCE_DIR}/cmake/Modules/ directory the file Windeployqt.cmake, you may use it like this:

install(TARGETS perfecttin-gui 
DESTINATION "${INSTALL_BIN_PATH}"
)

if(WIN32)
include(Windeployqt)
windeployqt(nitroshare-cli ${INSTALL_BIN_PATH})
endif()

Here is the full example.

Building vtk with QT5 windows 8

Did you do step 3 and 4 here? : Combining Qt 5.4.1 with vtk 6.2.0 (using CMake GUI 3.2.1) on windows

I'm guessing you didn't change VTK_QT_VERSION to 5

Unknown CMake Qt5 command

To use Qt5 in CMakeLists.txt you should use (a combination of) those functions:

In top level CMakeLists.txt

#### Qt5
find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
find_package( Qt5OpenGL REQUIRED )
find_package( Qt5Multimedia REQUIRED )
find_package( Qt5WebKitWidgets REQUIRED )
find_package( Qt5Xml REQUIRED )
set( CMAKE_AUTOMOC ON ) # to automoc remove the need to wrap by hand

EDIT:
The Qt5 cmake modules are provided by Qt5 itself, so you need to tell cmake where qt can be found. See the Qt5 CMake doc about that.

How to modify CMakelists for Qt5 from Windows to Linux?

finally solved version:

cmake_minimum_required (VERSION 3.5)

set(PRROJ_NAME QtGL_test)
project (${PRROJ_NAME})

set(HEADERS ${HEADERS} openglwindow.h )
set(SOURCES ${SOURCES} main.cpp ${HEADERS})
set(CMAKE_AUTOMOC ON)

add_executable(${PRROJ_NAME} ${SOURCES})
set(PROJ_INCLUDE_DIRS ${PROJ_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})

add_library(openglwindow openglwindow.cpp)
set(PROJ_LIBRARIES ${PROJ_LIBRARIES} openglwindow)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

if(WIN32)
find_path(CMAKE_PREFIX_PATH NAMES lib/cmake/Qt5/Qt5Config.cmake HINTS
"$ENV{Qt5_ROOT}"
)
message("Qt5_ROOT is $ENV{Qt5_ROOT}")
endif()
message("CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)

set(QT_FLAGS "-fPIC")
set(NEED_QT_COMPONENTS QTCORE QTGUI)
message("finding ${NEED_QT_COMPONENTS}")
foreach(COMPONENT Gui Core)
message("find_package(Qt5${COMPONENT})")
find_package("Qt5${COMPONENT}")
message("Qt5${COMPONENT}_FOUND is ${Qt5${COMPONENT}_FOUND}")
if("${Qt5${COMPONENT}_FOUND}")
set(PROJ_INCLUDE_DIRS ${PROJ_INCLUDE_DIRS} "${Qt5${COMPONENT}_INCLUDE_DIRS}")
set(PROJ_LIBRARIES ${PROJ_LIBRARIES} "Qt5::${COMPONENT}")
#Open add_definitions will error
#add_definitions("${Qt5${COMPONENT}_DEFINITIONS}")
qt5_use_modules(${PRROJ_NAME} ${COMPONENT})
endif()
endforeach(COMPONENT )

message("include_directories(${PROJ_INCLUDE_DIRS})")
include_directories(${PROJ_INCLUDE_DIRS})
message("target_link_libraries(${PRROJ_NAME} ${PROJ_LIBRARIES})")
target_link_libraries(${PRROJ_NAME} ${PROJ_LIBRARIES})
set(CMAKE_CXX_STANDARD 14)

if(UNIX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QT_FLAGS} -I/usr/local/include -Wall")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
endif()

CMake configure fails to find Qt5 on Linux

sudo apt-get install qtbase5-dev
sudo apt-get install qtdeclarative5-dev

I installed the 2 gt package and added the add prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR" to a directory containing one of the above files. mentioned in comment above @drescherjm

cmake build normally



Related Topics



Leave a reply



Submit