Enable multithreading in CMake
-
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 -
@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)
-
@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. -
@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)
-
@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.
-
@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.
-
@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.
-