cmake_modules/CheckHaskellPackageExists.cmake
author Simon McVittie <smcv@debian.org>
Mon, 12 Sep 2022 10:40:53 -0400
branch1.0.0
changeset 15859 7b1d6dfa3173
parent 13291 31615a2e0db1
child 15700 a3d2f69f3ac1
permissions -rw-r--r--
Remove FindSDL2 find-module, use sdl2-config.cmake instead This requires SDL >= 2.0.4. Since <https://bugzilla.libsdl.org/show_bug.cgi?id=2464> was fixed in SDL 2.0.4, SDL behaves as a CMake "config-file package", even if it was not itself built using CMake: it installs a sdl2-config.cmake file to ${libdir}/cmake/SDL2, which tells CMake where to find SDL's headers and library, analogous to a pkg-config .pc file. As a result, we no longer need to copy/paste a "find-module package" to be able to find a system copy of SDL >= 2.0.4 with find_package(SDL2). Find-module packages are now discouraged by the CMake developers, in favour of having upstream projects behave as config-file packages. This results in a small API change: FindSDL2 used to set SDL2_INCLUDE_DIR and SDL2_LIBRARY, but the standard behaviour for config-file packages is to set <name>_INCLUDE_DIRS and <name>_LIBRARIES. Use the CONFIG keyword to make sure we search in config-file package mode, and will not find a FindSDL2.cmake in some other directory that implements the old interface. In addition to deleting redundant code, this avoids some assumptions in FindSDL2 about the layout of a SDL installation. The current libsdl2-dev package in Debian breaks those assumptions; this is considered a bug and will hopefully be fixed soon, but it illustrates how fragile these assumptions can be. We can be more robust against different installation layouts by relying on SDL's own CMake integration. When linking to a copy of CMake in a non-standard location, users can now set the SDL2_DIR or CMAKE_PREFIX_PATH environment variable to point to it; previously, these users would have used the SDL2DIR environment variable. This continues to be unnecessary if using matching system-wide installations of CMake and SDL2, for example both from Debian.
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
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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: 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")
13291
31615a2e0db1 CMake: Rework Haskell package detection, use ghc-pkg to detect packages
Wuzzy <Wuzzy2@mail.ru>
parents: 12113
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()