Context
Using the below CMakeLists.txt
, it build the Qt
test project without issues ONLY when included to a parent project like:
RootProject
+--CMakeLists.txt // Parent CMake
+--TestQt
+--testwidget.cpp
+--testwidget.hpp // Empty class, just extends QWidget
+--CMakeLists.txt // My Test Project CMake
Parent Project just contain:
add_subdirectory( "TestQt" )
As soon as I try to build the "TestQt" project standalone, it just return an error like:
CMake Error at CMakeLists.txt:16 (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.
CMAKE_PREFIX_PATH
is empty in both cases.
Currently using Debian with a slightly old CMAKE 3.0.2
Question
What is wrong/ missing?
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets REQUIRED)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
# Project name
project ( "TestQt" )
add_executable( UnitTest_TestQt UnitTest.cpp testwidget.cpp)
target_link_libraries(UnitTest_TestQt Qt5::Widgets)
CMAKE_PREFIX_PATH
andQt5Widgets_DIR
– Amadeus/usr/lib/x86_64-linux-gnu/cmake/Qt5Widgets
when in subproject, butQt5Widgets_DIR-NOTFOUND
in standalone. Do you know why is not set in standalone? – Adrian Maireproject ( "TestQt" )
inside another project. – VelkanCMakeLists.txt
. If it's not there, it will be added implicitly. Stuff breaks if you callproject()
in otherCMakeLists.txt
somewhere down the directory hierarchy. – Velkan