I am trying to integrate my QT project to my CLION project.
In this case I am having problems with the CMAKE and QT integration.
The content of my CmakeList.txt is:
cmake_minimum_required(VERSION 3.12)
project(BD2_PROYECTO_1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/Users/jonathanprieto/Qt5.13.0/5.13.0/")
find_package(Qt5Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
add_executable(BD2_PROYECTO_1 parser.cpp parser.h main.cpp statichashing.cpp statichashing.h randomfile.cpp randomfile.h record.cpp record.h transactions.cpp transactions.h ui/input.cpp ui/input.h ui/ui_dialog.h ui/mainwindow.h ui/mainwindow.cpp ui/mainwindow.ui ui/ui_input.ui ui/input.h ui/dialog.ui)
target_link_libraries(helloworld Qt5::Widgets)
But I am getting the following error:
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets" with
any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
"Qt5Widgets_DIR" to a directory containing one of the above files. If
"Qt5Widgets" provides a separate development package or SDK, be sure it has
been installed.
Could someone help me?
Thank you
after some tries, I found the solution to my problem.
So I am posting my CMakeList.txt code in case you have the same problem.
cmake_minimum_required(VERSION 3.12)
project(BD2_PROYECTO_1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/Users/jonathanprieto/Qt5.13.0/5.13.0/clang_64/lib/cmake")
find_package(Qt5 COMPONENTS Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
add_executable(BD2_PROYECTO_1 parser.cpp parser.h main.cpp statichashing.cpp statichashing.h randomfile.cpp randomfile.h record.cpp record.h transactions.cpp transactions.h ui/input.cpp ui/input.h ui/ui_dialog.h ui/mainwindow.h ui/mainwindow.cpp ui/mainwindow.ui ui/ui_input.ui ui/input.h ui/dialog.ui ui/input.ui)
target_link_libraries(BD2_PROYECTO_1 Qt5::Widgets)
I hope this will helpful for you.
Related
I am trying to configure my project via the Cmake GUI. Sadly CMake throws me this error:
CMake Error at CMakeLists.txt:11 (find_package):
Could not find a configuration file for package "Qt6" that is compatible
with requested version "".
The following configuration files were considered but not accepted:
C:/Qt/6.3.1/mingw_64/lib/cmake/Qt6/Qt6Config.cmake, version: 6.3.1 (64bit)
Any hints why this is happening? I already checked if maybe my config file does not exist in C:/Qt/6.3.1/mingw_64/lib/cmake/Qt6/Qt6Config.cmake but the file exists.
Here is also my CMakeLists.txt:
cmake_minimum_required(VERSION 3.22)
project(environment_PO)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_PREFIX_PATH "C:/Qt/6.3.1/mingw_64")
find_package(Qt6 COMPONENTS
Core
Gui
Widgets
REQUIRED)
add_executable(environment_PO main.cpp mainWindow.h mainWindow.cpp datetime.h datetime.cpp generateSubjectCode.h generateSubjectCode.cpp loadSettings.h loadSettings.cpp saveSettings.h saveSettings.cpp)
target_link_libraries(environment_PO
Qt6::Core
Qt6::Gui
Qt6::Widgets
)
I have a CMake project that works pretty good in Linux, but it doesn't under Windows.
The first issue comes by final linking:
[100%] Linking CXX shared library libProjlib.dll
CMakeFiles\Projlib.dir/objects.a(configserver.cpp.obj): In function `ConfigServer::findAdapter(unsigned long*)':
C:/Users/jose/Documents/git-Projects/Proj/Projlib/configserver.cpp:859: undefined reference to `GetIpAddrTable'
Error 1
findAdapter belongs to C:\Qt\Tools\mingw810_64\x86_64-w64-mingw32\include\iphlpapi.h, but doesn't link automatic
My project is missconfigured, I think. I would like to select the MinGW compiler, automatic through CMakeLists.txt (For now, I configure the compiler means cmake-gui.exe ..), and naturally fix the issue, but I don't know how. (Google didn't gave me a solution)
Please, any help or suggestion, link.. etc. will be wellcomed.
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(CMAKE_PROJECT_NAME "testProject")
project(${CMAKE_PROJECT_NAME})
set(CMAKE_BUILD_TYPE Debug)
if("Windows" STREQUAL "${CMAKE_SYSTEM_NAME}")
message(STATUS "_______________________________________Compiling on Windows")
elseif("Linux" STREQUAL "${CMAKE_SYSTEM_NAME}")
message(STATUS "_______________________________________Compiling on GNU/Linux :-)")
endif()
set(CMAKE_BUILD_PARALLEL_LEVEL 8)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#list(APPEND CMAKE_PREFIX_PATH "/home/enigma/Qt/5.15.2/gcc_64") #linux
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\Tools\\mingw810_64")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
message(STATUS "___________________________________________________${CMAKE_BUILD_TYPE}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(binPath "binDebugProj")
elseif()
set(binPath "binProj")
endif()
set(TMP_BUILD "tmpBuild")
set(Proj_LIB "Projlib")
add_subdirectory(${Proj_LIB} "${CMAKE_SOURCE_DIR}/../${binPath}/${TMP_BUILD}/${Proj_LIB}")
include_directories(${Proj_LIB})
The Solution is:
target_link_libraries(${CARDEA_LIB} PUBLIC Qt5::Core Qt5::Network iphlpapi)
At the end did work. (I was savin in anoter CMakeLists.txt AGGHH, too musch hours today)
I am a student writing a project. I have created a program (here's the link to SVN: https://mysvn.ru/Ilya_Antonov/antonov_sem_prj). I use CMake to build it and generate the .sln project. But when run it in Visual Studio, there are some errors: the compiler can't open the files "drumswindow.h" and "mainwindow.h" (fatal error C1083). Please, take a look at my CMakeLists.txt:
cmake_minimum_required(VERSION 3.1.0)
project(MusicSimulator VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
find_package(Qt5 COMPONENTS Gui REQUIRED)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Qt5 COMPONENTS Multimedia REQUIRED)
add_executable(MusicSimulator
mainwindow.ui
mainwindow.cpp
mainwindow.h
main.cpp
drumswindow.ui
drumswindow.cpp
drumswindow.h
keyswindow.ui
keyswindow.cpp
keyswindow.h
images.qrc
drumres.qrc
keysres2.qrc
keysres3.qrc
keysres4.qrc
keysres5.qrc
keysres6.qrc
)
target_link_libraries(MusicSimulator Qt5::Widgets Qt5::Gui Qt5::Core Qt5::Multimedia)
What have I done wrong here?
You don't include the current source dir and therefore the compiler doesn't find it. Either add the current source dir or use the correct include statements (#include "keyswindow.h" for example)
I want to build a project which needs FLANN. When executing cmake, it shows
-- Checking for module 'flann'
-- Found flann, version 1.9.1
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
But I got ld: library not found for -lflann when executing make.
I'm using cmake 3.15.1 on MacOS.
The CMakeLists.txt shows below.
cmake_minimum_required(VERSION 2.8.11)
project(pcl_visualizer)
# init_qt: Let's do the CMake job for us
set(CMAKE_AUTOMOC ON) # For meta object compiler
set(CMAKE_AUTORCC ON) # Resource files
set(CMAKE_AUTOUIC ON) # UI files
set(Qt5_DIR "/usr/local/Cellar/qt/5.13.0/lib/cmake/Qt5")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find the QtWidgets library
find_package(Qt5 REQUIRED Widgets)
find_package(VTK REQUIRED)
find_package(PCL 1.7.1 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
add_definitions(${PCL_DEFINITIONS})
set(project_SOURCES main.cpp pclviewer.cpp)
add_executable(${PROJECT_NAME} ${project_SOURCES})
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES} Qt5::Widgets)
I want to make a Qt Quick project using CMake with compiled qml files. I put my QML files into a separate qrc/rcc file in a cmake projekt:
qt5_add_binary_resources("res" "qml.qrc" DESTINATION "qml.rcc")
This works fine so far. Now I wanted to compile them. According to the documentation I only need to change
qt5_add_resources(RESOURCES example.qrc)
add_executable(myapp ${SRC_LIST} ${RESOURCES)
to
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES example.qrc)
add_executable(myapp ${SRC_LIST} ${RESOURCES)
in a project. So I changed my CMakeLists.txt to
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources("QML_RESOURCE" "qml.qrc")
qt5_add_binary_resources("res" ${QML_RESOURCE} DESTINATION "qml.rcc")
But now I get
FAILED: qml.rcc cmd.exe /C "cd /D "D:\buildPath" && C:\Qt\5.12.3\msvc2017_64\bin\rcc.exe --binary --name res --output qml.rcc "D:/buildPath/main_qml.cpp" "D:/buildPath/qmlcache_loader.cpp""
RCC Parse Error: 'D:/buildPath/main_qml.cpp' Line: 1 Column: 1 [Start tag expected.] [2/4 30.3/sec] Automatic MOC for target PROJECT_NAME ninja: build stopped: subcommand failed.
17:10:39: The process "C:\Program Files\CMake\bin\cmake.exe" exited with code 1. Error while building/deploying project PROJECT_NAME (kit: Desktop Qt 5.12.3 MSVC2017 64bit) When executing step "Build with CMake"
There isn't much information about Qt and CMake, so I don't know what to do about this. I hope someone can give me some advice.
The full working CMakeLists is
cmake_minimum_required(VERSION 3.1)
project(QtQuickCompiler LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES qml.qrc)
add_executable(${PROJECT_NAME} "main.cpp" ${RESOURCES})
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick)
The full not working file is
cmake_minimum_required(VERSION 3.1)
project(QtQuickCompiler LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES qml.qrc)
qt5_add_binary_resources(qml ${RESOURCES} DESTINATION "qml.rcc")
add_executable(${PROJECT_NAME} "main.cpp")
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick)
This was created using the template projects provided by QtCreator.