forked from MarkSchofield/WindowsToolchain
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNinja.cmake
88 lines (79 loc) · 4.11 KB
/
Ninja.cmake
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
#----------------------------------------------------------------------------------------------------------------------
# MIT License
#
# Copyright (c) 2021 Mark Schofield
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#----------------------------------------------------------------------------------------------------------------------
#
# Downloads the Ninja Build executable from within a toolchain.
#
# The following variables can be used to configure the behavior of this file:
#
# | CMake Variable | Description |
# |-------------------------|---------------------------------------------------------------------------------------------------------------------------|
# | NINJA_VERSION | The version of Ninja to download - if it can't be found. Defaults to 1.10.2. |
# | NINJA_ARCHIVE_HASH | The hash of the Ninja archive, following the format of `string(<HASH>`. Defaults to the hash of the Ninja 1.10.2 archive. |
# | TOOLCHAIN_TOOLS_PATH | The path to download tools to. If not set, then tools will not be downloaded. |
include_guard()
if((NOT (CMAKE_GENERATOR STREQUAL Ninja)) AND (NOT (CMAKE_GENERATOR STREQUAL "Ninja Multi-Config")))
return()
endif()
if(NOT NINJA_VERSION)
set(NINJA_VERSION "1.10.2")
set(NINJA_ARCHIVE_HASH "SHA256=BBDE850D247D2737C5764C927D1071CBB1F1957DCABDA4A130FA8547C12C695F")
else()
if(NOT NINJA_ARCHIVE_HASH)
message(FATAL_ERROR "NINJA_VERSION is set to ${NINJA_VERSION}. NINJA_ARCHIVE_HASH must be set if NINJA_VERSION is set.")
endif()
endif()
find_program(NINJA_PATH
ninja ninja.exe
PATHS
${NINJA_PATH}
)
include("${CMAKE_CURRENT_LIST_DIR}/ToolchainCommon.cmake")
# If:
# 1. Ninja can't be found
# 2. TOOLCHAIN_TOOLS_PATH is set
# 3. CMAKE_MAKE_PROGRAM isn't specified, or it was specified and equal to where it would be downloaded to.
#
# Download and unpack ninja to TOOLCHAIN_TOOLS_PATH and set CMAKE_MAKE_PROGRAM to point to it.
if((NINJA_PATH STREQUAL "NINJA_PATH-NOTFOUND") AND TOOLCHAIN_TOOLS_PATH)
if(NOT IS_ABSOLUTE ${TOOLCHAIN_TOOLS_PATH})
message(WARNING "TOOLCHAIN_TOOLS_PATH is not an absolute path. This might result in an inconsistent behavior.")
endif()
set(NINJA_ARCHIVE_PATH "${TOOLCHAIN_TOOLS_PATH}/ninja.zip")
set(NINJA_PATH "${TOOLCHAIN_TOOLS_PATH}/ninja.exe")
if ((NOT CMAKE_MAKE_PROGRAM) OR (CMAKE_MAKE_PROGRAM STREQUAL NINJA_PATH))
toolchain_download_file(
URL "https://github.com/ninja-build/ninja/releases/download/v${NINJA_VERSION}/ninja-win.zip"
PATH ${NINJA_ARCHIVE_PATH}
EXPECTED_HASH ${NINJA_ARCHIVE_HASH}
)
if(${NINJA_ARCHIVE_PATH} IS_NEWER_THAN ${NINJA_PATH})
file(ARCHIVE_EXTRACT
INPUT ${NINJA_ARCHIVE_PATH}
DESTINATION ${TOOLCHAIN_TOOLS_PATH}
)
file(TOUCH_NOCREATE ${NINJA_PATH})
endif()
set(CMAKE_MAKE_PROGRAM ${NINJA_PATH} CACHE FILEPATH "" FORCE)
endif()
endif()