How to cross Clion, Emscripten and Cmake

In this article, I would like to go through and show the main points of how to configure the CLion IDE to compile a CMake project using Emscripten. When I was doing this crossing, I had to spend a day or two experimenting. And in this post I'm going to put together some "how to" that worked in the end.

Who are all these people?

Emscripten is a set of tools for compiling C ++ code to Asm.js / WebAssembly. Now WebAssembly has already come to the fore,

CMake is a system for generating a script for building a project.

CLion is a development environment for C / C ++ projects originally built around the use of CMake as a build tool. But backing up Emscripten wasn't easy

Prerequisites

The main requirement for everything to start from half a kick is very important to already have installed Python, preferably version 3. Also python must be available from the command line \

Cmake will need at least version  3.13

And of course, don't forget about Git

Setting up Emscripten

Download emsdk. (https://github.com/emscripten-core/emsdk)

And from the command line, we take the following steps:

  1. Downloading the latest version of Emscripten

    ./emsdk install latest
  2. We activate the latest version

    ./emsdk activate latest

. help emsdk , . IDE.

CLion

, . File -> Settings. Build, Execution, Deployment -> Toolchains.

CLion Windows, MSYS2 ( MinGW ). gcc ++ header' .

Linux , Toolchain Windows:

+ MinGW.

Environment MSYS2. MSYS2 e:\msys64

CMake (, CLion CMake ).

! C Compiler C++ Compiler .bat . Linux .bat . , Emscripten python , shell python .

CMake. target :

Toolchains toolchain

: CMake Options -DCMAKE_TOOLCHAIN_FILE= emsdk Emscripten.cmake.

Emscripten.cmake C Compiler C++ Compiler - .

CMake.

. Build->Build Project. , .

  1. , , .js

    set(CMAKE_EXECUTABLE_SUFFIX .js)
  2. Emscripten . , emcc .js . , 1 ,



    , linker', . :

    target_link_options(project PUBLIC "SHELL: --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/prejs.js --js-library ${CMAKE_CURRENT_SOURCE_DIR}/jsLib.js")
    target_link_options(project PUBLIC "SHELL: -s USE_GLFW=3 --preload-file glsl -s ALLOW_MEMORY_GROWTH=1")

    target_link_options Cmake . --preload-file , glsl , bundle'. .

  3. , . emscripten .js nodejs. .js nodejs :



    target_link_options(glslangValidator PUBLIC -s NODERAWFS=1)

, CLion Emscripten.








All Articles