-
Notifications
You must be signed in to change notification settings - Fork 1
/
Build.cmake
209 lines (181 loc) · 6.25 KB
/
Build.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# ReDefine build script
# Based on FOClassic setup
cmake_minimum_required( VERSION 3.7.2 FATAL_ERROR )
#> AutomatedBuild.cmake <#
# Prepare build directory
function( CreateBuildDirectory dir generator platform tool file )
# use full path
file( TO_CMAKE_PATH "${CMAKE_CURRENT_LIST_DIR}/${dir}" dir )
file( TO_NATIVE_PATH "${dir}" dir_native )
message( STATUS "Checking ${dir_native}" )
if( NOT EXISTS "${dir}" )
message( STATUS "Creating ${dir_native}" )
file( MAKE_DIRECTORY "${dir}" )
endif()
if( NOT EXISTS "${dir}/${file}" )
if( UNIX AND tool )
set( info ", toolchain: ${tool}" )
set( toolchain -DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_LIST_DIR}/Misc/CMake/${tool}.cmake )
elseif( WIN32 AND tool )
set( info ", toolset: ${tool}" )
set( toolset -T ${tool} )
endif()
if( platform )
string( APPEND info ", platform: ${platform}" )
set( platform -A ${platform} )
endif()
message( STATUS "Starting generator (${generator}${info})" )
execute_process(
COMMAND ${CMAKE_COMMAND} ${toolchain} -G "${generator}" ${platform} ${toolset} -S "${CMAKE_CURRENT_LIST_DIR}/Source"
RESULT_VARIABLE result
WORKING_DIRECTORY "${dir}"
)
if( NOT result EQUAL 0 )
list( APPEND BUILD_FAIL "${dir}" )
set( BUILD_FAIL "${BUILD_FAIL}" PARENT_SCOPE )
return()
endif()
endif()
if( EXISTS "${dir}/${file}" )
list( APPEND BUILD_DIRS "${dir}" )
set( BUILD_DIRS "${BUILD_DIRS}" PARENT_SCOPE )
else()
list( APPEND BUILD_FAIL "${dir}" )
set( BUILD_FAIL "${BUILD_FAIL}" PARENT_SCOPE )
endif()
endfunction()
function( RunAllBuilds )
foreach( dir IN LISTS BUILD_DIRS )
file( TO_NATIVE_PATH "${dir}" dir_native )
message( STATUS "Starting build (${dir_native})" )
execute_process(
COMMAND ${CMAKE_COMMAND} --build "${dir}" --config Release
RESULT_VARIABLE result
)
if( NOT result EQUAL 0 )
list( APPEND BUILD_FAIL "${dir}" )
set( BUILD_FAIL "${BUILD_FAIL}" PARENT_SCOPE )
endif()
endforeach()
endfunction()
#> FormatSource.cmake <#
function( FormatSource filename )
if( NOT EXISTS "${filename}" )
return()
endif()
set( root "." )
set( uncrustemp "${root}/FormatSource.tmp" )
set( uncrustify "${root}/Misc/SourceTools/uncrustify" )
set( uncrustcfg "${root}/Misc/SourceTools/uncrustify.cfg" )
if( UNCRUSTIFY_EXECUTABLE )
set( uncrustify "${UNCRUSTIFY_EXECUTABLE}" )
endif()
# CMAKE_EXECUTABLE_SUFFIX is not reliable
if( WIN32 AND NOT "${uncrustify}" MATCHES "\.[Ee][Xx][Ee]$" )
string( APPEND uncrustify ".exe" )
endif()
# in case of cancelled FormatSource runs
if( EXISTS "${uncrustemp}" )
file( REMOVE "${uncrustemp}" )
endif()
if( EXISTS "${uncrustify}" )
execute_process( COMMAND "${uncrustify}" -c "${uncrustcfg}" -l CPP -f "${filename}" -o "${uncrustemp}" -q --if-changed )
if( EXISTS "${uncrustemp}" )
file( RENAME "${uncrustemp}" "${filename}" )
endif()
endif()
endfunction()
#> ReDefine <#
if( DEFINED ENV{CI} )
# AppVeyor
if( DEFINED ENV{APPVEYOR_BUILD_WORKER_IMAGE} )
if( UNIX AND "$ENV{PLATFORM}" STREQUAL "x32" )
set( BUILD_TOOL "Linux32" )
elseif( UNIX AND "$ENV{PLATFORM}" STREQUAL "x64" )
elseif( WIN32 AND "$ENV{PLATFORM}" STREQUAL "x32" )
elseif( WIN32 AND "$ENV{PLATFORM}" STREQUAL "x64" )
set( BUILD_GENERATOR_SUFFIX " Win64" )
else()
message( FATAL_ERROR "Unknown platform : $ENV{PLATFORM}" )
endif()
if( "$ENV{APPVEYOR_BUILD_WORKER_IMAGE}" MATCHES "^Ubuntu" )
set( BUILD_FILE "Makefile" )
set( BUILD_GENERATOR "Unix Makefiles" )
elseif( "$ENV{APPVEYOR_BUILD_WORKER_IMAGE}" STREQUAL "Visual Studio 2017" )
set( BUILD_FILE "ReDefine.sln" )
set( BUILD_GENERATOR "Visual Studio 15 2017${BUILD_GENERATOR_SUFFIX}" )
else()
message( FATAL_ERROR "Unknown AppVeyor image ('$ENV{APPVEYOR_BUILD_WORKER_IMAGE}')" )
endif()
elseif( DEFINED ENV{GITHUB_ACTIONS} )
if( UNIX AND "$ENV{MATRIX_PLATFORM}" STREQUAL "x32" )
set( BUILD_TOOL "Linux32" )
elseif( UNIX AND "$ENV{MATRIX_PLATFORM}" STREQUAL "x64" )
elseif( WIN32 AND "$ENV{MATRIX_PLATFORM}" STREQUAL "x32" )
elseif( WIN32 AND "$ENV{MATRIX_PLATFORM}" STREQUAL "x64" )
set( BUILD_GENERATOR_SUFFIX " Win64" )
else()
message( FATAL_ERROR "Unknown platform : $ENV{MATRIX_PLATFORM}" )
endif()
if( "$ENV{MATRIX_OS}" MATCHES "^ubuntu-" )
set( BUILD_FILE "Makefile" )
set( BUILD_GENERATOR "Unix Makefiles" )
elseif( "$ENV{MATRIX_OS}" STREQUAL "windows-2016" )
set( BUILD_FILE "ReDefine.sln" )
set( BUILD_GENERATOR "Visual Studio 15 2017${BUILD_GENERATOR_SUFFIX}" )
elseif( "$ENV{MATRIX_OS}" STREQUAL "windows-2019" OR "$ENV{MATRIX_OS}" STREQUAL "windows-latest" )
set( BUILD_FILE "ReDefine.sln" )
set( BUILD_GENERATOR "Visual Studio 16 2019" )
if( "$ENV{MATRIX_PLATFORM}" STREQUAL "x32" )
set( BUILD_PLATFORM "Win32" )
elseif( "$ENV{MATRIX_PLATFORM}" STREQUAL "x64" )
set( BUILD_PLATFORM "x64" )
else()
message( FATAL_ERROR "Unknown platform ('$ENV{MATRIX_PLATFORM}')" )
endif()
else()
message( FATAL_ERROR "Unknown GitHub Actions image ('$ENV{MATRIX_OS}')" )
endif()
else()
message( FATAL_ERROR "Unknown CI" )
endif()
elseif( UNIX )
set( BUILD_FILE "Makefile" )
set( BUILD_GENERATOR "Unix Makefiles" )
# set( BUILD_TOOL "Linux32" )
elseif( WIN32 )
if( MINGW )
set( BUILD_FILE "Makefile" )
set( BUILD_GENERATOR "MinGW Makefiles" )
else()
set( BUILD_FILE "ReDefine.sln" )
set( BUILD_GENERATOR "Visual Studio 16 2019" )
endif()
endif()
FormatSource( "Source/Defines.cpp" )
FormatSource( "Source/Functions.cpp" )
FormatSource( "Source/Log.cpp" )
FormatSource( "Source/Main.cpp" )
FormatSource( "Source/Operators.cpp" )
FormatSource( "Source/Parser.cpp" )
FormatSource( "Source/Parser.h" )
FormatSource( "Source/Raw.cpp" )
FormatSource( "Source/ReDefine.cpp" )
FormatSource( "Source/ReDefine.h" )
FormatSource( "Source/Script.cpp" )
FormatSource( "Source/Text.cpp" )
FormatSource( "Source/Variables.cpp" )
FormatSource( "Source/Executable/CommandLine.cpp" )
FormatSource( "Source/Executable/CommandLine.h" )
FormatSource( "Source/Executable/Main.cpp" )
if( NOT BUILD_DIR )
set( BUILD_DIR "Build" )
endif()
CreateBuildDirectory( "${BUILD_DIR}" "${BUILD_GENERATOR}" "${BUILD_PLATFORM}" "${BUILD_TOOL}" "${BUILD_FILE}" )
if( BUILD_FAIL )
message( FATAL_ERROR "Build error" )
endif()
RunAllBuilds()
if( BUILD_FAIL )
message( FATAL_ERROR "Build error" )
endif()