cmake_modules/FindGHC.cmake
author Simon McVittie <smcv@debian.org>
Mon, 12 Sep 2022 10:40:53 -0400
branch1.0.0
changeset 15859 7b1d6dfa3173
parent 13291 31615a2e0db1
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:
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