CMake: link to a library related to Qt5
I have a library that uses Qt5. I create it using this CMakeLists.txt file:
cmake_minimum_required (VERSION 3.0)
project (testLib LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 REQUIRED Widgets)
add_library(testLib SHARED
src/TestClass.cpp
src/TestClass.h
)
target_include_directories(testLib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_link_libraries(testLib PUBLIC Qt5::Widgets)
export(TARGETS testLib FILE testLib-exports.cmake)
Now I am trying to link the executable with this library in the build path. This is what I have tried so far:
cmake_minimum_required (VERSION 3.0)
project(TestProject)
add_executable(myexec src/main.cpp )
include(/path/to/testLib-exports.cmake)
target_link_libraries(myexec testLib)
I am getting this error:
Target "myexec" links to target "Qt5 :: Widgets", but the target was not found. Perhaps the find_package () call of the target is missing for IMPORTED, or the ALIAS target is missing?
I don't want to explicitly use find_package()
cmake in myexec file, but I want it to be transitive. How am I supposed to reference testLib? If the answer is not in the build path, that's ok.
EDIT: I changed the export line to:
export(TARGETS testLib FILE testLib-exports.cmake EXPORT_LINK_INTERFACE_LIBRARIES)
This is similar to what I need, but the generated files with and without EXPORT_LINK_INTERFACE_LIBRARIES are identical. Both if they say
This file is independent of other imported targets that have been exported from the same project, but in a separate export set.
As I understand it, it should be using the target property of LINK_INTERFACE_LIBRARIES
target_ListLib, but I noticed that it is NOTFOUND
. maybe this is the problem? However INTERFACE_LINK_LIBRARIES
has Qt5 :: Widgets.
source to share
No one has answered this question yet
See similar questions:
or similar: