title: Emscripten - cmake - pass emscripten options in CMakeList file
body: <p>How to use <code>emcmake cmake</code> and pass emscripten command-line options?</p>
  
  <p>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.</p>
  
  <p>I can build my project (non-webassembly / normal desktop) with the following CMakeList.txt file</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>And for the web(assembly)</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>But shouldn't it be possible to use <code>emcmake cmake</code> and keep it all in the (single) CMakeList file? If I execute <code>emcmake cmake &amp;&amp; make</code> it generates a file real quick buts its as good as empty (missing all files).</p>
  
  <p>It probably comes down to how to pass the arguments to emscripten in the CMakeFile I guess... </p>
  
  <p>Duplicate of <a href="https://stackoverflow.com/questions/37747205/cmake-project-for-emscripten">CMake project for Emscripten</a> and <a href="https://stackoverflow.com/questions/42379391/issue-specifying-option-while-using-emscripten-emcmake">Issue specifying option while using Emscripten (Emcmake)</a></p>
  
  <p>But settings <code>SET_TARGET_PROPERTIES(Engine PROPERTIES LINK_FLAGS "-s SAFE_HEAP=1")</code> only gives the following kind of errors:</p>
  
  <pre><code>error: no such file or directory: 'SAFE_HEAP=1'
  </code></pre>
  
  <p>So really.. Am I wrong about how emcmake make work, and if not, how can I pass the emscripten arguments in the CMakeList file?</p>
  
  <p>Many thanks!</p>