Skip to content

Commit

Permalink
Add support for CMAKE_CROSSCOMPILING_EMULATOR.
Browse files Browse the repository at this point in the history
This variable was added in recent CMake Git master.  It should point to an
executable that acts like an emulator for the target system when
cross-compiling.  For emscripten, this is nodejs.

This executable is used by CMake to run executables in try_run commands.  By
adding support for this variable, it prevents the need to manually populate
the tedious TryRunResults.cmake file.

The emscripten configured path to NodeJS is added to the emcmake command.  In
the Emscripten.cmake file, if CMAKE_CROSSCOMPILING_EMULATOR is not defined
(which is would be if using emcmake), and attempt is made to find nodejs and
use it.
  • Loading branch information
thewtex committed May 12, 2015
1 parent 11630fb commit 832d95d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions cmake/Modules/Platform/Emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,14 @@ if ("${CMAKE_GENERATOR}" MATCHES "^Visual Studio.*")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${EMSCRIPTEN_VS_LINKER_FLAGS}" CACHE STRING "")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${EMSCRIPTEN_VS_LINKER_FLAGS}" CACHE STRING "")
endif()

if (NOT DEFINED CMAKE_CROSSCOMPILING_EMULATOR)
find_program(NODE_JS_EXECUTABLE NAMES nodejs node)
if(NODE_JS_EXECUTABLE)
set(CMAKE_CROSSCOMPILING_EMULATOR "${NODE_JS_EXECUTABLE}" CACHE FILEPATH "Path to the emulator for the target system.")
endif()
endif()
# No-op on CMAKE_CROSSCOMPILING_EMULATOR so older versions of cmake do not
# complain about unused CMake variable.
if(CMAKE_CROSSCOMPILING_EMULATOR)
endif()
5 changes: 3 additions & 2 deletions emcmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import os, subprocess, sys
from tools import shared

configure_path = shared.path_from_root('emconfigure')
exit(subprocess.call([shared.PYTHON, configure_path] + sys.argv[1:]))

exit(subprocess.call([shared.PYTHON, configure_path] + \
sys.argv[1] + \
['-DCMAKE_CROSSCOMPILING_EMULATOR=' + shared.NODE_JS] + sys.argv[2:]))

0 comments on commit 832d95d

Please sign in to comment.