cmake_modules/CheckHaskellPackageExists.cmake
changeset 13296 31615a2e0db1
parent 12118 72f5d670bbee
equal deleted inserted replaced
13295:a3b07219a091 13296:31615a2e0db1
       
     1 # Checks if a given Haskell package exists (using ghc-pkg)
       
     2 # and fails if it's missing.
       
     3 # Loosely based on CheckLibraryExists.cmake from CMake.
       
     4 #=============================================================================
       
     5 # Copyright 2002-2009 Kitware, Inc.
       
     6 #
       
     7 # Distributed under the OSI-approved BSD License
       
     8 #
       
     9 # This software is distributed WITHOUT ANY WARRANTY; without even the
       
    10 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
       
    11 # See the License for more information.
       
    12 #=============================================================================
       
    13 
       
    14 macro(CHECK_HASKELL_PACKAGE_EXISTS PACKAGE MODULE FUNCTION PARAMCOUNT)
       
    15 # NOTE: MODULE, FUNCTION and PARAMCOUNT are curretly ignored.
       
    16 # TODO: Either implement these or drop?
       
    17 
       
    18   set(VARIABLE "HS_PACKAGE_${PACKAGE}")
       
    19   if(NOT (${VARIABLE} EQUAL "1"))
       
    20     message(STATUS "Looking for Haskell package ${PACKAGE} ...")
       
    21 
       
    22     execute_process(COMMAND ${GHC_PKG_EXECUTABLE}
       
    23                     "latest"
       
    24                     ${PACKAGE}
       
    25                     "--simple-output"
       
    26                     RESULT_VARIABLE COMMAND_RESULT
       
    27                     ERROR_VARIABLE BUILD_ERROR
       
    28                     OUTPUT_STRIP_TRAILING_WHITESPACE
       
    29                     OUTPUT_QUIET
       
    30                     )
       
    31 
       
    32     if(${COMMAND_RESULT} EQUAL 0)
       
    33       message(STATUS "Looking for Haskell package ${PACKAGE} - found")
       
    34       set(${VARIABLE} "1" CACHE INTERNAL "Have package ${PACKAGE}")
       
    35       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
       
    36         "Determining if the Haskell package ${PACKAGE} exists has passed\n\n")
       
    37     else()
       
    38       message(STATUS "Looking for Haskell package ${PACKAGE} - not found")
       
    39       set(${VARIABLE} "0" CACHE INTERNAL "Have package ${PACKAGE}")
       
    40       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
       
    41         "Determining if the Haskell package ${PACKAGE} "
       
    42         "exists failed with the following output:\n"
       
    43         "${BUILD_ERROR}\n\n")
       
    44       message(FATAL_ERROR "Haskell package '${PACKAGE}' required")
       
    45     endif()
       
    46   endif()
       
    47 endmacro()