cmake_modules/CheckHaskellModuleExists.cmake
author sheepluva
Fri, 13 Jun 2014 21:17:50 +0200
changeset 10299 45e3e901b3b9
parent 10109 91d126fbd7bd
child 10723 2cfa65083621
permissions -rw-r--r--
grmlgrmlpas2cgrmlgrml
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     1
# Based on CheckLibraryExists.cmake from CMake
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     2
#=============================================================================
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     3
# Copyright 2002-2009 Kitware, Inc.
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     4
#
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     5
# Distributed under the OSI-approved BSD License
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     6
#
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     7
# This software is distributed WITHOUT ANY WARRANTY; without even the
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     8
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     9
# See the License for more information.
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    10
#=============================================================================
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    11
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    12
macro(CHECK_HASKELL_MODULE_EXISTS MODULE FUNCTION PARAMCOUNT LIBRARY)
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    13
  set(VARIABLE "HS_MODULE_${LIBRARY}_${FUNCTION}")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    14
  if("${VARIABLE}" MATCHES "^${VARIABLE}$")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    15
    message(STATUS "Looking for ${FUNCTION} in ${MODULE}")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    16
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    17
    set(PARAMETERS "")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    18
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    19
    if(PARAMCOUNT GREATER 0)
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    20
        foreach(__TRASH__ RANGE 1 ${PARAMCOUNT})
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    21
            set(PARAMETERS "${PARAMETERS} undefined")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    22
        endforeach()
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    23
    endif()
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    24
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    25
    set(PARAMETERS "")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    26
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    27
    execute_process(COMMAND ${GHC_EXECUTABLE}
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    28
                    "-DMODULE=${MODULE}"
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    29
                    "-DFUNCTION=${FUNCTION}"
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    30
                    "-DPARAMETERS=${PARAMETERS}"
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    31
                    -cpp
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    32
                    -c "${CMAKE_MODULE_PATH}/checkModule.hs"
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    33
                    ERROR_VARIABLE BUILD_ERROR
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    34
                    OUTPUT_STRIP_TRAILING_WHITESPACE
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    35
                    )
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    36
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    37
    if("${BUILD_ERROR}" STREQUAL "")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    38
      message(STATUS "Looking for ${FUNCTION} in ${MODULE} - found")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    39
      set(${VARIABLE} 1 CACHE INTERNAL "Have module ${MODULE}")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    40
      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    41
        "Determining if the function ${FUNCTION} exists in the ${MODULE} passed\n\n")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    42
    else()
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    43
      message(STATUS "Looking for ${FUNCTION} in ${MODULE} - not found")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    44
      set(${VARIABLE} "" CACHE INTERNAL "Have module ${MODULE}")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    45
      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    46
        "Determining if the function ${FUNCTION} exists in the ${MODULE} "
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    47
        "failed with the following output:\n"
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    48
        "${BUILD_ERROR}\n\n")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    49
      message(FATAL_ERROR "Haskell library '${LIBRARY}' required")
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    50
    endif()
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    51
  endif()
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    52
endmacro()