|
1
|
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) |
|
2
|
|
|
3
|
project(fossil C) |
|
4
|
include(ExternalProject) |
|
5
|
|
|
6
|
set(CMAKE_VERBOSE_MAKEFILE ON) |
|
7
|
|
|
8
|
|
|
9
|
set(default_build_type "RelWithDebInfo") |
|
10
|
|
|
11
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
|
12
|
message(STATUS "Setting build type to '${default_build_type}' as none was specified.") |
|
13
|
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE |
|
14
|
STRING "Choose the type of build." FORCE) |
|
15
|
# Set the possible values of build type for cmake-gui |
|
16
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS |
|
17
|
"Debug" "Release" "MinSizeRel" "RelWithDebInfo") |
|
18
|
else() |
|
19
|
message(STATUS "'${CMAKE_BUILD_TYPE}' build type") |
|
20
|
endif() |
|
21
|
|
|
22
|
set(isDebugBuild FALSE) |
|
23
|
if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]" ) |
|
24
|
set(isDebugBuild TRUE) |
|
25
|
endif() |
|
26
|
|
|
27
|
## VARIABLES --------------------------------------------------------------- |
|
28
|
## Additional parameters can be passed in the following variables which can |
|
29
|
## be defined on cmake command line (or in cache). |
|
30
|
## |
|
31
|
## The parameters correspond to the ones used in the external fossil build |
|
32
|
## process (as specified at configure, make, and make test) |
|
33
|
## |
|
34
|
if(FOSSIL_CONFIGURE) |
|
35
|
message(STATUS "Fossil build configuration '${FOSSIL_CONFIGURE}'") |
|
36
|
set(configure_FLAGS ${FOSSIL_CONFIGURE}) |
|
37
|
endif() |
|
38
|
|
|
39
|
if(FOSSIL_BUILD) |
|
40
|
message(STATUS "Fossil build variables '${FOSSIL_BUILD}'") |
|
41
|
set(build_FLAGS ${FOSSIL_BUILD}) |
|
42
|
endif() |
|
43
|
|
|
44
|
if(FOSSIL_TEST) |
|
45
|
message(STATUS "Fossil test configuration '${FOSSIL_TEST}'") |
|
46
|
set(test_FLAGS ${FOSSIL_TEST}) |
|
47
|
endif() |
|
48
|
|
|
49
|
|
|
50
|
add_executable(fossil-exe IMPORTED) |
|
51
|
|
|
52
|
set(fossil_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
|
53
|
set(fossil_EXE_DIR "${fossil_INSTALL_DIR}/bin") |
|
54
|
set(fossil_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
|
55
|
set(fossil_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/fossil) |
|
56
|
if(MSVC) |
|
57
|
set(fossil_BUILD_DIR ${fossil_BINARY_DIR}/msvcbld) |
|
58
|
else(MSVC) |
|
59
|
set(fossil_BUILD_DIR ${fossil_BINARY_DIR}/bld) |
|
60
|
endif(MSVC) |
|
61
|
set(fossil_TEST_DIR "${fossil_BINARY_DIR}/test") |
|
62
|
|
|
63
|
set(EXE ${CMAKE_EXECUTABLE_SUFFIX}) |
|
64
|
set(fossil_EXE "${fossil_EXE_DIR}/fossil${EXE}") |
|
65
|
file(TO_NATIVE_PATH "${fossil_EXE}" fossil_EXE) |
|
66
|
set_target_properties(fossil-exe PROPERTIES |
|
67
|
IMPORTED_LOCATION "${fossil_EXE}" |
|
68
|
) |
|
69
|
|
|
70
|
## SETUP IDE --------------------------------------------------------------- |
|
71
|
## Setup Project Sources View |
|
72
|
## Add more source files for convenience; otherwise only actual dependencies |
|
73
|
## would appear in the Projects tree pane. |
|
74
|
## |
|
75
|
file(GLOB_RECURSE project_sources_DIRS |
|
76
|
#"autosetup/*" #may be useful when debuging configure |
|
77
|
"skins/*" |
|
78
|
"src/*" |
|
79
|
"test/*.test" "test/tester.tcl" |
|
80
|
"win/*" |
|
81
|
"www/*.wiki" "www/*.md" "www/*.html" |
|
82
|
) |
|
83
|
|
|
84
|
file(GLOB project_sources_FILES |
|
85
|
"auto.def" |
|
86
|
"configure" |
|
87
|
"Makefile.in" |
|
88
|
|
|
89
|
"fossil.1" |
|
90
|
"manifest.uuid" |
|
91
|
"VERSION" |
|
92
|
|
|
93
|
"${fossil_BINARY_DIR}/autoconfig.h" |
|
94
|
"${fossil_BINARY_DIR}/Makefile*" |
|
95
|
|
|
96
|
"${fossil_BUILD_DIR}/*.[h]" |
|
97
|
#"${fossil_BUILD_DIR}/main_.c" |
|
98
|
) |
|
99
|
|
|
100
|
include_directories( |
|
101
|
"${fossil_BUILD_DIR}" |
|
102
|
"${fossil_BINARY_DIR}" |
|
103
|
"${PROJECT_SOURCE_DIR}/src" |
|
104
|
"${PROJECT_SOURCE_DIR}" |
|
105
|
) |
|
106
|
|
|
107
|
add_custom_target(project-sources ALL |
|
108
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} |
|
109
|
SOURCES ${project_sources_DIRS} ${project_sources_FILES} |
|
110
|
) |
|
111
|
|
|
112
|
## CONFIGURE --------------------------------------------------------------- |
|
113
|
## |
|
114
|
set(fossil_configure_FLAGS "") |
|
115
|
if(configure_FLAGS) |
|
116
|
set(fossil_configure_FLAGS ${configure_FLAGS}) |
|
117
|
endif() |
|
118
|
if(isDebugBuild) |
|
119
|
if(MSVC) |
|
120
|
if(NOT "${fossil_configure_FLAGS}" MATCHES "FOSSIL_DEBUG") |
|
121
|
set(fossil_configure_FLAGS "FOSSIL_DEBUG=1" ${fossil_configure_FLAGS}) |
|
122
|
endif() |
|
123
|
else(MSVC) |
|
124
|
if(NOT "${fossil_configure_FLAGS}" MATCHES "--fossil-debug") |
|
125
|
set(fossil_configure_FLAGS "--fossil-debug" ${fossil_configure_FLAGS}) |
|
126
|
endif() |
|
127
|
endif(MSVC) |
|
128
|
endif() |
|
129
|
|
|
130
|
## BUILD --------------------------------------------------------------- |
|
131
|
## |
|
132
|
# Build fossil as an external project; just pass the options for configure and |
|
133
|
# build stages. This way we rely upon the existing build scripts. |
|
134
|
# |
|
135
|
# Install the resulting binary into the local binary dir, such that the fossil |
|
136
|
# binary can be located at the fixed location on target platform. |
|
137
|
# |
|
138
|
# Then we define CMake install targets to copy the binaries from the local |
|
139
|
# binary dir. |
|
140
|
# |
|
141
|
|
|
142
|
if(isDebugBuild) |
|
143
|
set_property(DIRECTORY APPEND PROPERTY |
|
144
|
COMPILE_DEFINITIONS FOSSIL_DEBUG |
|
145
|
) |
|
146
|
endif() |
|
147
|
|
|
148
|
set(fossil_build_FLAGS "") |
|
149
|
if(build_FLAGS) |
|
150
|
set(fossil_build_FLAGS ${build_FLAGS}) |
|
151
|
endif() |
|
152
|
|
|
153
|
separate_arguments(fossil_configure_FLAGS) |
|
154
|
separate_arguments(fossil_build_FLAGS) |
|
155
|
|
|
156
|
if(MSVC) |
|
157
|
file(RELATIVE_PATH fossil_DESTDIR "${fossil_BUILD_DIR}" "${fossil_EXE_DIR}") |
|
158
|
file(TO_NATIVE_PATH "${fossil_DESTDIR}" fossil_DESTDIR) |
|
159
|
|
|
160
|
## Work around the suprisingly obstinate "simplification" of buildmsvc.bat |
|
161
|
## which mandates the use of BUILDDIR env variable to be able to build |
|
162
|
## out-of-source, instead of inferring the path automatically from the |
|
163
|
## current work directory, as it's commonly done. |
|
164
|
## |
|
165
|
## Create a wrapper which defines BUILDDIR then starts the build. |
|
166
|
|
|
167
|
file(TO_NATIVE_PATH "${fossil_BUILD_DIR}" fossil_BUILD_DIR_WIN) |
|
168
|
file(TO_NATIVE_PATH "${fossil_SOURCE_DIR}/win/buildmsvc.bat" fossil_BUILDMSVC) |
|
169
|
file(WRITE "${fossil_BINARY_DIR}/build.cmd" |
|
170
|
"set \"BUILDDIR=${fossil_BUILD_DIR_WIN}\"\n\"${fossil_BUILDMSVC}\" %*\n") |
|
171
|
|
|
172
|
ExternalProject_Add(fossil |
|
173
|
PREFIX fossil |
|
174
|
SOURCE_DIR "${fossil_SOURCE_DIR}" |
|
175
|
CONFIGURE_COMMAND "" |
|
176
|
BINARY_DIR "${fossil_BINARY_DIR}" |
|
177
|
BUILD_COMMAND "${fossil_BINARY_DIR}/build.cmd" |
|
178
|
${fossil_configure_FLAGS} |
|
179
|
${fossil_build_FLAGS} |
|
180
|
all |
|
181
|
install DESTDIR=${fossil_DESTDIR} |
|
182
|
VERBATIM |
|
183
|
INSTALL_COMMAND "" |
|
184
|
STEP_TARGETS configure build install |
|
185
|
) |
|
186
|
|
|
187
|
else(MSVC) |
|
188
|
|
|
189
|
set_property(DIRECTORY APPEND PROPERTY |
|
190
|
COMPILE_DEFINITIONS HAVE_AUTOCONFIG_H;_HAVE_SQLITE_CONFIG_H |
|
191
|
) |
|
192
|
|
|
193
|
file(RELATIVE_PATH fossil_DESTDIR "${fossil_BINARY_DIR}" "${fossil_INSTALL_DIR}") |
|
194
|
|
|
195
|
ExternalProject_Add(fossil |
|
196
|
PREFIX fossil |
|
197
|
SOURCE_DIR "${fossil_SOURCE_DIR}" |
|
198
|
CONFIGURE_COMMAND "${fossil_SOURCE_DIR}/configure" |
|
199
|
--prefix=/ ${fossil_configure_FLAGS} |
|
200
|
VERBATIM |
|
201
|
BINARY_DIR "${fossil_BINARY_DIR}" |
|
202
|
BUILD_COMMAND "${CMAKE_MAKE_PROGRAM}" |
|
203
|
${fossil_build_FLAGS} |
|
204
|
VERBATIM |
|
205
|
INSTALL_COMMAND "${CMAKE_MAKE_PROGRAM}" install |
|
206
|
DESTDIR=${fossil_DESTDIR} |
|
207
|
STEP_TARGETS configure build install |
|
208
|
) |
|
209
|
|
|
210
|
endif(MSVC) |
|
211
|
|
|
212
|
set_property(DIRECTORY APPEND PROPERTY |
|
213
|
ADDITIONAL_MAKE_CLEAN_FILES "${fossil_BUILD_DIR}" |
|
214
|
"${fossil_EXE_DIR}" |
|
215
|
) |
|
216
|
|
|
217
|
ExternalProject_Add_Step(fossil forcebuild |
|
218
|
COMMAND "${CMAKE_COMMAND}" -E echo "Build fossil" |
|
219
|
DEPENDEES configure |
|
220
|
DEPENDERS build |
|
221
|
ALWAYS 1 |
|
222
|
) |
|
223
|
|
|
224
|
add_dependencies(fossil-exe fossil) |
|
225
|
|
|
226
|
|
|
227
|
## We need an executable target, so that IDEs can infer what to run/debug. |
|
228
|
## Define a substitute executable target to stand in for the actual fossil binary |
|
229
|
## that we just built via ExternalProject_Add. |
|
230
|
## Keep the actual fossil binary, clean up the built substitute artifacts. |
|
231
|
|
|
232
|
get_filename_component(app_NAME "${fossil_EXE}" NAME_WE) |
|
233
|
get_filename_component(app_DIR "${fossil_EXE}" DIRECTORY) |
|
234
|
file(TO_NATIVE_PATH "${app_DIR}" app_DIR) |
|
235
|
|
|
236
|
file(WRITE "${CMAKE_BINARY_DIR}/app.c" "int main(){ return 0; }\n") |
|
237
|
add_executable(app app.c) |
|
238
|
|
|
239
|
set_target_properties(app PROPERTIES |
|
240
|
OUTPUT_NAME "${app_NAME}" |
|
241
|
RUNTIME_OUTPUT_DIRECTORY "${app_DIR}" |
|
242
|
) |
|
243
|
if(MSVC) |
|
244
|
set_target_properties(app PROPERTIES |
|
245
|
LINK_FLAGS "/INCREMENTAL:NO /MANIFEST:NO" |
|
246
|
) |
|
247
|
if(isDebugBuild) |
|
248
|
set_target_properties(app PROPERTIES |
|
249
|
PDB_NAME "${app_NAME}" |
|
250
|
) |
|
251
|
endif() |
|
252
|
endif() |
|
253
|
|
|
254
|
add_custom_command(TARGET app PRE_LINK |
|
255
|
COMMAND "${CMAKE_COMMAND}" -E chdir "$<TARGET_FILE_DIR:app>" |
|
256
|
"${CMAKE_COMMAND}" -E rename "$<TARGET_FILE_NAME:app>" |
|
257
|
"$<TARGET_FILE_NAME:app>-imported" |
|
258
|
) |
|
259
|
if(MSVC AND isDebugBuild) |
|
260
|
add_custom_command(TARGET app PRE_LINK |
|
261
|
COMMAND "${CMAKE_COMMAND}" -E chdir "$<TARGET_FILE_DIR:app>" |
|
262
|
"${CMAKE_COMMAND}" -E rename "$<TARGET_PROPERTY:app,PDB_NAME>.pdb" |
|
263
|
"$<TARGET_PROPERTY:app,PDB_NAME>.pdb-imported" |
|
264
|
) |
|
265
|
endif() |
|
266
|
add_custom_command(TARGET app POST_BUILD |
|
267
|
COMMAND "${CMAKE_COMMAND}" -E chdir "$<TARGET_FILE_DIR:app>" |
|
268
|
"${CMAKE_COMMAND}" -E remove "$<TARGET_FILE_NAME:app>" |
|
269
|
COMMAND "${CMAKE_COMMAND}" -E chdir "$<TARGET_FILE_DIR:app>" |
|
270
|
"${CMAKE_COMMAND}" -E rename "$<TARGET_FILE_NAME:app>-imported" |
|
271
|
"$<TARGET_FILE_NAME:app>" |
|
272
|
) |
|
273
|
if(MSVC AND isDebugBuild) |
|
274
|
add_custom_command(TARGET app POST_BUILD |
|
275
|
COMMAND "${CMAKE_COMMAND}" -E chdir "$<TARGET_FILE_DIR:app>" |
|
276
|
"${CMAKE_COMMAND}" -E rename "$<TARGET_PROPERTY:app,PDB_NAME>.pdb-imported" |
|
277
|
"$<TARGET_PROPERTY:app,PDB_NAME>.pdb" |
|
278
|
) |
|
279
|
endif() |
|
280
|
|
|
281
|
add_dependencies(app fossil-exe) |
|
282
|
|
|
283
|
|
|
284
|
## TEST --------------------------------------------------------------- |
|
285
|
## |
|
286
|
add_custom_target(test-fossil-setup |
|
287
|
COMMENT "Setting up test-fossil" |
|
288
|
DEPENDS fossil-install |
|
289
|
) |
|
290
|
add_custom_command(TARGET test-fossil-setup PRE_BUILD |
|
291
|
COMMAND "${CMAKE_COMMAND}" -E copy_directory |
|
292
|
"${fossil_SOURCE_DIR}/test" "${fossil_TEST_DIR}" |
|
293
|
WORKING_DIRECTORY "${fossil_BINARY_DIR}" |
|
294
|
COMMENT "Copying data for test-fossil" |
|
295
|
VERBATIM |
|
296
|
) |
|
297
|
add_custom_command(TARGET test-fossil-setup POST_BUILD |
|
298
|
WORKING_DIRECTORY "${fossil_TEST_DIR}" |
|
299
|
COMMENT "Setting up test-fossil" |
|
300
|
VERBATIM |
|
301
|
) |
|
302
|
|
|
303
|
|
|
304
|
# Run the test suite. |
|
305
|
# Other flags that can be included in TESTFLAGS are: |
|
306
|
# |
|
307
|
# -halt Stop testing after the first failed test |
|
308
|
# -keep Keep the temporary workspace for debugging |
|
309
|
# -prot Write a detailed log of the tests to the file ./prot |
|
310
|
# -verbose Include even more details in the output |
|
311
|
# -quiet Hide most output from the terminal |
|
312
|
# -strict Treat known bugs as failures |
|
313
|
# |
|
314
|
# TESTFLAGS can also include names of specific test files to limit |
|
315
|
# the run to just those test cases. |
|
316
|
|
|
317
|
set(TCL "tclsh") |
|
318
|
if( test_FLAGS ) |
|
319
|
set(fossil_test_FLAGS ${test_FLAGS}) |
|
320
|
endif() |
|
321
|
|
|
322
|
separate_arguments(fossil_test_FLAGS) |
|
323
|
add_custom_target(test-fossil |
|
324
|
COMMAND "${TCL}" tester.tcl "${fossil_EXE}" -quiet ${fossil_test_FLAGS} |
|
325
|
VERBATIM |
|
326
|
WORKING_DIRECTORY "${fossil_TEST_DIR}" |
|
327
|
COMMENT "Running test-fossil" |
|
328
|
DEPENDS fossil-install |
|
329
|
) |
|
330
|
|
|
331
|
add_custom_target(test-fossil-clean |
|
332
|
COMMENT "Tearing down test-fossil" |
|
333
|
DEPENDS fossil-install |
|
334
|
) |
|
335
|
add_custom_command(TARGET test-fossil-clean POST_BUILD |
|
336
|
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_TEST_DIR}" |
|
337
|
WORKING_DIRECTORY "${fossil_BINARY_DIR}" |
|
338
|
COMMENT "Removing data for test-fossil" |
|
339
|
VERBATIM |
|
340
|
) |
|
341
|
|
|
342
|
add_custom_target(clean-fossil |
|
343
|
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_EXE_DIR}" |
|
344
|
VERBATIM |
|
345
|
COMMAND "${CMAKE_MAKE_PROGRAM}" clean |
|
346
|
VERBATIM |
|
347
|
WORKING_DIRECTORY "${fossil_BINARY_DIR}" |
|
348
|
COMMENT "Cleaning fossil build artifacts" |
|
349
|
DEPENDS fossil-configure |
|
350
|
) |
|
351
|
|
|
352
|
|
|
353
|
enable_testing() |
|
354
|
add_test(NAME 01-setup |
|
355
|
COMMAND "${CMAKE_COMMAND}" --build . --target test-fossil-setup |
|
356
|
) |
|
357
|
add_test(NAME 02-test |
|
358
|
COMMAND "${CMAKE_COMMAND}" --build . --target test-fossil |
|
359
|
) |
|
360
|
add_test(NAME 03-clean |
|
361
|
COMMAND "${CMAKE_COMMAND}" --build . --target test-fossil-clean |
|
362
|
) |
|
363
|
set_property(TEST 02-test APPEND PROPERTY |
|
364
|
DEPENDS 01-setup) |
|
365
|
set_property(TEST 03-clean APPEND PROPERTY |
|
366
|
DEPENDS 01-setup) |
|
367
|
|
|
368
|
add_custom_target(check |
|
369
|
COMMAND "${CMAKE_CTEST_COMMAND}" -V |
|
370
|
) |
|
371
|
|
|
372
|
## INSTALL --------------------------------------------------------------- |
|
373
|
## |
|
374
|
install(DIRECTORY ${fossil_EXE_DIR}/ |
|
375
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/ |
|
376
|
USE_SOURCE_PERMISSIONS |
|
377
|
) |
|
378
|
|