Reputation: 321
I'm trying to get a cmake project set up on OS X. I've almost got it compiling but I'm having a little trouble with getting Qt5 working.
When I try to compile, I get:
fatal error: 'QtCore/QDir' file not found
fatal error: 'QtCore/QDate' file not found
When I check out my code, the IDE has both QtCore and QtWidgets highlighted in red, indicating that they weren't found.
Do any of you have any idea what I'm missing?
My CMakeLists.txt is as follows:
cmake_minimum_required(VERSION 3.3)
project(miniLogbook)
subdirs(sources headers lib other)
#For a basic project, you should probably only need to edit these variables
#Base QT directory
set(QT_PATH "/Users/rwardrup/Qt")
#Build output path of your QT Creator project
set(QT_BIN "./ml_debug")
#QT Version used, e.g. Probably found in ${QT_PATH}
set(QT_VERSION "5.7")
#Libraries to link to
set(QT_LIBRARIES Qt5::Core Qt5::Widgets Qt5::Gui)
#Libraries required. Probably the same as above minus the '::'. find_package() will be called on these
set(QT_LIBRARIES_REQUIRED Qt5Core Qt5Widgets Qt5Gui)
#################################################################
#Pull needed header files generated by QT first
set(QT_GENERATED qtGenerated)
add_custom_target(${QT_GENERATED})
#Get all header files in the directory
file(GLOB QT_GEN_HEADERS ${QT_BIN}/*.h)
#Copy them to the project dir
foreach(QT_GEN_HEADERS ${QT_GEN_HEADERS})
add_custom_command(TARGET ${QT_GENERATED} PRE_BUILD COMMAND
${CMAKE_COMMAND} -E copy_if_different
${QT_GEN_HEADERS} ${CMAKE_SOURCE_DIR})
endforeach()
#Build tool paths
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
set(CMAKE_AR "/usr/bin/ar")
set(CMAKE_LINKER "/usr/bin/g++")
#find packages
foreach(QT_LIBRARIES_REQUIRED ${QT_LIBRARIES_REQUIRED})
find_package( ${QT_LIBRARIES_REQUIRED} REQUIRED )
endforeach()
file(GLOB QT_CPP_GENERATED ${QT_BIN}/*.cpp)
set(SOURCES sources/main.cpp sources/mainwindow.cpp headers/mainwindow.h ${QT_GEN_HEADERS} ${QT_CPP_GENERATED})
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.59.0 COMPONENTS filesystem)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(miniLogbook ${SOURCES})
add_dependencies(${PROJECT_NAME} ${QT_GENERATED})
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${Boost_LIBRARIES})
endif()
Upvotes: 1
Views: 1593
Reputation: 5800
Your foreach
loops are bugged.
In both cases you are overwriting the list of values to loop over with the first element.
They should read along the following pattern:
foreach(_loop_var ${list_of_values})
# do stuff with ${_loop_var}
endforeach(_loop_var)
I'm sure the problem you are facing is just the symptom of CMake not having searched for all the Qt5 modules you want it to search for. You might want to recheck the CMake cache and log output.
Side note: It is very bad practice to hard code absolute paths to system components into CMake files. That renders CMake (almost) useless. If you don't want to give a lot of command line arguments to CMake to specify specific locations, read about toolchain files.
If this CMakeLists file is an example template from somewhere, I'd recommend not to use that source for CMake related advice.
Upvotes: 1