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
QtWS25 Last Chance

Enable multithreading in CMake

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
16 Posts 5 Posters 4.0k 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.
  • I Ivan4587
    21 Feb 2023, 10:08

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

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 21 Feb 2023, 10:13 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 22 Feb 2023, 01:21
    0
    • J jsulm
      21 Feb 2023, 10:13

      @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 22 Feb 2023, 01:21 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.

      J 1 Reply Last reply 22 Feb 2023, 07:22
      0
      • I Ivan4587
        22 Feb 2023, 01:21

        @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.

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 22 Feb 2023, 07:22 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

        J I 2 Replies Last reply 22 Feb 2023, 08:31
        1
        • I Ivan4587
          21 Feb 2023, 09:42

          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 22 Feb 2023, 08:11 last edited by
          #7
          This post is deleted!
          1 Reply Last reply
          0
          • I Ivan4587
            21 Feb 2023, 09:42

            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

            M Offline
            M Offline
            Mesrine
            wrote on 22 Feb 2023, 08:28 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
            • J jsulm
              22 Feb 2023, 07:22

              @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.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 22 Feb 2023, 08:31 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
              • J jsulm
                22 Feb 2023, 07:22

                @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 22 Feb 2023, 08:45 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.

                J M 2 Replies Last reply 22 Feb 2023, 08:46
                0
                • I Ivan4587
                  22 Feb 2023, 08:45

                  @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.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 22 Feb 2023, 08:46 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
                    22 Feb 2023, 08:45

                    @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.

                    M Offline
                    M Offline
                    Mesrine
                    wrote on 22 Feb 2023, 08:59 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 23 Feb 2023, 03:43
                    1
                    • I Ivan4587
                      21 Feb 2023, 09:42

                      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

                      J Offline
                      J Offline
                      JoeCFD
                      wrote on 22 Feb 2023, 14:31 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
                      • M Mesrine
                        22 Feb 2023, 08:59

                        @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 23 Feb 2023, 03:43 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.

                        J 1 Reply Last reply 23 Feb 2023, 06:12
                        0
                        • I Ivan4587
                          23 Feb 2023, 03:43

                          @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.

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 23 Feb 2023, 06:12 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 23 Feb 2023, 08:40
                          1
                          • J jsulm
                            23 Feb 2023, 06:12

                            @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 23 Feb 2023, 08:40 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 23 Feb 2023, 08:41

                            13/16

                            22 Feb 2023, 14:31

                            • Login

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