Debian Codegraph @

build_tooling/cmake/tangent.cmake

raw
1 set(TANGENT_MODULES_DIR ${CMAKE_CURRENT_LIST_DIR}/tangent)
2
3 # =================================================
4 # Detect whether this is local or installed tooling
5 # =================================================
6 get_filename_component(_local_tooling_dir
7 ${CMAKE_CURRENT_LIST_DIR}/../../tangent/tooling ABSOLUTE)
8 if(EXISTS ${_local_tooling_dir})
9 set(TANGENT_TOOLING ${_local_tooling_dir})
10 else()
11 set(TANGENT_TOOLING ${TANGENT_MODULES_DIR})
12 endif()
13
14 # =================
15 # Submodules
16 # =================
17
18 # NOTE(josh): order matters
19 set(_tangent_modules
20 environment.cmake
21 wrappers.cmake
22 codestyle.cmake
23 ctest_helpers.cmake
24 debian.cmake
25 doctools.cmake
26 pkgconfig.cmake
27 re2-config.cmake)
28 foreach(module ${_tangent_modules})
29 include(${TANGENT_MODULES_DIR}/${module})
30 endforeach()
31
32 if(TANGENT_SPARSE_EXPORT)
33 message(STATUS "Detected sparse export: ${TANGENT_SPARSE_EXPORT}")
34 endif()
35
36 if(NOT TANGENT_BUILD_CONTEXT)
37 set(TANGENT_BUILD_CONTEXT
38 WORKSTATION
39 CACHE STRING "what is the context for the current build")
40 endif()
41
42 # =================
43 # Global properties
44 # =================
45
46 # Will be populated by subdirectory listfiles with the dependencies of the
47 # master sphinx build
48 set_property(GLOBAL PROPERTY global_doc_files "")
49
50 # ======================
51 # Top-level (UI) targets
52 # ======================
53
54 add_custom_command(
55 OUTPUT __always_rebuild
56 COMMAND cmake -E echo "" > /dev/null
57 COMMENT "Running every-build")
58
59 add_custom_target(chkfmt DEPENDS __always_rebuild)
60 add_custom_target(doc DEPENDS __always_rebuild)
61 add_custom_target(format DEPENDS __always_rebuild)
62 add_custom_target(gen DEPENDS __always_rebuild)
63 add_custom_target(lint DEPENDS __always_rebuild)
64 add_custom_target(precommit DEPENDS __always_rebuild)
65 add_custom_target(test-deps DEPENDS __always_rebuild)
66 add_custom_target(wheels DEPENDS __always_rebuild)
67
68 # ==================
69 # Codestyle Manifest
70 # ==================
71
72 if(CMAKE_GENERATOR STREQUAL "Ninja")
73 add_custom_target(
74 check-codestyle-manifest
75 BYPRODUCTS ${CMAKE_BINARY_DIR}/codestyle_manifest.cmake
76 DEPENDS __always_rebuild
77 COMMAND
78 python -B ${TANGENT_TOOLING}/generate_style_manifest.py #
79 --outfile ${CMAKE_BINARY_DIR}/codestyle_manifest.cmake #
80 --excludes-from ${CMAKE_SOURCE_DIR}/build_tooling/lint-excludes.txt #
81 -- ${CMAKE_SOURCE_DIR}
82 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
83 COMMENT "Checking for changes in codestyle manifest")
84 else()
85 add_custom_command(
86 OUTPUT ${CMAKE_BINARY_DIR}/codestyle_manifest.cmake
87 DEPENDS __always_rebuild
88 COMMAND
89 python -B ${TANGENT_TOOLING}/generate_style_manifest.py #
90 --outfile ${CMAKE_BINARY_DIR}/codestyle_manifest.cmake #
91 --excludes-from ${CMAKE_SOURCE_DIR}/build_tooling/lint-excludes.txt #
92 -- ${CMAKE_SOURCE_DIR}
93 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
94 COMMENT "Checking for changes in codestyle manifest")
95
96 add_custom_target(check-codestyle-manifest
97 DEPENDS ${CMAKE_BINARY_DIR}/codestyle_manifest.cmake)
98 endif()
99
100 check_call(
101 COMMAND
102 python -B ${TANGENT_TOOLING}/generate_style_manifest.py #
103 --outfile ${CMAKE_BINARY_DIR}/codestyle_manifest.cmake #
104 --excludes-from ${CMAKE_SOURCE_DIR}/build_tooling/lint-excludes.txt #
105 -- ${CMAKE_SOURCE_DIR}
106 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
107
108 check_call(
109 COMMAND python -B ${TANGENT_TOOLING}/cmake_post.py --binary-dir
110 ${CMAKE_BINARY_DIR} --generator "${CMAKE_GENERATOR}"
111 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
112
113 # If the manifest changes, then we need to rerun cmake to import link/fmt rules
114 # for the new manifest
115 # configure_file(${CMAKE_BINARY_DIR}/codestyle_manifest.cmake
116 # ${CMAKE_BINARY_DIR}/codestyle_manifest.stamp COPYONLY)
117
118 include(${CMAKE_BINARY_DIR}/codestyle_manifest.cmake)
119
120 # ========================
121 # Local python environment
122 # ========================
123
124 # Create python environment with packages needed to do the build
125 set(PYENV_WITNESS ${CMAKE_BINARY_DIR}/pyenv.witness)
126 set(PYENV
127 ${CMAKE_COMMAND} -E env #
128 VIRTUAL_ENV=${CMAKE_BINARY_DIR}/pyenv #
129 "PATH=${CMAKE_BINARY_DIR}/pyenv:\$\${PATH}")
130
131 if(CMAKE_GENERATOR STREQUAL "Ninja")
132 set(_depfile DEPFILE ${CMAKE_BINARY_DIR}/pyenv.d)
133 endif()
134
135 add_custom_command(
136 OUTPUT ${PYENV_WITNESS}
137 COMMAND rm -rf ${CMAKE_BINARY_DIR}/pyenv
138 COMMAND virtualenv -p python3 ${CMAKE_BINARY_DIR}/pyenv
139 COMMAND ${PYENV} pip install -r requirements.txt
140 COMMAND echo "pyenv.witness : \\\\" > ${CMAKE_BINARY_DIR}/pyenv.d
141 COMMAND
142 env LC_ALL=C #
143 find ${CMAKE_BINARY_DIR}/pyenv -type l,f #
144 | sed 's: :\\\\ :g' #
145 | sort #
146 | sed 's:$$:\\\\:' >> ${CMAKE_BINARY_DIR}/pyenv.d
147 COMMAND touch ${PYENV_WITNESS}
148 DEPENDS requirements.txt
149 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
150 COMMENT "Creating python environment" ${_depfile})
151
152 # NOTE(josh): bug in cmake 3.10. If we don't create this custom target, then
153 # cmake wont emit the rule... even though we have a rule later on that depends
154 # on the outputs of the custom command.
155 add_custom_target(pyenv DEPENDS ${PYENV_WITNESS})
156
157 # ==============
158 # doxygen target
159 # ==============
160
161 # NOTE(josh): some sparse checkouts don't include doxygen
162 if(EXISTS ${CMAKE_SOURCE_DIR}/doxy.config.in)
163 # configure the doxygen configuration
164 # NOTE(josh): maybe want to expose this for editor integration
165 # ~~~
166 # set(DOXY_WARN_FORMAT "\"$file($line) : $text \"")
167 # set(DOXY_WARN_FORMAT "\"$file:$line: $text \"")
168 # ~~~
169 configure_file("${PROJECT_SOURCE_DIR}/doxy.config.in"
170 "${PROJECT_BINARY_DIR}/doxy.config")
171
172 add_custom_command(
173 OUTPUT ${PROJECT_BINARY_DIR}/doxy.stamp
174 COMMAND doxygen ${PROJECT_BINARY_DIR}/doxy.config
175 COMMAND touch ${PROJECT_BINARY_DIR}/doxy.stamp
176 DEPENDS ${PROJECT_BINARY_DIR}/doxy.config
177 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
178
179 add_custom_target(doxygen DEPENDS ${PROJECT_BINARY_DIR}/doxy.stamp)
180 add_dependencies(doc doxygen)
181 endif()
182
183 # ==================
184 # better-test target
185 # ==================
186
187 add_custom_target(
188 better-test
189 DEPENDS test-deps
190 COMMAND ctest --force-new-ctest-process --output-on-failure
191 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
192 COMMENT "Execute ctest")
193
194 add_custom_target(
195 best-test
196 COMMENT "Execute all tests")
197
198 # ====================
199 # buildbot-test target
200 # ====================
201
202 add_custom_target(
203 buildbot-test
204 DEPENDS test-deps
205 COMMAND
206 # cmake-format: off
207 ctest
208 --label-exclude CI_DISABLED
209 --force-new-ctest-process
210 --output-on-failure
211 --output-log ${CMAKE_BINARY_DIR}/ctestlog.txt
212 # cmake-format: on
213 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
214
215 # =========
216 # git hooks
217 # =========
218
219 add_custom_target(pre-push)
220 add_dependencies(pre-push lint chkfmt)
221
222 add_custom_target(pre-release)
223 add_dependencies(pre-release better-test doc lint chkfmt)
224
225 # ========================
226 # bake vscode config files
227 # ========================
228
229 # Inform vscode where compile commands is
230 find_program(_python_path python)
231 file(GLOB _vscode_files ${CMAKE_SOURCE_DIR}/.vscode/*)
232 execute_process(
233 COMMAND
234 python -B ${TANGENT_TOOLING}/vscode_varsub.py #
235 --var cmakeBinaryDir=${CMAKE_BINARY_DIR} #
236 --var "pythonPath=${_python_path}" #
237 sub ${_vscode_files}
238 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
239
240 add_custom_target(
241 unsub-vscode
242 COMMAND
243 python -B ${TANGENT_TOOLING}/vscode_varsub.py #
244 --var cmakeBinaryDir=${CMAKE_BINARY_DIR} #
245 --var "pythonPath=${_python_path}" #
246 --touch ${CMAKE_SOURCE_DIR}/CMakeLists.txt #
247 unsub ${_vscode_files}
248 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
249 COMMENT "Restoring variables in vscode")
250 add_dependencies(precommit unsub-vscode)