-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathCMakeLists.txt
144 lines (125 loc) · 4 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
find_program(SPHINX_EXECUTABLE
NAMES sphinx-build
HINTS $ENV{SPHINX_DIR}
PATH_SUFFIXES bin
DOC "Sphinx documentation generator")
SET(SWIFT_SPHINX_PAPER_SIZE "letter"
CACHE STRING "Paper size for generated documentation")
SET(SPHINX_ARGS
-Q
-D latex_paper_size=${SWIFT_SPHINX_PAPER_SIZE}
-d ${CMAKE_BINARY_DIR}/doctrees)
if(SPHINX_EXECUTABLE)
add_custom_target(docs_html ALL
${SPHINX_EXECUTABLE} ${SPHINX_ARGS} -b html
. ${CMAKE_BINARY_DIR}/docs/html
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building HTML documentation")
# Selectively install docs intended for general consumption.
install(
FILES
${CMAKE_BINARY_DIR}/docs/html/LangRef.html
DESTINATION share/swift/docs/html)
install(
DIRECTORY
${CMAKE_BINARY_DIR}/docs/html/_static
${CMAKE_BINARY_DIR}/docs/html/whitepaper
DESTINATION share/swift/docs/html)
else(SPHINX_EXECUTABLE)
message(WARNING "Unable to find sphinx-build program. Not building docs")
endif(SPHINX_EXECUTABLE)
## Example testing
find_program(LITRE_EXECUTABLE
NAMES litre
DOC "LitRe literate programming tool for docutils")
find_program(SPHINX_EXECUTABLE
NAMES sphinx-build
HINTS $ENV{SPHINX_DIR}
PATH_SUFFIXES bin
DOC "Sphinx documentation generator")
if(LITRE_EXECUTABLE)
# Find all the .rst files
file(GLOB_RECURSE rst_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.rst)
set(subdir_CMakeLists)
foreach(rst ${rst_files})
# Prepare a testing directory containing a CMakeLists.txt
# and example files extracted from the .rst
set(test_dir "litre-tests/${rst}.litre-tests")
add_custom_command(
OUTPUT
${test_dir}/CMakeLists.txt
COMMAND
${LITRE_EXECUTABLE}
--default_compiler=${CMAKE_BINARY_DIR}/bin/swift
"--dump_dir=${test_dir}"
--traceback
--report=severe # suppress most .rst errors. We have lots of them.
${CMAKE_CURRENT_SOURCE_DIR}/${rst}
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/${rst}
COMMENT
"Generating/Updating LitRe tests for ${rst}"
VERBATIM
)
list(APPEND subdir_CMakeLists ${test_dir}/CMakeLists.txt)
endforeach()
# Create a top-level CMakeLists.txt in a temporary file
add_custom_command(
OUTPUT
litre-top-CMakeLists.cmake
COMMAND
${CMAKE_COMMAND} -DOUTPUT=litre-top-CMakeLists.cmake
-DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/GenerateTopLevelLitreCMakeLists.cmake
${rst_files}
DEPENDS
${rst_files}
COMMENT
"Generating top-level LitRe CMakeLists.txt content"
VERBATIM
)
# Only update the real top-level CMakeLists.txt if something changed
add_custom_command(
OUTPUT
litre-tests/CMakeLists.txt
COMMAND
${CMAKE_COMMAND} -E copy_if_different litre-top-CMakeLists.cmake litre-tests/CMakeLists.txt
DEPENDS
litre-top-CMakeLists.cmake
COMMENT
"Updating top-level LitRe CMakeLists.txt"
VERBATIM
)
# Create a build directory
add_custom_command(
OUTPUT litre-tests/build
COMMAND ${CMAKE_COMMAND} -E make_directory litre-tests/build
)
# Run CMake itself to configure/build the tests
add_custom_command(
OUTPUT
litre-tests/results
COMMAND
${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${CMAKE_CURRENT_BINARY_DIR}/litre-tests"
COMMAND
${CMAKE_COMMAND} --build .
COMMAND
${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/litre-tests/results"
WORKING_DIRECTORY
litre-tests/build
DEPENDS
${CMAKE_BINARY_DIR}/bin/swift
litre-tests/CMakeLists.txt litre-tests/build ${subdir_CMakeLists}
COMMENT
"Running LitRe tests"
VERBATIM
)
# Add a target so these tests show up in the Xcode project.
add_custom_target(
LiterateTests SOURCES ${rst_files}
DEPENDS litre-tests/results
)
set_target_properties(LiterateTests PROPERTIES FOLDER "Tests")
else()
message(WARNING "LitRe not found; code examples won't be tested.")
endif()