使用Emscripten(Emcmake)时指定问题的选项 [英] Issue specifying option while using Emscripten (Emcmake)

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

问题描述

我的问题是关于将 CMakeLists.txt 与Emscriptem一起使用,并指定输出类型以及命令行选项.

My question is regarding using a CMakeLists.txt with Emscriptem and specifying the output type along with a command line option.

我想使用一个简单的Emscripten命令,例如: emcc file.cpp -o file.html --preload-file asset_dir/并将其更改为我可以在CMake系统中指定的内容.我尝试了将可执行文件重命名为具有html扩展名的幼稚方法,但这没有用.我还尝试使用 -D--preload-file:PATH = asset_dir ,但这也不起作用.

I want to take a simple Emscripten command such as: emcc file.cpp -o file.html --preload-file asset_dir/ and change it to something that I can specify within my CMake system. I tried the naive approach of renaming the executable to have an extension of html but that didn't work. I also tried using -D--preload-file:PATH=asset_dir and that did not work either.

我的 CMakeLists.txt 文件很小,包含在下面.我使用命令 emcmake cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE = Release -DCMAKE_CXX_COMPILER = em ++ ..&&emmake make 来构建它.

My CMakeLists.txt file is small and is contained below. I use the command emcmake cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=em++ .. && emmake make to build it.

CMAKE_MINIMUM_REQUIRED(VERSION 3.2.0 FATAL_ERROR)
PROJECT(ProjJS)

# Set typical CMAKE settings
SET(CMAKE_BUILD_TYPE_INIT "Release")
SET(CMAKE_VERBOSE_MAKEFILE OFF CACHE BOOL "Turn on Verbose Makefiles" FORCE)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")

SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)

SET(PROJ_SOURCES
    hello.cpp
    ....
)

set(NAME_OF_EXE "ProjJS")

set(BOOST_LIB "boost")
set(BOOST_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extlibs/")
set(BOOST_LIB_PATH "${CMAKE_SOURCE_DIR}/extlibs/boost/libs/")

add_subdirectory(extlibs/boost)


SET(BOOST_PROGRAM_OPTIONS_SOURCES
    ${BOOST_LIB_PATH}/program_options/cmdline.cpp
    ${BOOST_LIB_PATH}/program_options/config_file.cpp
    ....
)

SET(BOOST_SYSTEM_SOURCES
    ${BOOST_LIB_PATH}/system/error_code.cpp
)

ADD_EXECUTABLE(${NAME_OF_EXE} ${PROJ_SOURCES})
add_library(${BOOST_LIB} STATIC ${BOOST_PROGRAM_OPTIONS_SOURCES} ${BOOST_SYSTEM_SOURCES})
TARGET_INCLUDE_DIRECTORIES(${BOOST_LIB} PUBLIC "${BOOST_INCLUDE_PATH}")

TARGET_LINK_LIBRARIES(${NAME_OF_EXE} PUBLIC ${BOOST_LIB})
TARGET_INCLUDE_DIRECTORIES(${NAME_OF_EXE} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/include")
TARGET_INCLUDE_DIRECTORIES(${NAME_OF_EXE} BEFORE PRIVATE "${BOOST_INCLUDE_PATH}" ${PROJ_SOURCES})

推荐答案

对于输出后缀,这应该有效:

For the output suffix this should work:

set(CMAKE_EXECUTABLE_SUFFIX ".html")

完整示例:

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(demo)

set(CMAKE_EXECUTABLE_SUFFIX ".html")

add_executable(hello tests/hello_world.cpp)

这将发出 hello.html 等.

对于其他标志,我发现的最佳选择是使用 target_link_libraries ,CMake会将其附加到链接行,并且可以包含任何内容.例如:

For other flags, the best option I've found is to use target_link_libraries which CMake just appends to the link line, and can contain anything. For example:

target_link_libraries(binaryen_js "-s MODULARIZE")
target_link_libraries(binaryen_js "-s INITIAL_MEMORY=512MB")

这将打开模块化并将初始内存设置为512MB(例如Binaryen CMake脚本).

That turns on modularize and sets the initial memory to 512MB (example from the Binaryen CMake script).

这篇关于使用Emscripten(Emcmake)时指定问题的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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