-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
153 lines (138 loc) · 5.48 KB
/
CMakeLists.txt
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Clone and build the llvm-mos compiler, linker and assembler
# cmake 3.15 permits us to build multiple targets in one go
cmake_minimum_required(VERSION 3.15)
project(build-llvm-mos-compiler-dist
LANGUAGES C CXX)
# Set constants
if(NOT DEFINED LLVM_MOS_GIT_URL)
set(LLVM_MOS_GIT_URL https://github.com/llvm-mos/llvm-mos.git
CACHE STRING "URL of git repository containing the llvm-mos compilers")
endif()
if(NOT DEFINED LLVM_MOS_GIT_TAG)
set(LLVM_MOS_GIT_TAG main
CACHE STRING "Tag, branch or hash of git repository to pull")
endif()
if(NOT DEFINED LLVM_MOS_GIT_RELEASE_SLUG)
set(LLVM_MOS_RELEASE_SLUG ${LLVM_MOS_GIT_TAG}
CACHE STRING "The short, human-readable, no-slashes name of the release to create (i.e. feature-do-linking)")
endif()
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE MinSizeRel
CACHE STRING "Build type for compilers")
endif()
set(LLVM_MOS_CMAKE_CACHE_FILE clang/cmake/caches/MOS.cmake
CACHE STRING "Path from root of project to the MOS cmake cache file")
set(LLVM_MOS_GH_RELEASE_CREATE_FLAGS --prerelease
CACHE STRING "Flags to pass to Github CLI's release create command")
set(LLVM_MOS_TEST_SUITE_ENABLED No
CACHE BOOL "Should this build run the test suite for the llvm-mos compilers?")
set(LLVM_MOS_TEST_SUITE_TARGET check-llvm
CACHE STRING "The target to cmake in order to test")
set(LLVM_MOS_INSTALL_SUBPATH dist/llvm-mos)
set(LLVM_MOS_TEST_SUITE_DISABLED (NOT ${LLVM_MOS_TEST_SUITE_ENABLED}))
# Find whatever local host compiler we have
include(CMakeDetermineCXXCompiler)
# Make adjustments for MSVC
set(LLVM_MOS_C_FLAGS "")
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
list(APPEND LLVM_MOS_C_FLAGS /FS)
list(REMOVE_DUPLICATES LLVM_MOS_C_FLAGS)
endif()
include(ExternalProject)
set(LLVM_MOS_CMAKE_ARGS
-C <SOURCE_DIR>/${LLVM_MOS_CMAKE_CACHE_FILE}
<SOURCE_DIR>/llvm
-DCMAKE_C_FLAGS:STRING=${LLVM_MOS_C_FLAGS}
-DCMAKE_CXX_FLAGS:STRING=${LLVM_MOS_C_FLAGS}
)
# Any Windows specific flags go here
if (WIN32)
list(APPEND LLVM_MOS_CMAKE_ARGS "")
list(REMOVE_DUPLICATES LLVM_MOS_CMAKE_ARGS)
endif()
set(LLVM_MOS_CMAKE_CACHE_ARGS "")
# Download and build the llvm-mos compiler
ExternalProject_Add( build
GIT_REPOSITORY ${LLVM_MOS_GIT_URL}
GIT_TAG ${LLVM_MOS_GIT_TAG}
GIT_PROGRESS 1
GIT_SHALLOW 0
CMAKE_ARGS ${LLVM_MOS_CMAKE_ARGS}
CMAKE_CACHE_ARGS ${LLVM_MOS_CMAKE_CACHE_ARGS}
-DCMAKE_INSTALL_PREFIX:STRING=<INSTALL_DIR>/${LLVM_MOS_INSTALL_SUBPATH}
INSTALL_COMMAND cmake -E echo "Skipping install step"
COMMAND cmake --build . --target install
TEST_COMMAND cmake --build . --target ${LLVM_MOS_TEST_SUITE_TARGET}
TEST_AFTER_INSTALL YES
TEST_EXCLUDE_FROM_MAIN ${LLVM_MOS_TEST_SUITE_DISABLED}
USES_TERMINAL_DOWNLOAD 1
USES_TERMINAL_UPDATE 1
USES_TERMINAL_CONFIGURE 1
USES_TERMINAL_BUILD 1
USES_TERMINAL_INSTALL 1
USES_TERMINAL_TEST 1
)
ExternalProject_Get_Property(build INSTALL_DIR)
ExternalProject_Get_Property(build SOURCE_DIR)
string(TOLOWER ${CMAKE_SYSTEM_NAME} LLVM_MOS_PLATFORM_NAME)
set(LLVM_MOS_INSTALL_DIR ${INSTALL_DIR}/${LLVM_MOS_INSTALL_SUBPATH})
set(LLVM_MOS_SOURCE_DIR ${SOURCE_DIR})
set(LLVM_MOS_RELEASE_NAME llvm-mos-${LLVM_MOS_PLATFORM_NAME}-${LLVM_MOS_RELEASE_SLUG})
if (WIN32)
set(LLVM_MOS_PACKAGE_PATH
${LLVM_MOS_INSTALL_DIR}/../../${LLVM_MOS_RELEASE_NAME}.7z)
find_program(LLVM_MOS_7Z 7z REQUIRED)
set(package_command ${LLVM_MOS_7Z} a ${LLVM_MOS_PACKAGE_PATH} llvm-mos)
else()
set(LLVM_MOS_PACKAGE_PATH
${LLVM_MOS_INSTALL_DIR}/../../${LLVM_MOS_RELEASE_NAME}.tar.xz)
find_program(LLVM_MOS_TAR tar REQUIRED)
set(package_command ${LLVM_MOS_TAR} -cJvf ${LLVM_MOS_PACKAGE_PATH} llvm-mos)
endif()
add_custom_target(package
COMMAND ${CMAKE_COMMAND} -E copy ${LLVM_MOS_SOURCE_DIR}/llvm/LICENSE.TXT ${LLVM_MOS_INSTALL_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${LLVM_MOS_SOURCE_DIR}/NOTICE ${LLVM_MOS_INSTALL_DIR}
COMMAND ${package_command}
WORKING_DIRECTORY ${LLVM_MOS_INSTALL_DIR}/..
BYPRODUCTS ${LLVM_MOS_PACKAGE_PATH}
COMMENT Compressing release package ${LLVM_MOS_PACKAGE_PATH}
DEPENDS build
)
find_program(LLVM_MOS_GIT git REQUIRED)
find_program(LLVM_MOS_GH gh REQUIRED)
string(TIMESTAMP LLVM_MOS_DATE_TIME UTC)
add_custom_target(ship
# Ignore the gh release command if it fails by throwing in a git command
# that always succeeds.
COMMAND
cd
COMMAND
${LLVM_MOS_GH} release delete ${LLVM_MOS_RELEASE_NAME} -y ||
echo "No previous release ${LLVM_MOS_RELEASE_NAME} to delete"
COMMAND
git push --delete origin ${LLVM_MOS_RELEASE_NAME} ||
echo "No previous tag ${LLVM_MOS_RELEASE_NAME} to delete"
COMMAND
echo "This is an automated build of the ${LLVM_MOS_RELEASE_SLUG} branch for ${CMAKE_SYSTEM_NAME}." > git.log
COMMAND
echo "Repository: ${LLVM_MOS_GIT_URL}" >> git.log
COMMAND
echo "Branch: ${LLVM_MOS_RELEASE_SLUG}" >> git.log
COMMAND
echo "Tag: ${LLVM_MOS_GIT_TAG}" >> git.log
COMMAND
echo "Target: ${CMAKE_SYSTEM_NAME}" >> git.log
COMMAND
echo "Time: ${LLVM_MOS_DATE_TIME}" >> git.log
COMMAND
${LLVM_MOS_GH} release create
${LLVM_MOS_RELEASE_NAME}
--notes-file git.log
--title ${LLVM_MOS_RELEASE_NAME}
--target ${LLVM_MOS_GIT_TAG}
${LLVM_MOS_GH_RELEASE_CREATE_FLAGS}
${LLVM_MOS_PACKAGE_PATH}
DEPENDS package
WORKING_DIRECTORY ${LLVM_MOS_SOURCE_DIR}
COMMENT Compressing release package ${LLVM_MOS_PACKAGE_PATH}
)