Emscripten的CMake项目 [英] CMake project for Emscripten

查看:557
本文介绍了Emscripten的CMake项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想结交CMake和Emscripten朋友。在Emscripten项目网站上没有找到或多或少提供信息的文档,但是它们提供了CMake工具链文件,因此我认为应该可以。
到目前为止,没有高级参数的非常基本的编译效果很好,但是在使用 embind 并预加载文件时遇到了问题。


  1. 链接过程似乎错过了Emscripten二进制文件,并为所有与嵌入相关的函数发出警告,如下所示:警告:未解决的符号:_embind_register_class
  2. 在编译期间不会生成 .data 文件。

  3. li>

我创建了一个简单的示例,其中包含两个目标:一个正常(客户端)和一个手册(手动客户端),它们只是运行我期望运行的emcc: https:/ /github.com/xwaffelx/minimal-cmake-emscripten-project/blob/master/README.md



虽然手动操作有效,但我没有认为这是一种正确的方法... / p>

---更新---



根据要求,以下是更简短的示例:


  1. CMakeLists.txt文件

      cmake_minimum_required(2.8版)
    cmake_policy(SET CMP0015新)
    项目(测试)
    设置(在CMAKE_VERBOSE_MAKEFILE上)
    设置(CMAKE_RUNTIME_OUTPUT_DIRECTORY $ {CMAKE_CURRENT_SOURCE_DIR} /build.emscripten)
    include_directories( lib / assimp / include)
    link_directories( lib / assimp / lib-js)
    link_libraries( assimp)
    文件(GLOB_RECURSE CORE_HDR src / .h)
    文件(GLOB_RECURSE CORE_SRC src /
    .cpp)
    add_definitions(-s DEMANGLE_SUPPORT = 1 --preload-file $ {CMAKE_SOURCE_DIR} / assets --bind)
    add_executable(客户端$ {CORE_SRC} $ { CORE_HDR})


结果应等于运行手动执行以下命令:

  emcc 
-Ilib / assimp / include
-s DEMANGLE_SUPPORT = 1
--preload-file资产
-绑定
应用lication.cpp
lib / assimp / lib-js / libassimp.so
-o client.js



这是Application.cpp:

  #include Application.h 

#include< iostream>

#include< assimp / Importer.hpp>
#include< assimp / scene.h>
#include< assimp / postprocess.h>

void Application :: Initialize(){
std :: cout<< 初始化应用程序。 << std :: endl;
Assimp ::进口进口商; //出于测试目的
}

void Application :: SayHello(){
std :: cout<< 你好! << std :: endl;
}

和Application.h:

  #ifndef APPLICATION_H 
#define APPLICATION_H

#include< emscripten / html5.h>
#include< emscripten / bind.h>

名称空间e =脚本;

类申请{
public:
void Initialize();
void SayHello();
};

EMSCRIPTEN_BINDINGS(EMTest){
e :: class_< Application>( Application)
.constructor()
.function( Initialize,& Application :: Initialize)
.function( SayHello,& Application :: SayHello);
}

#endif

然后我按以下方式运行cmake :
cmake -DCMAKE_TOOLCHAIN_PATH = path / to / Emscripten.cmake ..&& make
但是,在链接和运行代码期间会生成类似 warning:unresolved symbol:_embind_register_class 之类的警​​告,并且<$中没有预加载的数据c $ c> client.data 文件是在编译CMake项目时创建的。同时没有警告,并且在手动编译时一切正常。

解决方案

解决方案是在链接期间指定所有标志通过提供以下CMake指令:
set_target_properties(客户端属性LINK_FLAGS -s DEMANGLE_SUPPORT = 1 --preload-file资产--bind)



感谢emscripten的开发人员在github问题跟踪器中提供了帮助。


I want to make CMake and Emscripten friends. Didn't find more or less informative documentation on the Emscripten project website, but they provide CMake toolchain file so I think it should be possible. So far very basic compilation without advanced parameters works fine, but I have issues while using embind and preloading files.

  1. Linking process seems to miss Emscripten "binaries" and produces warnings for all embind related functions like this one: warning: unresolved symbol: _embind_register_class which results in respective errors while loading compiled JS file in rowser.
  2. No .data file is generated during the compilation.

I've created a minimalistic example which includes two targets: one "normal" (client) and one manual (manual-client) which simply runs emcc as I expect it to be run: https://github.com/xwaffelx/minimal-cmake-emscripten-project/blob/master/README.md

Although manual way works, I don't think it is a proper way to do it...

--- Update ---

As requested, here is even more short example:

  1. CMakeLists.txt file

    cmake_minimum_required(VERSION 2.8)
    cmake_policy(SET CMP0015 NEW)
    project(emtest)
    set(CMAKE_VERBOSE_MAKEFILE on)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build.emscripten)
    include_directories("lib/assimp/include")
    link_directories("lib/assimp/lib-js")
    link_libraries("assimp")
    file(GLOB_RECURSE CORE_HDR src/.h)
    file(GLOB_RECURSE CORE_SRC src/.cpp)
    add_definitions("-s DEMANGLE_SUPPORT=1 --preload-file ${CMAKE_SOURCE_DIR}/assets --bind")
    add_executable(client ${CORE_SRC} ${CORE_HDR})
    

Result should be equivalent to running the following command manualy:

emcc 
    -Ilib/assimp/include 
    -s DEMANGLE_SUPPORT=1
    --preload-file assets
    --bind
    Application.cpp 
    lib/assimp/lib-js/libassimp.so 
    -o client.js

Here is the Application.cpp:

#include "Application.h"

#include <iostream>

#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>

void Application::Initialize() {
    std::cout << "Initializing application." << std::endl;
    Assimp::Importer importer; // For test purpose
}

void Application::SayHello() {
    std::cout << "Hello!" << std::endl;
}

and Application.h:

#ifndef APPLICATION_H
#define APPLICATION_H

#include <emscripten/html5.h>
#include <emscripten/bind.h>

namespace e = emscripten;

class Application {
public:
    void Initialize();
    void SayHello();
};

EMSCRIPTEN_BINDINGS(EMTest) {
  e::class_<Application>("Application")
    .constructor()
      .function("Initialize", &Application::Initialize)
      .function("SayHello", &Application::SayHello);
}

#endif

THen I run cmake as follows: cmake -DCMAKE_TOOLCHAIN_PATH=path/to/Emscripten.cmake .. && make However, warnings like warning: unresolved symbol: _embind_register_class are produced during linking and running the code and no preloaded data in client.data file is created while compiling CMake project. At the same time no warnings and everything runs OK while compiling manually.

解决方案

The solution was to specify all the flags during the linking by providing following CMake instruction: set_target_properties(client PROPERTIES LINK_FLAGS "-s DEMANGLE_SUPPORT=1 --preload-file assets --bind")

Thanks to developers of emscripten who helped in the github issues tracker.

这篇关于Emscripten的CMake项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆