Issue specifying option while using Emscripten (Em

2019-07-27 14:36发布

问题:

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

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.

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})