cmake_modules/CheckHaskellPackageExists.cmake
author Wuzzy <Wuzzy2@mail.ru>
Wed, 15 May 2019 03:56:00 +0200
changeset 14957 8e4e508d153c
parent 13296 31615a2e0db1
permissions -rw-r--r--
Use HaltFatalError for all VideoRec failures
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
     1
# Checks if a given Haskell package exists (using ghc-pkg)
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
     2
# and fails if it's missing.
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
     3
# Loosely based on CheckLibraryExists.cmake from CMake.
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     4
#=============================================================================
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     5
# Copyright 2002-2009 Kitware, Inc.
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     6
#
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     7
# Distributed under the OSI-approved BSD License
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     8
#
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
     9
# This software is distributed WITHOUT ANY WARRANTY; without even the
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    10
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    11
# See the License for more information.
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    12
#=============================================================================
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    13
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    14
macro(CHECK_HASKELL_PACKAGE_EXISTS PACKAGE MODULE FUNCTION PARAMCOUNT)
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    15
# NOTE: MODULE, FUNCTION and PARAMCOUNT are curretly ignored.
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    16
# TODO: Either implement these or drop?
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    17
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    18
  set(VARIABLE "HS_PACKAGE_${PACKAGE}")
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    19
  if(NOT (${VARIABLE} EQUAL "1"))
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    20
    message(STATUS "Looking for Haskell package ${PACKAGE} ...")
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    21
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    22
    execute_process(COMMAND ${GHC_PKG_EXECUTABLE}
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    23
                    "latest"
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    24
                    ${PACKAGE}
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    25
                    "--simple-output"
10723
2cfa65083621 Use ghc return value instead of looking for the stderr, do not throw error when an haskell module throws a build failure, e.g. because of false positives like this one (debian/arm*)
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10109
diff changeset
    26
                    RESULT_VARIABLE COMMAND_RESULT
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    27
                    ERROR_VARIABLE BUILD_ERROR
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    28
                    OUTPUT_STRIP_TRAILING_WHITESPACE
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    29
                    OUTPUT_QUIET
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    30
                    )
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    31
10723
2cfa65083621 Use ghc return value instead of looking for the stderr, do not throw error when an haskell module throws a build failure, e.g. because of false positives like this one (debian/arm*)
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10109
diff changeset
    32
    if(${COMMAND_RESULT} EQUAL 0)
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    33
      message(STATUS "Looking for Haskell package ${PACKAGE} - found")
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    34
      set(${VARIABLE} "1" CACHE INTERNAL "Have package ${PACKAGE}")
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    35
      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    36
        "Determining if the Haskell package ${PACKAGE} exists has passed\n\n")
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    37
    else()
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    38
      message(STATUS "Looking for Haskell package ${PACKAGE} - not found")
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    39
      set(${VARIABLE} "0" CACHE INTERNAL "Have package ${PACKAGE}")
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    40
      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    41
        "Determining if the Haskell package ${PACKAGE} "
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    42
        "exists failed with the following output:\n"
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    43
        "${BUILD_ERROR}\n\n")
13296
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12118
diff changeset
    44
      message(FATAL_ERROR "Haskell package '${PACKAGE}' required")
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    45
    endif()
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    46
  endif()
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    47
endmacro()