Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. qt6 and cmake equivalent of qt5 and qmake
Forum Updated to NodeBB v4.3 + New Features

qt6 and cmake equivalent of qt5 and qmake

Scheduled Pinned Locked Moved Solved Qt 6
3 Posts 2 Posters 870 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • posktomtenP Offline
    posktomtenP Offline
    posktomten
    wrote on last edited by
    #1

    Hey!
    I have made three libraries in Qt that can be used in different programs. One is to check for updates, one is able to update (Linux only) and the third is a homemade variant of QFontDialog.

    With qmake in Qt 5 it worked like this to include the libraries (*.pro file)
    unix:LIBS += "-L../lib"
    unix:LIBS += -lcheckupdate
    unix:LIBS += -lupdateappimage
    unix:LIBS += -lselectfont

    win32:CONFIG(release, debug|release): LIBS += -L../lib/ -lcheckupdate # Release
    else:win32:CONFIG(debug, debug|release): LIBS += -L../lib/ -lcheckupdated # Debug
    win32:CONFIG(release, debug|release): LIBS += -L../lib/ -lselectfont # Release
    else:win32:CONFIG(debug, debug|release): LIBS += -L../lib/ -lselectfont # Debug

    INCLUDEPATH += "../include"
    DEPENDPATH += "../include"

    How to do with cmake? Have tried with Qt Creator. But the option to add a library is disabled.

    posktomten

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      target_link_libraries and target_include_directories is what you are looking for but, since you are the owner of the libraries, the better practice is to export the targets of your library so that users of your library can consume it easily with CMake.

      If you take this example and run (I assume linux here)

      mkdir build
      cd build
      cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=RELEASE  ../
      cmake --build . --target install
      

      Then you can use the library in your application with the familiar find_package(MyLib)/target_link_libraries(MyApp MyLib::MyLib)

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • posktomtenP Offline
        posktomtenP Offline
        posktomten
        wrote on last edited by
        #3

        Thanks so much!
        I have downloaded your example and started exploring how it works. I made it work by starting from a "CMakeLists.txt" created by Qt Creator. It seems to work. But I need to learn cmake, so I thank you for your example. After 30 years of programming with qmake, it takes some time to learn new things.

        Create a *.so or a *.dll file
        Qt5
            else()
                 # add_executable(myProgram
        		 # Changed to
                 add_library(myLib SHARED
                    ${PROJECT_SOURCES}
                )
        		
        Qt6
        
        if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
             # qt_add_executable(myProgram
        	 # Changed to
             add_library(myLib SHARED
                MANUAL_FINALIZATION
                ${PROJECT_SOURCES}	
        		
        		
        Use the library file (Only tested with Qt6 and Windows)
        
        target_link_libraries (myTestProgram PRIVATE $ {PROJECT_SOURCE_DIR} /lib/myLib.dll)
        
        
        Or include the library file in a project that uses qmake
        
        win32:CONFIG(release, debug|release): LIBS += -L../lib/ -ldownloadunpack  # Release
        else:win32:CONFIG(debug, debug|release): LIBS += -L../lib/ -ldownloadunpackd # Debug
        unix:LIBS += -ldownloadunpack
        

        posktomten

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved