summaryrefslogtreecommitdiff
path: root/cmake/deps-helper.cmake
blob: f37ccb1f2d082690fca427c4e77809c25a3003c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
###############################################################################
# Top contributors (to current version):
#   Gereon Kremer
#
# This file is part of the cvc5 project.
#
# Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
# in the top-level source directory and their institutional affiliations.
# All rights reserved.  See the file COPYING in the top-level source
# directory for licensing information.
# #############################################################################
#
# Defines some initial setup for building the dependencies (paths and default
# options for external projects) and some helper functions and macros that are
# used in the custom FindX.cmake scripts.
##

# where to build dependencies
set(DEPS_PREFIX "${CMAKE_BINARY_DIR}/deps")
# base path to installed dependencies
set(DEPS_BASE "${CMAKE_BINARY_DIR}/deps")
# CMake wants directories specified via INTERFACE_INCLUDE_DIRECTORIES
# (and similar) to exist when target property is set.
file(MAKE_DIRECTORY "${DEPS_BASE}/include/")

set(COMMON_EP_CONFIG
    PREFIX ${DEPS_PREFIX}
    LOG_DOWNLOAD ON
    LOG_UPDATE ON
    LOG_CONFIGURE ON
    LOG_BUILD ON
    LOG_INSTALL ON
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.14")
    set(COMMON_EP_CONFIG ${COMMON_EP_CONFIG}
        LOG_PATCH ON
        LOG_MERGED_STDOUTERR ON
        LOG_OUTPUT_ON_FAILURE ON
    )
endif()

macro(check_auto_download name disable_option)
    if(NOT ENABLE_AUTO_DOWNLOAD)
        if (${name}_FIND_VERSION)
            set(depname "${name} (>= ${${name}_FIND_VERSION})")
        else()
            set(depname "${name}")
        endif()
        if("${disable_option}" STREQUAL "")
            message(FATAL_ERROR "Could not find the required dependency \
${depname} in the system. Please install it yourself or use --auto-download to \
let us download and build it for you.")
        else()
            message(FATAL_ERROR "Could not find the optional dependency \
${depname} in the system. You can disable this dependency with \
${disable_option}, install it yourself or use --auto-download to let us \
download and build it for you.")
        endif()
    endif()
endmacro(check_auto_download)

# Check if the given external project was already set up in a previous
# configure call.
macro(check_ep_downloaded name)
  if(EXISTS "${DEPS_PREFIX}/src/${name}")
    set(${name}_DOWNLOADED TRUE)
  else()
    set(${name}_DOWNLOADED FALSE)
  endif()
endmacro()

macro(check_system_version name)
    # find_package sets this variable when called with a version
    # https://cmake.org/cmake/help/latest/command/find_package.html#version-selection
    # we ignore the EXACT option and version ranges here
    if (${name}_FIND_VERSION)
        if(${name}_VERSION VERSION_LESS ${name}_FIND_VERSION)
            message(VERBOSE "System version for ${name} has incompatible \
version: required ${${name}_FIND_VERSION} but found ${${name}_VERSION}")
            set(${name}_FOUND_SYSTEM FALSE)
        endif()
    endif()
endmacro(check_system_version)

# fail if we are cross compiling as indicated by name and processor
# we are cross compiling if
# - CMAKE_SYSTEM_NAME has been changed to ${name}
# - CMAKE_SYSTEM_PROCESSOR has been changed to ${processor}
function(check_if_cross_compiling OUT name processor)
    if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}")
        if(NOT "${name}" STREQUAL "")
            if("${CMAKE_SYSTEM_NAME}" STREQUAL "${name}")
                set(${OUT} TRUE PARENT_SCOPE)
                return()
            endif()
        endif()
    endif()
    if(NOT "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}")
        if(NOT "${processor}" STREQUAL "")
            if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "${processor}")
                set(${OUT} TRUE PARENT_SCOPE)
                return()
            endif()
        endif()
    endif()
    set(${OUT} FALSE PARENT_SCOPE)
endfunction(check_if_cross_compiling)

# fail if we are cross compiling as indicated by name and processor
# we are cross compiling if
# - CMAKE_SYSTEM_NAME has been changed to ${name}
# - CMAKE_SYSTEM_PROCESSOR has been changed to ${processor}
function(fail_if_cross_compiling name processor target error)
    check_if_cross_compiling(FAIL "${name}" "${processor}")
    if(FAIL)
        message(SEND_ERROR
        "We are cross compiling from \
${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR} to \
${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}.\n"
        "This is not supported by ${target}:\n"
        "${error}")
    endif()
endfunction(fail_if_cross_compiling)

function(fail_if_include_missing include target)
    include(CheckIncludeFileCXX)
    check_include_file_cxx(${include} HAVE_INCLUDE)
    if(NOT HAVE_INCLUDE)
        message(SEND_ERROR "${target} requires ${include} header, but it is not available.")
    endif()
endfunction(fail_if_include_missing)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback