cmake_modules/FindClang.cmake
author Simon McVittie <smcv@debian.org>
Mon, 12 Sep 2022 10:40:53 -0400
branch1.0.0
changeset 15859 7b1d6dfa3173
parent 9246 75f430ebeb74
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:
9246
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
     1
# - Try to find the Clang/LLVM executable
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
     2
# Once done this will define
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
     3
#
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
     4
#  CLANG_FOUND       - system has Clang
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
     5
#  CLANG_VERSION     - Clang version
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
     6
#  CLANG_EXECUTABLE  - Clang executable
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
     7
#
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
     8
# Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com>
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
     9
#
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    10
# Redistribution and use is allowed according to the terms of the BSD license.
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    11
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    12
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    13
find_program(CLANG_EXECUTABLE
8450
404ddce27b23 add support for clang 3.3 (although there has to be a better way for this) and output right version number
koda
parents: 8113
diff changeset
    14
        NAMES clang-mp-3.3 clang-mp-3.2 clang-mp-3.1 clang-mp-3.0 clang
8109
b5cd8cad2d86 Move code for Clang to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
    15
        PATHS /opt/local/bin /usr/local/bin /usr/bin)
9246
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    16
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    17
if (CLANG_EXECUTABLE)
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    18
    execute_process(COMMAND ${CLANG_EXECUTABLE} --version
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    19
                    OUTPUT_VARIABLE CLANG_VERSION_OUTPUT
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    20
                    ERROR_VARIABLE CLANG_VERSION_ERROR
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    21
                    RESULT_VARIABLE CLANG_VERSION_RESULT
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    22
                    OUTPUT_STRIP_TRAILING_WHITESPACE
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    23
                    )
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    24
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    25
    if(${CLANG_VERSION_RESULT} EQUAL 0)
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    26
        string(REGEX MATCH "[0-9]+\\.[0-9]+" CLANG_VERSION "${CLANG_VERSION_OUTPUT}")
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    27
        string(REGEX REPLACE "([0-9]+\\.[0-9]+)" "\\1" CLANG_VERSION "${CLANG_VERSION}")
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    28
    else()
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    29
        message(SEND_ERROR "Command \"${CLANG_EXECUTABLE} --version\" failed with output: ${CLANG_VERSION_ERROR}")
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    30
    endif()
8113
0ad9c42dca7c Refactor Clang module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8111
diff changeset
    31
endif()
8109
b5cd8cad2d86 Move code for Clang to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
    32
9246
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    33
include(FindPackageHandleStandardArgs)
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    34
find_package_handle_standard_args(Clang DEFAULT_MSG CLANG_EXECUTABLE CLANG_VERSION)
75f430ebeb74 new FindClang.cmake
koda
parents: 9133
diff changeset
    35
mark_as_advanced(CLANG_VERSION)
8109
b5cd8cad2d86 Move code for Clang to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
    36