E
E
Egorithm2020-01-16 12:46:57
Qt
Egorithm, 2020-01-16 12:46:57

How to connect third party library to Qt project via CMake?

Created a project on the CMake system.

I open CMakeLists.txt:
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)

Tell me, please, where and how can I add headers and the library itself?
And is it possible to somehow do without the dll, having the source code?
Maybe you can create a subproject (with your own CMakeLists.txt) and make it compile, link and build into a library directly from Qt? (So ​​that by changing one SHARED command to STATIC, you can change the way the entire main project is built)
I read a bunch of everything on the net, and I just have a mess in my head, I can’t figure out what and how to do =(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2020-01-16
@EgoRusMarch

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 question

Ask a Question

731 491 924 answers to any question