CMake checks for haskell modules needed
authorunc0rr
Tue, 04 Feb 2014 23:53:43 +0400
changeset 10109 91d126fbd7bd
parent 10108 c68cf030eded
child 10110 a7aed2eea727
CMake checks for haskell modules needed
QTfrontend/CMakeLists.txt
cmake_modules/CheckHaskellModuleExists.cmake
cmake_modules/FindGHC.cmake
cmake_modules/checkModule.hs
gameServer/CMakeLists.txt
--- a/QTfrontend/CMakeLists.txt	Tue Feb 04 19:45:22 2014 +0100
+++ b/QTfrontend/CMakeLists.txt	Tue Feb 04 23:53:43 2014 +0400
@@ -16,7 +16,7 @@
 if(APPLE AND
    ${QTVERSION} VERSION_GREATER "4.7.0" AND
    ${QTVERSION} VERSION_LESS "4.7.4")
-    message(FATAL_ERROR "This version of QT is known *not* to work, please update or use a lower version")
+   message(FATAL_ERROR "This version of Qt is known *not* to work, please update or use a lower version")
 endif()
 
 find_package(SDL1or2)            #video in SDLInteraction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/CheckHaskellModuleExists.cmake	Tue Feb 04 23:53:43 2014 +0400
@@ -0,0 +1,52 @@
+# Based on CheckLibraryExists.cmake from CMake
+#=============================================================================
+# Copyright 2002-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+macro(CHECK_HASKELL_MODULE_EXISTS MODULE FUNCTION PARAMCOUNT LIBRARY)
+  set(VARIABLE "HS_MODULE_${LIBRARY}_${FUNCTION}")
+  if("${VARIABLE}" MATCHES "^${VARIABLE}$")
+    message(STATUS "Looking for ${FUNCTION} in ${MODULE}")
+
+    set(PARAMETERS "")
+
+    if(PARAMCOUNT GREATER 0)
+        foreach(__TRASH__ RANGE 1 ${PARAMCOUNT})
+            set(PARAMETERS "${PARAMETERS} undefined")
+        endforeach()
+    endif()
+
+    set(PARAMETERS "")
+
+    execute_process(COMMAND ${GHC_EXECUTABLE}
+                    "-DMODULE=${MODULE}"
+                    "-DFUNCTION=${FUNCTION}"
+                    "-DPARAMETERS=${PARAMETERS}"
+                    -cpp
+                    -c "${CMAKE_MODULE_PATH}/checkModule.hs"
+                    ERROR_VARIABLE BUILD_ERROR
+                    OUTPUT_STRIP_TRAILING_WHITESPACE
+                    )
+
+    if("${BUILD_ERROR}" STREQUAL "")
+      message(STATUS "Looking for ${FUNCTION} in ${MODULE} - found")
+      set(${VARIABLE} 1 CACHE INTERNAL "Have module ${MODULE}")
+      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+        "Determining if the function ${FUNCTION} exists in the ${MODULE} passed\n\n")
+    else()
+      message(STATUS "Looking for ${FUNCTION} in ${MODULE} - not found")
+      set(${VARIABLE} "" CACHE INTERNAL "Have module ${MODULE}")
+      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+        "Determining if the function ${FUNCTION} exists in the ${MODULE} "
+        "failed with the following output:\n"
+        "${BUILD_ERROR}\n\n")
+      message(FATAL_ERROR "Haskell library '${LIBRARY}' required")
+    endif()
+  endif()
+endmacro()
--- a/cmake_modules/FindGHC.cmake	Tue Feb 04 19:45:22 2014 +0100
+++ b/cmake_modules/FindGHC.cmake	Tue Feb 04 23:53:43 2014 +0400
@@ -17,7 +17,7 @@
     )
 
 if (GHC_EXECUTABLE)
-    # check Freepascal version
+    # check ghc version
     execute_process(COMMAND ${GHC_EXECUTABLE} -V
                     OUTPUT_VARIABLE GHC_VERSION_OUTPUT
                     ERROR_VARIABLE GHC_VERSION_ERROR
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/checkModule.hs	Tue Feb 04 23:53:43 2014 +0400
@@ -0,0 +1,5 @@
+module Main where
+
+import qualified MODULE as M
+
+main = undefined $ M.FUNCTION PARAMETERS
--- a/gameServer/CMakeLists.txt	Tue Feb 04 19:45:22 2014 +0100
+++ b/gameServer/CMakeLists.txt	Tue Feb 04 23:53:43 2014 +0400
@@ -3,6 +3,30 @@
 
 find_package_or_disable(GHC NOSERVER)
 
+include(${CMAKE_MODULE_PATH}/CheckHaskellModuleExists.cmake)
+
+check_haskell_module_exists("Control.Exception" mask 1 base)
+check_haskell_module_exists("Data.Map" size 1 containers)
+check_haskell_module_exists("Data.Vector" length 1 vector)
+check_haskell_module_exists("Data.ByteString" pack 1 bytestring)
+check_haskell_module_exists("Text.Show.ByteString" putDigit 1 bytestring-show)
+check_haskell_module_exists("Network.BSD" getHostName 0 network)
+check_haskell_module_exists("Data.Time" getCurrentTime 0 time)
+check_haskell_module_exists("Control.Monad.State" fix 1 mtl)
+check_haskell_module_exists("Codec.Binary.Base64" encode 1 dataenc)
+check_haskell_module_exists("System.Log.Logger" warningM 1 hslogger)
+check_haskell_module_exists("System.Process" createProcess 3 process)
+check_haskell_module_exists("Data.ByteString.Lazy.UTF8" decode 1 utf8-string)
+check_haskell_module_exists("Data.Digest.Pure.SHA" sha1 1 SHA)
+check_haskell_module_exists("System.Entropy" openHandle 0 entropy)
+check_haskell_module_exists("Codec.Compression.Zlib" decompress 1 zlib)
+check_haskell_module_exists("System.Random" getStdGen 0 random)
+
+# this one needs type signatures to work
+# check_haskell_module_exists("Control.DeepSeq" deepseq 2 deepseq)
+
+
+
 set(hwserver_sources
     OfficialServer/DBInteraction.hs
     Actions.hs