assimp
assimp copied to clipboard
Bug: Pthreads in Assimp 5.3.0 with vcpkg
Describe the bug
I want to compile a C++ Cmake-project on Windows with emscripten to WebAssembly. I was able to successfully use the Qt 6.6.2 WebAssembly (single-threaded) Kit. Therefore i installed zlib and assimp via vcpkg and emcmdprompt and also added the toolchain like this:
set(CMAKE_TOOLCHAIN_FILE "C:...\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake") in my Cmake-File right at the top
I also set the VCPKG_CHAINLOAD_TOOLCHAIN_FILE in the initial configuration to the Path
C:\Qt\6.6.2\wasm_singlethread\lib\cmake\Qt6\qt.toolchain.cmake
As soon as I switch from the single-threaded to the multi-threaded kit and change the VCPKG_CHAINLOAD_TOOLCHAIN_FILE accordingly to:
C:\Qt\6.6.2\wasm_multithread\lib\cmake\Qt6\qt.toolchain.cmake
I get the following ninja build error when trying to build
wasm-ld: error: --shared-memory is disallowed by 3DSLoader.cpp.o because it was not compiled with 'atomics' or 'bulk-memory' features
The problem seems to be that the pthreads option does not seem to be enabled on assimp. I tried to check if there was such an option on installation with vcpkg in
\vcpkg\buildtrees\assimp\src\v5.3.1-c1ad782f20.clean\Build.md
I need to mention that I am fairly new to everything on this topic, so feel free to correct me on anything i might have done wrong.
To Reproduce Steps to reproduce the behavior: I have installed the following programs/packages:
- CMake 3.29.0
- Python 3.12.2 (64-bit)
- Qt Creator 12.0.2 with Qt 6.6.2
- emscripten package 3.1.37
- vcpkg for windows
- zlib and assimp via emcmdprompt and wasm32-emscripten.cmake triplet
Then i set the Variables and included assimp in Cmake.
Expected behavior
The Qt 6.6.2 multithreading Kit (with emsdk 3.1.37) compiles the assimp Library with pthreads enabled.
Screenshots
Platform (please complete the following information):
- OS: Windows 10
- Browser Google Chrome Version 123.0.6312.106 (64-Bit)
Additional information This is CmakeLists.txt where i see the most potential in fixing or me being the problem. I one tried ther set(WASM_BUILD_FLAGS) but could not find any proper documentation on using it like here? https://github.com/emscripten-core/emscripten/issues/20129 I also tried the -pthread option on target_compile_options.
set(CMAKE_TOOLCHAIN_FILE "C:\\MA_Clothing_Simulator\\ClothSimulator\\Packages\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake")
cmake_minimum_required(VERSION 3.5)
project(Clothing-Simulator VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(FORCE_EXCEPTION_FLAG "-fwasm-exceptions")
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
find_package(assimp 5.3.0 CONFIG REQUIRED)
set(PROJECT_SOURCES
main.cpp
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(Clothing-Simulator
MANUAL_FINALIZATION
${PROJECT_SOURCES}
model.h model.cpp
view.h view.cpp
controller.h controller.cpp
physicsengine.h physicsengine.cpp
mesh.h mesh.cpp
stb_image.h
ipublisher.h
iobserver.h
mvcfactory.h
)
target_compile_options(Clothing-Simulator PRIVATE -Wextra -Wall -Wsign-conversion -Wfloat-equal -pedantic -Wredundant-decls -Wshadow -Wpointer-arith -O3 ${FORCE_EXCEPTION_FLAG})
set_target_properties(Clothing-Simulator PROPERTIES
${BUNDLE_ID_OPTION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(Clothing-Simulator PRIVATE
Qt6::Core
Qt6::Gui
Qt6::OpenGL
Qt6::OpenGLWidgets
Qt6::Widgets
assimp::assimp
)
# Objects:
set(object_resource_files
"assets/Exocube/Exocube.obj"
)
qt6_add_resources(Clothing-Simulator "objects"
PREFIX
"/assets/"
FILES
${object_resource_files}
)
target_link_options(Clothing-Simulator PUBLIC --embed-file --bind
${CMAKE_SOURCE_DIR}/assets@/
${FORCE_EXCEPTION_FLAG}
)
target_include_directories(Clothing-Simulator PUBLIC ${CMAKE_CURRENT_LIST_DIR})
# Resources:
set(shaders_resource_files
"fshader.glsl"
"vshader.glsl"
)
qt6_add_resources(Clothing-Simulator "shaders"
PREFIX
"/"
FILES
${shaders_resource_files}
)
set(textures_resource_files
"test.png"
"assets/Exocube/texture_diffuse.png"
)
qt6_add_resources(Clothing-Simulator "textures"
PREFIX
"/"
FILES
${textures_resource_files}
)
//Define target properties for Android with Qt 6 as: set_property(TARGET Clothing-Simulator 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(Clothing-Simulator 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(Clothing-Simulator
${PROJECT_SOURCES}
)
endif()
endif()
include(GNUInstallDirs)
install(TARGETS Clothing-Simulator
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(Clothing-Simulator)
endif()