emsdkHack.cmake 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #[=======================================================================[.rst:
  2. emsdkHack
  3. ---------
  4. The Emscripten platform doesn't support the use of shared libraries as known by cmake.
  5. * https://github.com/emscripten-core/emscripten/issues/15276
  6. * https://github.com/emscripten-core/emscripten/issues/17804
  7. This workaround only works due to the way the cmake scripts are loaded.
  8. Prior to the use of ``project( ... )`` directive we need to set
  9. ``CMAKE_PROJECT_INCLUDE=cmake/emscripten.cmake``.
  10. This file will be loaded after the toolchain overriding the settings that
  11. prevent shared library building.
  12. CMAKE_PROJECT_INCLUDE was Added in version 3.15.
  13. ``CMAKE_PROJECT_<projectName>_INCLUDE`` was Added in version 3.17:
  14. More information on cmake's `code injection`_
  15. .. _code injection:https://cmake.org/cmake/help/latest/command/project.html#code-injection
  16. Overwrite Shared Library Properties to allow shared libs to be generated.
  17. ]=======================================================================]
  18. if( EMSCRIPTEN )
  19. set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
  20. set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-sSIDE_MODULE=1")
  21. set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-sSIDE_MODULE=1")
  22. set(CMAKE_SHARED_LIBRARY_SUFFIX) # remove the suffix from the shared lib
  23. set(CMAKE_STRIP FALSE) # used by default in pybind11 on .so modules
  24. # The Emscripten toolchain sets the default value for EMSCRIPTEN_SYSTEM_PROCESSOR to x86
  25. # and CMAKE_SYSTEM_PROCESSOR to this value. I don't want that.
  26. set(CMAKE_SYSTEM_PROCESSOR "wasm32" )
  27. # the above prevents the need for logic like:
  28. #if( ${CMAKE_SYSTEM_NAME} STREQUAL Emscripten )
  29. # set( SYSTEM_ARCH wasm32 )
  30. #endif ()
  31. endif ()