0

So(rry), I have a source code of qt that I built on windows with msvc and it was installed at some %QT_INSTALL_DIR%. Now I want to link this library with cmake to my project at some %PROJECT_DIR%. My CMakeLists.txt looks as following:

cmake_minimum_required(VERSION 3.5)

project(project VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})
include_directories(./parser/)
add_subdirectory(parser)
set(PROJECT_SOURCES
        main.cpp
        window.cpp
        window.h
        window.ui
        controller.cpp
        controller.h
        siteinfo.h
        siteinfo.cpp
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(project
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET project APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(project SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(project
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(project PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${CURL_LIBRARIES})

set_target_properties(project PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(project)
endif()

So as I presume, I need to add set(CMAKE_PREFIX_PATH %SOME_PATH%) to this CMakeLists.txt so cmake could know where to look for configuration.cmake files. But I question this %SOME_PATH%. Could someone tell me what this path should be or am I completely wrong with my assumptions?

DLWHI
  • 71
  • 5
  • 3
    This might help: [How to statically link Qt libraries?](https://stackoverflow.com/questions/50154001/how-to-statically-link-qt-libraries) – Jesper Juhl May 11 '23 at 13:46
  • 1
    My advice is instead of trying to build statically create an installer for your application like most other commercial applications do. It's pretty easy create an NCIS or WIX installer with CMake. I have done so for my Qt based applications since 2008 at work. – drescherjm May 11 '23 at 13:49
  • It needs to be able to find qmake https://cmake.org/cmake/help/latest/module/FindQt4.html#module:FindQt4 – Alan Birtles May 11 '23 at 14:09
  • I understand that you have bought commercial license. This is only case when you have legal right to link Qt statically. – Marek R May 11 '23 at 14:18
  • @MarekR no you can statically link Qt in open source or non-distributed applications under the LGPL licence – Alan Birtles May 11 '23 at 14:25
  • @MarekR GPL and LGPL let you do pretty much anything, including static linking, as long as you do what the license requires. With LGPL, you can even not LGPL your own code, if you distribute object files and allow re-linking with custom LGPL Qt libs (but it is a hassle and really not worth it compared to just using dynamic libs). – hyde May 11 '23 at 18:02

0 Answers0