Answer the question
In order to leave comments, you need to log in
How to connect third party library to Qt project via CMake?
Created a project on the CMake system.
cmake_minimum_required(VERSION 3.5)
project(yfx LANGUAGES CXX)
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_CXXSTANDARD_REQUIRED ON)
find_package(Qt5 COMSHAREDPONENTS Widgets REQUIRED)
if(ANDROID)
add_library(yfx SHARED main.cpp yfx.cpp yfx.h yfx.ui)
else()
add_executable(yfx main.cpp yfx.cpp yfx.h yfx.ui)
endif()
target_link_libraries(yfx PRIVATE Qt5::Widgets)
Answer the question
In order to leave comments, you need to log in
Of course, in target_link_libraries, just add the library name at the end, separated by a space.
But usually find_package/find_library/pkg_check_modules is used to first determine if the library is installed on the system. And in target_link_libraries add variables that are initialized by these functions.
See: https://cmake.org/cmake/help/latest/genindex.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question