forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
181 lines (157 loc) · 5.06 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
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
add_subdirectory(tools)
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
-W
-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")
else()
message(WARNING "Unable to find sphinx-build program. Not building docs")
endif()
## 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()
if (LLVM_ENABLE_DOXYGEN)
if (DOXYGEN_FOUND)
set(abs_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
set(abs_builddir ${CMAKE_CURRENT_BINARY_DIR})
if (HAVE_DOT)
set(DOT ${LLVM_PATH_DOT})
endif()
if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
set(enable_searchengine "YES")
set(searchengine_url "${LLVM_DOXYGEN_SEARCHENGINE_URL}")
set(enable_server_based_search "YES")
set(enable_external_search "YES")
set(extra_search_mappings "${LLVM_DOXYGEN_SEARCH_MAPPINGS}")
else()
set(enable_searchengine "NO")
set(searchengine_url "")
set(enable_server_based_search "NO")
set(enable_external_search "NO")
set(extra_search_mappings "")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg @ONLY)
set(abs_top_srcdir)
set(abs_top_builddir)
set(DOT)
set(enable_searchengine)
set(searchengine_url)
set(enable_server_based_search)
set(enable_external_search)
set(extra_search_mappings)
add_custom_target(doxygen-swift
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating swift doxygen documentation." VERBATIM)
if(LLVM_BUILD_DOCS)
add_dependencies(doxygen doxygen-swift)
endif()
swift_install_in_component(dev
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
DESTINATION "docs/html")
endif()
endif()