Fully support emscripten toolchain in our build system
authorkoda
Thu, 21 Apr 2016 11:55:36 -0400
changeset 11664 71bdf987e41f
parent 11663 f87ed83568c8
child 11665 64bb93e9b2b5
Fully support emscripten toolchain in our build system
CMakeLists.txt
misc/liblua/CMakeLists.txt
misc/libphyslayer/CMakeLists.txt
project_files/hwc/CMakeLists.txt
project_files/hwc/rtl/CMakeLists.txt
--- a/CMakeLists.txt	Thu Apr 21 11:54:21 2016 -0400
+++ b/CMakeLists.txt	Thu Apr 21 11:55:36 2016 -0400
@@ -51,6 +51,22 @@
 
 option(NOVERSIONINFOUPDATE "Disable update of version_info.txt. To be used if source is in a git/repo that is NOT the hedgewars repo" OFF)
 
+
+if(BUILD_ENGINE_JS)
+    if(NOT CMAKE_TOOLCHAIN_FILE)
+        message(FATAL_ERROR "Missing emscripten toolchain file\nRerun cmake with -DCMAKE_TOOLCHAIN_FILE=${CMAKE_SOURCE_DIR}/cmake_modules/Platform/Emscripten.cmake")
+    endif()
+
+    set(BUILD_ENGINE_C ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(NOAUTOUPDATE ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(PHYSFS_SYSTEM OFF CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(LUA_SYSTEM OFF CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(NOVIDEOREC ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(NOSERVER ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(GL2 ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(BUILD_SHARED_LIBS OFF CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+endif()
+
 #system paths for finding required fonts (see share/hedgewars/Data/fonts)
 #subdirectories will NOT be searched.
 #all fonts that can't be found will be bundled with hedgewars
@@ -91,7 +107,10 @@
 
 
 #perform safe check that enable/disable compilation features
-include(${CMAKE_MODULE_PATH}/compilerchecks.cmake)
+#skip when crosscompiling to javascript
+if(NOT BUILD_ENGINE_JS)
+    include(${CMAKE_MODULE_PATH}/compilerchecks.cmake)
+endif()
 
 #set default compiler flags
 add_flag_append(CMAKE_C_FLAGS "-Wall -pipe")
@@ -136,7 +155,7 @@
 
 
 #build engine without freepascal
-if(BUILD_ENGINE_C)
+if(BUILD_ENGINE_C AND NOT BUILD_ENGINE_JS)
     find_package(Clang REQUIRED)
 
     if(${CLANG_VERSION} VERSION_LESS "3.0")
@@ -226,9 +245,6 @@
 else()
     #main pascal engine
     add_subdirectory(hedgewars)
-    if(BUILD_ENGINE_JS)
-        message(FATAL_ERROR "This option needs BUILD_ENGINE_C to be set")
-    endif()
 endif()
 
 #Android related build scripts
@@ -236,9 +252,13 @@
 if(ANDROID)
     add_subdirectory(project_files/Android-build)
 else(ANDROID)
+    #skip frontend for javascript
+    if(NOT BUILD_ENGINE_JS)
+        add_subdirectory(QTfrontend)
+        add_subdirectory(share)
+    endif()
+
     add_subdirectory(bin)
-    add_subdirectory(QTfrontend)
-    add_subdirectory(share)
     add_subdirectory(tools)
 endif(ANDROID)
 
--- a/misc/liblua/CMakeLists.txt	Thu Apr 21 11:54:21 2016 -0400
+++ b/misc/liblua/CMakeLists.txt	Thu Apr 21 11:55:36 2016 -0400
@@ -23,4 +23,8 @@
 set(LUA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Lua include dir" FORCE)
 set(LUA_LIBRARY ${lua_fullpath} CACHE STRING "Lua library" FORCE)
 
+#emscripten does not expose headers but has an internal binary copy
+if(BUILD_ENGINE_JS)
+    set(LUA_LIBRARY "lua_emscripten_internal" CACHE STRING "Lua library" FORCE)
+endif()
 
--- a/misc/libphyslayer/CMakeLists.txt	Thu Apr 21 11:54:21 2016 -0400
+++ b/misc/libphyslayer/CMakeLists.txt	Thu Apr 21 11:55:36 2016 -0400
@@ -26,3 +26,7 @@
 set(PHYSLAYER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Physlayer include dir" FORCE)
 set(PHYSLAYER_LIBRARY ${physlayer_fullpath} CACHE STRING "Physlayer library" FORCE)
 
+if(BUILD_ENGINE_JS)
+    set_target_properties(physlayer PROPERTIES SUFFIX ".bc")
+endif()
+
--- a/project_files/hwc/CMakeLists.txt	Thu Apr 21 11:54:21 2016 -0400
+++ b/project_files/hwc/CMakeLists.txt	Thu Apr 21 11:55:36 2016 -0400
@@ -6,9 +6,6 @@
 find_package(SDL2_net REQUIRED)
 find_package(SDL2_image REQUIRED)
 find_package(SDL2_ttf REQUIRED)
-if(BUILD_ENGINE_JS)
-    find_package(Emscripten REQUIRED)
-endif()
 
 #compile our rtl implementation
 include_directories(${GLEW_INCLUDE_DIR})
@@ -81,13 +78,12 @@
 add_definitions(-DPAS2C)
 add_definitions(-Werror=incompatible-pointer-types)
 
+add_executable(hwengine WIN32 ${engine_sources})
+
 if(BUILD_ENGINE_JS)
-    #hijack the c compiler with emscripten
-    set(CMAKE_C_COMPILER ${EMSCRIPTEN_EXECUTABLE})
+    set_target_properties(hwengine PROPERTIES SUFFIX ".html")
 endif()
 
-add_executable(hwengine WIN32 ${engine_sources})
-
 target_link_libraries(hwengine  fpcrtl
                                 ${LUA_LIBRARY}
                                 ${OPENGL_LIBRARY}
--- a/project_files/hwc/rtl/CMakeLists.txt	Thu Apr 21 11:54:21 2016 -0400
+++ b/project_files/hwc/rtl/CMakeLists.txt	Thu Apr 21 11:55:36 2016 -0400
@@ -5,12 +5,3 @@
 
 add_library(fpcrtl STATIC ${fpcrtl_src})
 
-#if(WEBGL)
-#    set_target_properties(fpcrtl PROPERTIES PREFIX "em")
-#    set_target_properties(fpcrtl PROPERTIES SUFFIX ".bc")
-#endif(WEBGL)
-
-
-
-
-