add CMakeFile for pas2c, add WEBGL config option webgl
authorkoda
Mon, 05 Nov 2012 02:24:28 +0100
branchwebgl
changeset 7973 afb67e34a6b5
parent 7969 7fcbbd46704a
child 7975 1a8308265fdd
add CMakeFile for pas2c, add WEBGL config option
CMakeLists.txt
tools/pas2c/CMakeLists.txt
--- a/CMakeLists.txt	Mon Nov 05 01:35:54 2012 +0100
+++ b/CMakeLists.txt	Mon Nov 05 02:24:28 2012 +0100
@@ -55,6 +55,7 @@
 
 option(BUILD_ENGINE_LIBRARY "Enable hwengine library [default: off]" OFF)
 option(ANDROID "Enable Android build [default: off]" OFF)
+option(WEBGL "Enable WebGL build [default: off]" OFF)
 
 option(NOAUTOUPDATE "Disable OS X Sparkle update checking" OFF)
 option(CROSSAPPLE "Enable OSX when not on OSX [default: off]" OFF)
@@ -204,8 +205,8 @@
 set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
 
 
-#server discovery
-if(NOT NOSERVER)
+#Haskell compiler discovery (for server and webgl
+if((NOT NOSERVER) OR WEBGL)
     if(GHC)
         set(ghc_executable ${GHC})
     else()
@@ -213,22 +214,28 @@
     endif()
 
     if(ghc_executable)
-        set(HAVE_NETSERVER true)
-        add_subdirectory(gameServer)
-        message(STATUS "Found GHC: ${ghc_executable}")
+        exec_program(${ghc_executable} ARGS "-V" OUTPUT_VARIABLE ghc_version_long)
+        string(REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" ghc_version "${ghc_version_long}")
+        message(STATUS "Found GHC: ${ghc_executable} (version ${ghc_version})")
     else()
-        message(STATUS "Could NOT find GHC, server will not be built")
-        set(HAVE_NETSERVER false)
+        message(STATUS "Could NOT find GHC, needed by gameServer and pas2c")
     endif()
+endif()
+
+
+#check gameServer
+if((ghc_executable) AND (NOT NOSERVER) AND (NOT WEBGL))
+    set(HAVE_NETSERVER true)
+    add_subdirectory(gameServer)
 else()
-    message(STATUS "Server will not be built per user request")
+    message(STATUS "Skipping gameServer target")
     set(HAVE_NETSERVER false)
 endif()
 
 
 #lua discovery
 find_package(Lua)
-if(LUA_FOUND)
+if(LUA_FOUND AND (NOT WEBGL))
     message(STATUS "Found LUA: ${LUA_DEFAULT}")
 else()
     message(STATUS "LUA will be provided by the bundled sources")
@@ -238,23 +245,32 @@
 endif()
 
 
-#main engine
-add_subdirectory(hedgewars)
+if(WEBGL)
+    if (NOT ghc_executable)
+        message(FATAL_ERROR "A Haskell compiler is required to build the WebGL port")
+    endif()
+    #pascal to c converter
+    add_subdirectory(tools/pas2c)
+else()
+    #main engine
+    add_subdirectory(hedgewars)
 
-#Android related build scripts
-if(ANDROID)
-    #run cmake -DANDROID=1 to enable this
-    add_subdirectory(project_files/Android-build)
+    #Android related build scripts
+    if(ANDROID)
+        #run cmake -DANDROID=1 to enable this
+        add_subdirectory(project_files/Android-build)
+    endif()
+
+    #TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set
+    if(NOT (BUILD_ENGINE_LIBRARY OR ANDROID OR WEBGL))
+        add_subdirectory(bin)
+        add_subdirectory(misc/quazip)
+        add_subdirectory(QTfrontend)
+        add_subdirectory(share)
+        add_subdirectory(tools)
+    endif()
 endif()
 
-#TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set
-if(NOT (BUILD_ENGINE_LIBRARY OR ANDROID))
-    add_subdirectory(bin)
-    add_subdirectory(misc/quazip)
-    add_subdirectory(QTfrontend)
-    add_subdirectory(share)
-    add_subdirectory(tools)
-endif()
 
 
 # CPack variables
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/pas2c/CMakeLists.txt	Mon Nov 05 02:24:28 2012 +0100
@@ -0,0 +1,28 @@
+set(pas2c_sources
+    Main.hs
+    PascalBasics.hs
+    PascalParser.hs
+    PascalPreprocessor.hs
+    PascalUnitSyntaxTree.hs
+    pas2c.hs
+        )
+
+set(pas2c_main ${hedgewars_SOURCE_DIR}/tools/pas2c/Main.hs)
+
+set(ghc_flags
+    --make ${pas2c_main}
+    -i${hedgewars_SOURCE_DIR}/tools/pas2c/
+    -o ${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}
+    -odir ${CMAKE_CURRENT_BINARY_DIR}
+    -hidir ${CMAKE_CURRENT_BINARY_DIR}
+    ${haskell_flags})
+
+add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}"
+        COMMAND "${ghc_executable}"
+        ARGS ${ghc_flags}
+        MAIN_DEPENDENCY ${hwserv_main}
+        DEPENDS ${hwserver_sources}
+        )
+
+add_custom_target(pas2c ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}")
+