cmake_modules/FindGHC.cmake
changeset 13291 31615a2e0db1
parent 10109 91d126fbd7bd
equal deleted inserted replaced
13290:a3b07219a091 13291:31615a2e0db1
     1 # - Try to find the Glasgow Haskell Compiler executable
     1 # - Try to find the Glasgow Haskell Compiler executable
     2 # Once done this will define
     2 # Once done this will define
     3 #
     3 #
     4 #  GHC_FOUND       - system has GHC
     4 #  GHC_VERSION        - GHC version
     5 #  GHC_VERSION     - GHC version
     5 #  GHC_EXECUTABLE     - GHC executable
     6 #  GHC_EXECUTABLE  - GHC executable
     6 #  GHC_PKG_VERSION    - ghc-pkg version
       
     7 #  GHC_PKG_EXECUTABLE - ghc-pkg executable
     7 #
     8 #
     8 # Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com>
     9 # Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com>
     9 #
    10 #
    10 # Redistribution and use is allowed according to the terms of the BSD license.
    11 # Redistribution and use is allowed according to the terms of the BSD license.
    11 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
    12 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
    12 
    13 
    13 
    14 
    14 find_program(GHC_EXECUTABLE
    15 find_program(GHC_EXECUTABLE
    15     NAMES ghc
    16     NAMES ghc
       
    17     PATHS /opt/local/bin /usr/local/bin /usr/bin
       
    18     )
       
    19 
       
    20 find_program(GHC_PKG_EXECUTABLE
       
    21     NAMES ghc-pkg
    16     PATHS /opt/local/bin /usr/local/bin /usr/bin
    22     PATHS /opt/local/bin /usr/local/bin /usr/bin
    17     )
    23     )
    18 
    24 
    19 if (GHC_EXECUTABLE)
    25 if (GHC_EXECUTABLE)
    20     # check ghc version
    26     # check ghc version
    30     else()
    36     else()
    31         message(SEND_ERROR "Command \"${GHC_EXECUTABLE} -V\" failed with output: ${GHC_VERSION_ERROR}")
    37         message(SEND_ERROR "Command \"${GHC_EXECUTABLE} -V\" failed with output: ${GHC_VERSION_ERROR}")
    32     endif()
    38     endif()
    33 endif()
    39 endif()
    34 
    40 
       
    41 if (GHC_PKG_EXECUTABLE)
       
    42     # check ghc-pkg version
       
    43     execute_process(COMMAND ${GHC_PKG_EXECUTABLE} -V
       
    44                     OUTPUT_VARIABLE GHC_PKG_VERSION_OUTPUT
       
    45                     ERROR_VARIABLE GHC_PKG_VERSION_ERROR
       
    46                     RESULT_VARIABLE GHC_PKG_VERSION_RESULT
       
    47                     OUTPUT_STRIP_TRAILING_WHITESPACE
       
    48                     )
       
    49 
       
    50     if(${GHC_PKG_VERSION_RESULT} EQUAL 0)
       
    51         string(REGEX MATCH "([0-9]+)" GHC_PKG_VERSION ${GHC_PKG_VERSION_OUTPUT})
       
    52     else()
       
    53         message(SEND_ERROR "Command \"${GHC_PKG_EXECUTABLE} -V\" failed with output: ${GHC_PKG_VERSION_ERROR}")
       
    54     endif()
       
    55 endif()
       
    56 
    35 include(FindPackageHandleStandardArgs)
    57 include(FindPackageHandleStandardArgs)
    36 find_package_handle_standard_args(GHC DEFAULT_MSG GHC_EXECUTABLE GHC_VERSION)
    58 find_package_handle_standard_args(GHC DEFAULT_MSG GHC_EXECUTABLE GHC_VERSION)
    37 mark_as_advanced(GHC_VERSION)
    59 mark_as_advanced(GHC_VERSION)
    38 
    60