通过CMakeList文件中的emscripten选项

通过CMakeList文件中的emscripten选项

本文介绍了Emscripten-cmake-通过CMakeList文件中的emscripten选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 emcmake cmake 并传递emscripten命令行选项?

How to use emcmake cmake and pass emscripten command-line options?

c ++ / CMake的新功能,但在Google上找不到任何有用的信息。因此,也许问题只是愚蠢,在这种情况下,我道歉。

Pretty new to c++ / CMake, but can't find anything helpful on google. So maybe the question is just to stupid, in that case I apologise.

我可以使用以下CMakeList.txt文件构建我的项目(非网络组装/普通桌面)

I can build my project (non-webassembly / normal desktop) with the following CMakeList.txt file

cmake_minimum_required(VERSION 3.7)
project(Engine)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_INCLUDE_PATH /usr/local/include)
set(SOURCE_FILES main.cpp src/Background.cpp src/Background.h src/Camera.cpp src/Chart.cpp src/Chart.h src/logger.cpp src/Engine.cpp src/Engine.h src/GL.cpp src/GL.h src/Instrument.cpp src/Instrument.h)
set(EMCC_LINKER_FLAGS "-s SAFE_HEAP=1 --bind -s WASM=1 -O3 -o ../index.js -s LEGACY_GL_EMULATION=0  -s GL_UNSAFE_OPTS=0 --pre-js pre-module.js --post-js post-module.js -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -s INVOKE_RUN=0  -std=c++11 -s USE_WEBGL2=1 -s FULL_ES3=1 -s USE_GLFW=3 -s OFFSCREENCANVAS_SUPPORT=1 --preload-file shaders --preload-file extern --use-preload-plugins")
set(CMAKE_REQUIRED_FLAGS "${EMCC_LINKER_FLAGS}")

find_package(OPENGL REQUIRED)
find_package(GLEW REQUIRED)
#find_package(SDL2 REQUIRED)
find_package(glfw3 REQUIRED)
find_package(assimp REQUIRED)
find_package(Freetype REQUIRED)

include_directories(/emscripten/ /emscripten/emscripten/incoming/system/include)
include_directories(/usr/local/include)
include_directories(${FREETYPE_INCLUDE_DIRS} ${SDL2_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${GLFW_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR} ${SDL2_TTF_INCLUDE_DIR})

#add_subdirectory(shaders)

add_executable(Engine ${SOURCE_FILES} extern/stb_image.cpp src/Camera.h src/Cubes.cpp src/Chart.cpp)

target_link_libraries(Engine ${FREETYPE_LIBRARIES} ${OPENGL_gl_LIBRARY} ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARIES} ${SDL2_TTF_LIBRARIES} ${GLEW_LIBRARIES} glfw assimp)
#
#file(GLOB shaders/**/*.glsl shaders/*.glsl)

file(INSTALL shaders DESTINATION .)
file(INSTALL textures DESTINATION .)
#set(CMAKE_EXE_LINKER_FLAGS "${EMCC_LINKER_FLAGS}")
#SET_TARGET_PROPERTIES(Engine PROPERTIES LINK_FLAGS "-s SAFE_HEAP=1")
# add extra lib directories
#link_directories(/usr/local/lib)

用于Web(程序集)

emcc main.cpp ./src/*.cpp ./extern/*.cpp -o dist/engine.js -g  -s DISABLE_EXCEPTION_CATCHING=0 -s TOTAL_MEMORY=33554432  -s DEMANGLE_SUPPORT=1 -s SAFE_HEAP=1 --bind -s WASM=1 -Os -s LEGACY_GL_EMULATION=0  -s GL_UNSAFE_OPTS=0 --pre-js pre-module.js --post-js post-module.js -s ASSERTIONS=2 -s GL_ASSERTIONS=1 -s INVOKE_RUN=0  -std=c++11 -s USE_WEBGL2=1 -s FULL_ES3=1 -s USE_GLFW=3 -s OFFSCREENCANVAS_SUPPORT=1 --preload-file textures --preload-file shaders --preload-file extern --use-preload-plugins

但是不应该使用 emcmake cmake 并将其全部保存在(单个)CMakeList文件中吗?如果我执行 emcmake cmake&& make 它会真正快速地生成一个文件,但其效果与空文件一样好(丢失所有文件)。

But shouldn't it be possible to use emcmake cmake and keep it all in the (single) CMakeList file? If I execute emcmake cmake && make it generates a file real quick buts its as good as empty (missing all files).

它可能取决于如何传递我猜想在CMakeFile中实现脚本的参数...

It probably comes down to how to pass the arguments to emscripten in the CMakeFile I guess...

重复的和

但是设置 SET_TARGET_PROPERTIES(Engine PROPERTIES LINK_FLAGS -s SAFE_HEAP = 1)仅给出以下类型的错误:

But settings SET_TARGET_PROPERTIES(Engine PROPERTIES LINK_FLAGS "-s SAFE_HEAP=1") only gives the following kind of errors:

error: no such file or directory: 'SAFE_HEAP=1'

真的。我对emcmake的工作方式有误,如果没有,我该如何在其中传递emscripten参数

So really.. Am I wrong about how emcmake make work, and if not, how can I pass the emscripten arguments in the CMakeList file?

非常感谢!

推荐答案

作为Emscripten / CMake的菜鸟,我没有意识到emcmake不会自动使用emscripten基本cmake文件(我确实希望如果我运行特殊的emscripten emcmake命令...。)

As a noob to Emscripten / CMake, I wasn't realising that emcmake does not automatically use the emscripten base cmake file (what I do expect if I run an Special emscripten emcmake command....)

无论如何,事实证明我不需要emcmake,可以像这样从三元组调用cmake此->

Anyway, turns out I don't need emcmake and can just call cmake from the ternimal like this ->

cmake -DCMAKE_BUILD_TYPE=Debug -G \"Unix Makefiles\" -DCMAKE_TOOLCHAIN_FILE=/emscripten/emscripten/incoming/cmake/Modules/Platform/Emscripten.cmake . && make

这是我最后的CMakeList.txt

And here is my final CMakeList.txt

cmake_minimum_required(VERSION 3.7)
project(Engine)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist)
SET(CMAKE_BUILD_TYPE_INIT "Release")
set(CMAKE_CXX_STANDARD 11)

if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
    set(CMAKE_C_COMPILER "emcc")
endif ()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
set(SOURCE_FILES main.cpp src/Background.cpp src/Background.h src/Camera.cpp src/Chart.cpp src/Chart.h src/logger.cpp src/Engine.cpp src/Engine.h src/GL.cpp src/GL.h src/Instrument.cpp src/Instrument.h src/Text.cpp src/Text.h)

find_package(OPENGL REQUIRED)

if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
    find_package(GLEW REQUIRED)
    find_package(glfw3 REQUIRED)
    find_package(assimp REQUIRED)
    find_package(freetype REQUIRED)
endif ()

include_directories(
        /emscripten/
        /emscripten/emscripten/incoming/system/include
        /opt/X11/include/freetype2
        /usr/local/Cellar/freetype/2.8/include/freetype2
        ${FREETYPE_INCLUDE_DIRS}
        ${OPENGL_INCLUDE_DIR}
)

if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
    include_directories(${GLEW_INCLUDE_DIR})
endif ()

add_executable(Engine ${SOURCE_FILES} extern/stb_image.cpp src/Camera.h src/Cubes.cpp src/Chart.cpp)

target_link_libraries(Engine ${OPENGL_gl_LIBRARY})

if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
    set_target_properties(Engine PROPERTIES LINK_FLAGS "-o dist/engine.js -s USE_FREETYPE=1 -s DISABLE_EXCEPTION_CATCHING=0 -s DEMANGLE_SUPPORT=1 -s SAFE_HEAP=1 --bind -s WASM=1 -O2 -s LEGACY_GL_EMULATION=0  -s GL_UNSAFE_OPTS=0 --pre-js pre-module.js --post-js post-module.js -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -s INVOKE_RUN=0  -std=c++11 -s USE_WEBGL2=1 -s FULL_ES3=1 -s USE_GLFW=3 -s OFFSCREENCANVAS_SUPPORT=1 --preload-file textures --preload-file shaders --preload-file fonts")

else ()
    target_link_libraries(Engine glfw glew)
endif ()

file(INSTALL shaders DESTINATION .)
file(INSTALL textures DESTINATION .)

这篇关于Emscripten-cmake-通过CMakeList文件中的emscripten选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 14:56