I have started a project with QTCreator and CMake but without adding anything it has a build error:
Running /Users/hectoresteban/Qt/Tools/CMake/CMake.app/Contents/bin/cmake '-GCodeBlocks - Ninja' /Users/hectoresteban/Documents/C++/Qt/trial in /Users/hectoresteban/Documents/C++/Qt/trial/build.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!
See also "/Users/hectoresteban/Documents/C++/Qt/trial/build/CMakeFiles/CMakeOutput.log".
CMake process exited with exit code 1.
Elapsed time: 00:00.
What should I do? I do not want to build it with Ninja but with a normal Unix Makefile but I do not know how to change the build settings
The initial CMakeLists.txt is:
cmake_minimum_required(VERSION 3.5)
project(trial LANGUAGES CXX)
set(ANDROID_NDK_ROOT "/Users/hectoresteban/Documents/C++/Qt/android-ndk-r21d")
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(Qt5 COMPONENTS Core LinguistTools REQUIRED)
set(TS_FILES trial_en_DE.ts)
add_executable(trial
main.cpp
${TS_FILES}
)
target_link_libraries(trial Qt5::Core)
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
Related
I want to implement a Matrix class, and I want to use CUDA to speed up matrix multiplication. But when I try to compile the source files. I meet some problems. I know that I need to use NVCC to compile the *.cu. But I don't know how to write the CMakeLists.txt to compile the *.cu and *.cpp at the same time. I've tried many ways I found on Google, but they all don't work. Here is my current CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(Project_4 LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_BUILD_TYPE RELEASE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build)
find_package(CUDA REQUIRED)
include(FindCUDA)
include_directories(${CUDA_INCLUDE_DIRS})
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_30,code=sm_30)
include_directories(include)
aux_source_directory(src DIR_SRCS)
file(GLOB cu *.cu)
cuda_add_executable(cuda ${DIR_SRCS} ${cu})
add_executable(Project_4 ${DIR_SRCS})
set_target_properties(Project_4 PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
Then when compiling, it will report that CMake Error at cuda_generated_ cuda_helper.cu.o.RELEASE.cmake:282. And if I write CMakeLists.txt in this way:
cmake_minimum_required(VERSION 3.16)
project(Project_4 LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_BUILD_TYPE RELEASE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build)
include_directories(include)
aux_source_directory(src DIR_SRCS)
find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_30,code=sm_30)
add_executable(Project_4 ${DIR_SRCS})
set_target_properties(Project_4 PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
Then it will report error error: expected primary-expression before "<" token at where I call the kernel function.
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this. I will appreciate a lot. Thanks.
I created an example for you. It is not based on your cmake. But it works for me maybe it helps you.
clone repo: git clone -b cmake_cuda_example https://github.com/werto87/durak_computer_controlled_opponent.git
install: conan dependency manager
Install: cuda toolkit
create an empty folder called build inside the "durak_computer_controlled_opponent" folder
go inside this folder and inside the terminal run "conan install .. --build missing"
cmake ..
cmake --build .
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 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.
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.