Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Enable multithreading in CMake
Forum Updated to NodeBB v4.3 + New Features

Enable multithreading in CMake

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
16 Posts 5 Posters 4.2k Views
  • 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.
  • JonBJ JonB

    @Ivan4587 said in Enable multithreading in CMake:

    by building Qt from source and configuring with the "-feature-thread" flag".

    That argument is to be used with the Qt configure tool.

    I Offline
    I Offline
    Ivan4587
    wrote on last edited by
    #3

    @JonB understood, so i'm looking for the way in CMake.

    jsulmJ 1 Reply Last reply
    0
    • I Ivan4587

      @JonB understood, so i'm looking for the way in CMake.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #4

      @Ivan4587 Do you use make, nmake or ninja?
      ninja enables parallel build (processes by the way, not threads).
      If you use make/nmake then use -j NUMBER_OF_PARALLEL_BUILDS command, like:

      make -j 16
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Ivan4587 Do you use make, nmake or ninja?
        ninja enables parallel build (processes by the way, not threads).
        If you use make/nmake then use -j NUMBER_OF_PARALLEL_BUILDS command, like:

        make -j 16
        
        I Offline
        I Offline
        Ivan4587
        wrote on last edited by
        #5

        @jsulm i'm using QT Creator with CMake file. So i need to add some parameters in the CMakeLists.txt file to enable multithreading for QT on WebAssembly.

        jsulmJ 1 Reply Last reply
        0
        • I Ivan4587

          @jsulm i'm using QT Creator with CMake file. So i need to add some parameters in the CMakeLists.txt file to enable multithreading for QT on WebAssembly.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #6

          @Ivan4587 No, you do not specify the number of parallel builds inside CMakeLists.txt! This should be decided on each machine and/or by each developer depending on available ressources.
          Simply specify the parameter in QtCreator: go to Projects (on the left side), then "Build Steps" and edit "Make" entry.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          jsulmJ I 2 Replies Last reply
          1
          • I Ivan4587

            Hello everyone,

            i need to build my project with QT for WebAssembly using CMake. But i cannot find the way to enable multithreading.
            What i found is the description with that, "Qt on WebAssembly supports multithreading, however support is disabled by default in order to be compatible with as many browsers as possible. Thread support can be enabled by building Qt from source and configuring with the "-feature-thread" flag".
            But how could i config it in my CMake file? Any suggestion? Thanks a lot!

            Best regards,
            Ivan

            I Offline
            I Offline
            Ivan4587
            wrote on last edited by
            #7
            This post is deleted!
            1 Reply Last reply
            0
            • I Ivan4587

              Hello everyone,

              i need to build my project with QT for WebAssembly using CMake. But i cannot find the way to enable multithreading.
              What i found is the description with that, "Qt on WebAssembly supports multithreading, however support is disabled by default in order to be compatible with as many browsers as possible. Thread support can be enabled by building Qt from source and configuring with the "-feature-thread" flag".
              But how could i config it in my CMake file? Any suggestion? Thanks a lot!

              Best regards,
              Ivan

              MesrineM Offline
              MesrineM Offline
              Mesrine
              wrote on last edited by
              #8

              @Ivan4587
              First you need to compile Qt from source enabling multithreading as you said.

              Then you need to enable emscripten code generation for pthreads in your Cmake project like this.

              I normally put this on my root CMakeLists.txt

              if(EMSCRIPTEN)
              target_compile_options(target PRIVATE -pthread)
              target_link_options(target PRIVATE -pthread -sPTHREAD_POOL_SIZE=8)
              endif()
              

              And this work for firefox, but not for Chrome(I think)

              1 Reply Last reply
              1
              • jsulmJ jsulm

                @Ivan4587 No, you do not specify the number of parallel builds inside CMakeLists.txt! This should be decided on each machine and/or by each developer depending on available ressources.
                Simply specify the parameter in QtCreator: go to Projects (on the left side), then "Build Steps" and edit "Make" entry.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @jsulm Looks like I completelly misunderstood the question. Ignore my posts in this thread :-)

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Ivan4587 No, you do not specify the number of parallel builds inside CMakeLists.txt! This should be decided on each machine and/or by each developer depending on available ressources.
                  Simply specify the parameter in QtCreator: go to Projects (on the left side), then "Build Steps" and edit "Make" entry.

                  I Offline
                  I Offline
                  Ivan4587
                  wrote on last edited by
                  #10

                  @jsulm Maybe i didn't describe correctly... I'm not looking for the way to build it parallel, but the way to enable multithreading when i use the WebAssembly.

                  jsulmJ MesrineM 2 Replies Last reply
                  0
                  • I Ivan4587

                    @jsulm Maybe i didn't describe correctly... I'm not looking for the way to build it parallel, but the way to enable multithreading when i use the WebAssembly.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @Ivan4587 No, your description is OK, I just was too fast while reading :-)

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • I Ivan4587

                      @jsulm Maybe i didn't describe correctly... I'm not looking for the way to build it parallel, but the way to enable multithreading when i use the WebAssembly.

                      MesrineM Offline
                      MesrineM Offline
                      Mesrine
                      wrote on last edited by
                      #12

                      @Ivan4587 But it is not clear if you have manage to compile qt from source enabling multithreading.

                      In that case my previous answer will help you after you do that.

                      In your cmake project you need to link to the qt wasm libraries compiled with multithreading support(by using the configure flag). You should not add multi threading support to Qt libraries from your CMake project.

                      I 1 Reply Last reply
                      1
                      • I Ivan4587

                        Hello everyone,

                        i need to build my project with QT for WebAssembly using CMake. But i cannot find the way to enable multithreading.
                        What i found is the description with that, "Qt on WebAssembly supports multithreading, however support is disabled by default in order to be compatible with as many browsers as possible. Thread support can be enabled by building Qt from source and configuring with the "-feature-thread" flag".
                        But how could i config it in my CMake file? Any suggestion? Thanks a lot!

                        Best regards,
                        Ivan

                        JoeCFDJ Offline
                        JoeCFDJ Offline
                        JoeCFD
                        wrote on last edited by
                        #13

                        @Ivan4587 said in Enable multithreading in CMake:

                        -feature-thread

                        if you have the pro file and are able to build it with the flag, you can find out where it is added in Makefile. From there, you will be able to figure out where to add it in the cmake file.

                        1 Reply Last reply
                        0
                        • MesrineM Mesrine

                          @Ivan4587 But it is not clear if you have manage to compile qt from source enabling multithreading.

                          In that case my previous answer will help you after you do that.

                          In your cmake project you need to link to the qt wasm libraries compiled with multithreading support(by using the configure flag). You should not add multi threading support to Qt libraries from your CMake project.

                          I Offline
                          I Offline
                          Ivan4587
                          wrote on last edited by
                          #14

                          @Mesrine

                          @Mesrine said in Enable multithreading in CMake:

                          But it is not clear if you have manage to compile qt from source enabling multithreading.

                          That's the point. I'm using QT 6, as i known, it is not open source anymore.

                          jsulmJ 1 Reply Last reply
                          0
                          • I Ivan4587

                            @Mesrine

                            @Mesrine said in Enable multithreading in CMake:

                            But it is not clear if you have manage to compile qt from source enabling multithreading.

                            That's the point. I'm using QT 6, as i known, it is not open source anymore.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #15

                            @Ivan4587 said in Enable multithreading in CMake:

                            as i known, it is not open source anymore

                            It is open source. You can get Qt6 source code in exact same way as Qt5.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            I 1 Reply Last reply
                            1
                            • jsulmJ jsulm

                              @Ivan4587 said in Enable multithreading in CMake:

                              as i known, it is not open source anymore

                              It is open source. You can get Qt6 source code in exact same way as Qt5.

                              I Offline
                              I Offline
                              Ivan4587
                              wrote on last edited by
                              #16

                              @jsulm ok... i'll have a try.

                              1 Reply Last reply
                              0
                              • I Ivan4587 has marked this topic as solved on

                              • Login

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