cmake_modules/CheckHaskellPackageExists.cmake
author unC0Rr
Wed, 04 Sep 2024 14:54:34 +0200
branchtransitional_engine
changeset 16031 1b1d5729ff3e
parent 15700 a3d2f69f3ac1
permissions -rw-r--r--
Fix test to match new yaml structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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: 12113
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: 12113
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
15700
a3d2f69f3ac1 Description: Make the new network-bsd package optional, by implementing the keyword REQUIRED in the check_haskell_package_exists macro
Gianfranco Costamagna <locutusofborg@debian.org>
parents: 13291
diff changeset
    14
macro(CHECK_HASKELL_PACKAGE_EXISTS PACKAGE MODULE FUNCTION PARAMCOUNT REQUIRED)
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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: 12113
diff changeset
    16
# TODO: Either implement these or drop?
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    17
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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: 12113
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: 12113
diff changeset
    20
    message(STATUS "Looking for Haskell package ${PACKAGE} ...")
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    21
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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: 12113
diff changeset
    23
                    "latest"
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
diff changeset
    24
                    ${PACKAGE}
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
diff changeset
    29
                    OUTPUT_QUIET
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    30
                    )
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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)
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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: 12113
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
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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()
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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: 12113
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
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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: 12113
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")
15700
a3d2f69f3ac1 Description: Make the new network-bsd package optional, by implementing the keyword REQUIRED in the check_haskell_package_exists macro
Gianfranco Costamagna <locutusofborg@debian.org>
parents: 13291
diff changeset
    44
      if("${REQUIRED}" STREQUAL "REQUIRED")
a3d2f69f3ac1 Description: Make the new network-bsd package optional, by implementing the keyword REQUIRED in the check_haskell_package_exists macro
Gianfranco Costamagna <locutusofborg@debian.org>
parents: 13291
diff changeset
    45
        message(FATAL_ERROR "Haskell package '${PACKAGE}' required")
a3d2f69f3ac1 Description: Make the new network-bsd package optional, by implementing the keyword REQUIRED in the check_haskell_package_exists macro
Gianfranco Costamagna <locutusofborg@debian.org>
parents: 13291
diff changeset
    46
      else()
a3d2f69f3ac1 Description: Make the new network-bsd package optional, by implementing the keyword REQUIRED in the check_haskell_package_exists macro
Gianfranco Costamagna <locutusofborg@debian.org>
parents: 13291
diff changeset
    47
        message(STATUS "Haskell package '${PACKAGE}' optionally required, but not found")
a3d2f69f3ac1 Description: Make the new network-bsd package optional, by implementing the keyword REQUIRED in the check_haskell_package_exists macro
Gianfranco Costamagna <locutusofborg@debian.org>
parents: 13291
diff changeset
    48
      endif()
10109
91d126fbd7bd CMake checks for haskell modules needed
unc0rr
parents:
diff changeset
    49
    endif()
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
endmacro()