cmake_modules/FindGHC.cmake
author nemo
Sun, 29 Jul 2018 11:37:14 -0400
changeset 13570 5190d41a2440
parent 13291 31615a2e0db1
permissions -rw-r--r--
oh. and indent that loop
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8671
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
     1
# - Try to find the Glasgow Haskell Compiler executable
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
     2
# Once done this will define
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
     3
#
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
     4
#  GHC_VERSION        - GHC version
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
     5
#  GHC_EXECUTABLE     - GHC executable
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
     6
#  GHC_PKG_VERSION    - ghc-pkg version
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
     7
#  GHC_PKG_EXECUTABLE - ghc-pkg executable
8671
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
     8
#
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
     9
# Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com>
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    10
#
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    11
# Redistribution and use is allowed according to the terms of the BSD license.
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    12
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    13
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    14
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    15
find_program(GHC_EXECUTABLE
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    16
    NAMES ghc
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    17
    PATHS /opt/local/bin /usr/local/bin /usr/bin
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    18
    )
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    19
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    20
find_program(GHC_PKG_EXECUTABLE
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    21
    NAMES ghc-pkg
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    22
    PATHS /opt/local/bin /usr/local/bin /usr/bin
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    23
    )
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    24
8671
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    25
if (GHC_EXECUTABLE)
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents: 8671
diff changeset
    26
    # check ghc version
8671
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    27
    execute_process(COMMAND ${GHC_EXECUTABLE} -V
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    28
                    OUTPUT_VARIABLE GHC_VERSION_OUTPUT
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    29
                    ERROR_VARIABLE GHC_VERSION_ERROR
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    30
                    RESULT_VARIABLE GHC_VERSION_RESULT
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    31
                    OUTPUT_STRIP_TRAILING_WHITESPACE
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    32
                    )
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    33
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    34
    if(${GHC_VERSION_RESULT} EQUAL 0)
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    35
        string(REGEX MATCH "([0-9]+)" GHC_VERSION ${GHC_VERSION_OUTPUT})
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    36
    else()
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    37
        message(SEND_ERROR "Command \"${GHC_EXECUTABLE} -V\" failed with output: ${GHC_VERSION_ERROR}")
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    38
    endif()
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    39
endif()
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    40
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    41
if (GHC_PKG_EXECUTABLE)
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    42
    # check ghc-pkg version
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    43
    execute_process(COMMAND ${GHC_PKG_EXECUTABLE} -V
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    44
                    OUTPUT_VARIABLE GHC_PKG_VERSION_OUTPUT
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    45
                    ERROR_VARIABLE GHC_PKG_VERSION_ERROR
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    46
                    RESULT_VARIABLE GHC_PKG_VERSION_RESULT
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    47
                    OUTPUT_STRIP_TRAILING_WHITESPACE
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    48
                    )
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    49
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    50
    if(${GHC_PKG_VERSION_RESULT} EQUAL 0)
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    51
        string(REGEX MATCH "([0-9]+)" GHC_PKG_VERSION ${GHC_PKG_VERSION_OUTPUT})
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    52
    else()
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    53
        message(SEND_ERROR "Command \"${GHC_PKG_EXECUTABLE} -V\" failed with output: ${GHC_PKG_VERSION_ERROR}")
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    54
    endif()
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    55
endif()
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 10109
diff changeset
    56
8671
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    57
include(FindPackageHandleStandardArgs)
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    58
find_package_handle_standard_args(GHC DEFAULT_MSG GHC_EXECUTABLE GHC_VERSION)
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    59
mark_as_advanced(GHC_VERSION)
a9957b7797f3 write FindGHC.cmake for haskell stuff
koda
parents:
diff changeset
    60