1 cmake_minimum_required(VERSION 3.1)
5 run_cmake_command(NoArgs ${CMAKE_COMMAND})
6 run_cmake_command(InvalidArg1 ${CMAKE_COMMAND} -invalid)
7 run_cmake_command(InvalidArg2 ${CMAKE_COMMAND} --invalid)
8 run_cmake_command(Wizard ${CMAKE_COMMAND} -i)
9 run_cmake_command(C-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -C)
10 run_cmake_command(C-no-arg2 ${CMAKE_COMMAND} -B DummyBuildDir -C -T)
11 set(RunCMake_TEST_RAW_ARGS [[-C ""]])
12 run_cmake_command(C-no-arg3 ${CMAKE_COMMAND} -B DummyBuildDir)
13 unset(RunCMake_TEST_RAW_ARGS)
14 run_cmake_command(C-no-file ${CMAKE_COMMAND} -B DummyBuildDir -C nosuchcachefile.txt)
15 run_cmake_command(Cno-file ${CMAKE_COMMAND} -B DummyBuildDir -Cnosuchcachefile.txt)
16 run_cmake_command(cache-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeCache.txt)
17 run_cmake_command(lists-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeLists.txt)
18 run_cmake_command(D-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -D)
19 run_cmake_command(D-no-src ${CMAKE_COMMAND} -B DummyBuildDir -D VAR=VALUE)
20 run_cmake_command(Dno-src ${CMAKE_COMMAND} -B DummyBuildDir -DVAR=VALUE)
21 run_cmake_command(U-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -U)
22 run_cmake_command(U-no-src ${CMAKE_COMMAND} -B DummyBuildDir -U VAR)
23 run_cmake_command(Uno-src ${CMAKE_COMMAND} -B DummyBuildDir -UVAR)
24 run_cmake_command(E-no-arg ${CMAKE_COMMAND} -E)
25 run_cmake_command(E_capabilities ${CMAKE_COMMAND} -E capabilities)
26 run_cmake_command(E_capabilities-arg ${CMAKE_COMMAND} -E capabilities --extra-arg)
27 run_cmake_command(E_compare_files-different-eol ${CMAKE_COMMAND} -E compare_files ${RunCMake_SOURCE_DIR}/compare_files/lf ${RunCMake_SOURCE_DIR}/compare_files/crlf)
28 run_cmake_command(E_compare_files-ignore-eol-same ${CMAKE_COMMAND} -E compare_files --ignore-eol ${RunCMake_SOURCE_DIR}/compare_files/lf ${RunCMake_SOURCE_DIR}/compare_files/crlf)
29 run_cmake_command(E_compare_files-ignore-eol-empty ${CMAKE_COMMAND} -E compare_files --ignore-eol ${RunCMake_SOURCE_DIR}/compare_files/empty1 ${RunCMake_SOURCE_DIR}/compare_files/empty2)
30 run_cmake_command(E_compare_files-ignore-eol-nonexistent ${CMAKE_COMMAND} -E compare_files --ignore-eol nonexistent_a nonexistent_b)
31 run_cmake_command(E_compare_files-invalid-arguments ${CMAKE_COMMAND} -E compare_files file1.txt file2.txt file3.txt)
32 run_cmake_command(E_echo_append ${CMAKE_COMMAND} -E echo_append)
33 run_cmake_command(E_rename-no-arg ${CMAKE_COMMAND} -E rename)
34 run_cmake_command(E_server ${CMAKE_COMMAND} -E server)
35 run_cmake_command(E_true ${CMAKE_COMMAND} -E true)
36 run_cmake_command(E_true-extraargs ${CMAKE_COMMAND} -E true ignored)
37 run_cmake_command(E_false ${CMAKE_COMMAND} -E false)
38 run_cmake_command(E_false-extraargs ${CMAKE_COMMAND} -E false ignored)
40 run_cmake_command(E_touch_nocreate-no-arg ${CMAKE_COMMAND} -E touch_nocreate)
41 run_cmake_command(E_touch-nonexistent-dir ${CMAKE_COMMAND} -E touch "${RunCMake_BINARY_DIR}/touch-nonexistent-dir/foo")
43 run_cmake_command(E_time ${CMAKE_COMMAND} -E time ${CMAKE_COMMAND} -E echo "hello world")
44 run_cmake_command(E_time-no-arg ${CMAKE_COMMAND} -E time)
46 run_cmake_command(E___run_co_compile-no-iwyu ${CMAKE_COMMAND} -E __run_co_compile -- command-does-not-exist)
47 run_cmake_command(E___run_co_compile-bad-iwyu ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist -- command-does-not-exist)
48 run_cmake_command(E___run_co_compile-no--- ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist command-does-not-exist)
49 run_cmake_command(E___run_co_compile-no-cc ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist --)
51 run_cmake_command(G_no-arg ${CMAKE_COMMAND} -B DummyBuildDir -G)
52 run_cmake_command(G_bad-arg ${CMAKE_COMMAND} -B DummyBuildDir -G NoSuchGenerator)
53 run_cmake_command(P_no-arg ${CMAKE_COMMAND} -P)
54 run_cmake_command(P_no-file ${CMAKE_COMMAND} -P nosuchscriptfile.cmake)
55 run_cmake_command(P_args ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_DIR}/P_args.cmake" relative/path "${RunCMake_SOURCE_DIR}")
56 run_cmake_command(P_arbitrary_args ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_DIR}/P_arbitrary_args.cmake" -- -DFOO -S -B --fresh --version)
57 run_cmake_command(P_fresh ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_DIR}/P_fresh.cmake" --fresh)
59 run_cmake_command(build-no-dir
60 ${CMAKE_COMMAND} --build)
61 run_cmake_command(build-no-cache
62 ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR})
63 run_cmake_command(build-unknown-command-short
64 ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} -invalid-command)
65 run_cmake_command(build-unknown-command-long
66 ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} --invalid-command)
67 run_cmake_command(build-unknown-command-partial-match
68 ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} --targetinvalid)
69 run_cmake_command(build-invalid-target-syntax
70 ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} --target=invalid)
71 run_cmake_command(build-no-generator
72 ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-no-generator)
73 run_cmake_command(build-bad-dir
74 ${CMAKE_COMMAND} --build dir-does-not-exist)
75 run_cmake_command(build-bad-generator
76 ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-generator)
78 run_cmake_command(install-prefix-no-arg ${CMAKE_COMMAND} -B DummyBuildDir --install-prefix)
80 run_cmake_command(install-no-dir
81 ${CMAKE_COMMAND} --install)
82 run_cmake_command(install-bad-dir
83 ${CMAKE_COMMAND} --install dir-does-not-exist)
84 run_cmake_command(install-unknown-command-short
85 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR} -invalid-command)
86 run_cmake_command(install-unknown-command-long
87 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR} --invalid-command)
88 run_cmake_command(install-options-to-vars
89 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-install-options-to-vars
90 --strip --prefix /var/test --config sample --component pack)
91 run_cmake_command(install-default-dir-permissions-all
92 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
93 --default-directory-permissions u=rwx,g=rx,o=rx)
94 run_cmake_command(install-default-dir-permissions-afew
95 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
96 --default-directory-permissions u=rwx,g=rx)
97 run_cmake_command(install-default-dir-permissions-none
98 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars)
99 run_cmake_command(install-default-dir-permissions-invalid-comma1
100 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
101 --default-directory-permissions u=rwxg=,x)
102 run_cmake_command(install-default-dir-permissions-invalid-comma2
103 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
104 --default-directory-permissions u=rwxg,=x)
105 run_cmake_command(install-default-dir-permissions-comma-at-the-end
106 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
107 --default-directory-permissions u=rwx,)
108 run_cmake_command(install-default-dir-permissions-invalid-assignment
109 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
110 --default-directory-permissions u=rwx,=x)
111 run_cmake_command(install-default-dir-permissions-assignment-at-the-end
112 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
113 --default-directory-permissions u=rwx,g=)
114 run_cmake_command(install-default-dir-permissions-assignment-at-the-beginning
115 ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
116 --default-directory-permissions =u=rwx,g=rx)
118 run_cmake_command(cache-bad-entry
119 ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-entry/)
120 run_cmake_command(cache-empty-entry
121 ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-empty-entry/)
123 function(run_ExplicitDirs)
124 set(RunCMake_TEST_NO_CLEAN 1)
125 set(RunCMake_TEST_NO_SOURCE_DIR 1)
127 set(source_dir ${RunCMake_BINARY_DIR}/ExplicitDirsMissing)
129 file(REMOVE_RECURSE "${source_dir}")
130 file(MAKE_DIRECTORY "${source_dir}")
131 file(WRITE ${source_dir}/CMakeLists.txt [=[
132 cmake_minimum_required(VERSION 3.13)
133 project(ExplicitDirsMissing LANGUAGES NONE)
135 set(RunCMake_TEST_SOURCE_DIR "${source_dir}")
136 set(RunCMake_TEST_BINARY_DIR "${source_dir}")
137 run_cmake_with_options(ExplicitDirs-no-S-B -DFOO=BAR)
139 file(WRITE ${source_dir}/CMakeLists.txt [=[
140 cmake_minimum_required(VERSION 3.13)
141 project(ExplicitDirsMissing LANGUAGES NONE)
142 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
143 message(FATAL_ERROR "CWD used as binary dir")
145 message(STATUS "CMAKE_SOURCE_DIR='${CMAKE_SOURCE_DIR}'")
146 message(STATUS "CMAKE_BINARY_DIR='${CMAKE_BINARY_DIR}'")
149 file(REMOVE_RECURSE "${source_dir}/build")
150 # Test with a setup where binary_dir won't be created by `run_cmake_with_options`
151 run_cmake_with_options(ExplicitDirs-S-arg-build-dir-not-created -S ${source_dir} build/)
152 run_cmake_with_options(ExplicitDirs-S-arg-reverse-build-dir-not-created build/ -S${source_dir} )
154 file(REMOVE_RECURSE "${source_dir}/build")
155 file(MAKE_DIRECTORY "${source_dir}/build")
156 run_cmake_with_options(ExplicitDirs-S-arg-build-dir-empty -S ${source_dir} build/)
158 set(source_dir ${RunCMake_SOURCE_DIR}/ExplicitDirs)
159 set(binary_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-build)
160 set(working_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-cwd)
162 set(RunCMake_TEST_SOURCE_DIR "${source_dir}")
163 set(RunCMake_TEST_BINARY_DIR "${binary_dir}")
165 file(MAKE_DIRECTORY "${working_dir}")
166 set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${working_dir}")
168 file(REMOVE_RECURSE "${binary_dir}")
169 run_cmake_with_options(ExplicitDirs-S-arg -S ${source_dir} ${binary_dir})
170 run_cmake_with_options(ExplicitDirs-S-arg-reverse-order ${binary_dir} -S${source_dir} )
171 run_cmake_with_options(ExplicitDirs-S-no-arg -S )
172 run_cmake_with_options(ExplicitDirs-S-no-arg2 -S -T)
173 run_cmake_with_raw_args(ExplicitDirs-S-no-arg3 [[-S ""]])
174 run_cmake_with_options(ExplicitDirs-S-B -S ${source_dir} -B ${binary_dir})
175 run_cmake_with_options(ExplicitDirs-S-B-extra-path -S ${source_dir} -B ${binary_dir} /extra/path/)
176 run_cmake_with_raw_args(ExplicitDirs-S-B-non-path "-S \"${source_dir}\" -B \"${binary_dir}\" \"\"")
177 run_cmake_with_raw_args(ExplicitDirs-S-B-non-path2 "-S \"${source_dir}\" \"\" -B \"${binary_dir}\"")
179 file(REMOVE_RECURSE "${binary_dir}/other_dir")
180 file(MAKE_DIRECTORY "${binary_dir}/other_dir")
181 file(WRITE "${binary_dir}/other_dir/CMakeLists.txt" [=[ ]=])
182 run_cmake_with_options(ExplicitDirs-S-S-same -S ${source_dir} -S ${source_dir} -B ${binary_dir})
183 run_cmake_with_options(ExplicitDirs-S-S-differs -S ${binary_dir}/other_dir -S ${source_dir} -B ${binary_dir})
184 run_cmake_with_options(ExplicitDirs-S-implicit-same -S ${source_dir} ${source_dir} -B ${binary_dir})
185 run_cmake_with_options(ExplicitDirs-S-implicit-differs -S ${binary_dir}/other_dir ${source_dir} -B ${binary_dir})
186 run_cmake_with_options(ExplicitDirs-S-implicit-differs2 ${binary_dir}/other_dir -S ${source_dir} -B ${binary_dir})
187 run_cmake_with_options(ExplicitDirs-S-implicit-differs3 ${binary_dir}/other_dir ${source_dir} -B ${binary_dir})
188 run_cmake_with_options(ExplicitDirs-S-S-Sdiffers -S ${binary_dir}/other_dir1 -S ${binary_dir}/other_dir2 -S ${source_dir} -B ${binary_dir})
189 run_cmake_with_options(ExplicitDirs-S-S-Simplicit ${binary_dir}/other_dir1 ${binary_dir}/other_dir2 ${source_dir} -B ${binary_dir})
191 # make sure that -B can explicitly construct build directories
192 file(REMOVE_RECURSE "${binary_dir}")
193 run_cmake_with_options(ExplicitDirs-B-arg -B ${binary_dir} ${source_dir})
194 file(REMOVE_RECURSE "${binary_dir}")
195 run_cmake_with_options(ExplicitDirs-B-arg-reverse-order ${source_dir} -B${binary_dir})
196 run_cmake_with_options(ExplicitDirs-B-no-arg -B )
197 run_cmake_with_options(ExplicitDirs-B-no-arg2 -B -T)
198 run_cmake_with_raw_args(ExplicitDirs-B-no-arg3 [[-B ""]])
199 file(REMOVE_RECURSE "${binary_dir}")
200 run_cmake_with_options(ExplicitDirs-B-S -B${binary_dir} -S${source_dir})
201 run_cmake_with_options(ExplicitDirs-B-S-extra-path -B${binary_dir} -S${source_dir} /extra/path/)
203 unset(RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
205 message("copied to ${RunCMake_TEST_BINARY_DIR}/initial-cache.txt")
206 file(COPY ${RunCMake_SOURCE_DIR}/C_buildsrcdir/initial-cache.txt DESTINATION ${RunCMake_TEST_BINARY_DIR})
208 # CMAKE_BINARY_DIR should be determined by -B if specified, and CMAKE_SOURCE_DIR determined by -S if specified.
209 # Path to initial-cache.txt is relative to the $PWD, which is normally set to ${RunCMake_TEST_BINARY_DIR}.
210 run_cmake_with_options(ExplicitDirs-C_buildsrcdir -B DummyBuildDir -S ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C initial-cache.txt)
211 # Test that full path works, too.
212 run_cmake_with_options(ExplicitDirs-C_buildsrcdir -B DummyBuildDir -S ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C ${RunCMake_TEST_BINARY_DIR}/initial-cache.txt)
213 run_cmake_with_options(ExplicitDirs-C_buildsrcdir -B DummyBuildDir ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C ${RunCMake_TEST_BINARY_DIR}/initial-cache.txt)
218 set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/Fresh-build")
220 set(RunCMake_TEST_VARIANT_DESCRIPTION "-empty")
221 run_cmake_with_options(Fresh --fresh -DFIRST=ON)
222 set(RunCMake_TEST_NO_CLEAN 1)
224 set(RunCMake_TEST_VARIANT_DESCRIPTION "-reconfig")
225 run_cmake_with_options(Fresh --fresh)
227 set(RunCMake_TEST_VARIANT_DESCRIPTION "-src-from-cache")
228 set(RunCMake_TEST_NO_SOURCE_DIR 1)
229 run_cmake_with_options(Fresh --fresh "${RunCMake_TEST_BINARY_DIR}")
233 function(run_Toolchain)
234 set(RunCMake_TEST_NO_SOURCE_DIR 1)
235 set(source_dir ${RunCMake_SOURCE_DIR}/Toolchain)
237 run_cmake_with_options(toolchain-no-arg -S ${source_dir} --toolchain=)
238 run_cmake_with_options(toolchain-valid-abs-path -S ${source_dir} --toolchain "${source_dir}/toolchain.cmake")
239 run_cmake_with_options(toolchain-valid-rel-src-path -S ${source_dir} --toolchain=toolchain.cmake)
241 set(RunCMake_TEST_NO_CLEAN 1)
242 set(binary_dir ${RunCMake_BINARY_DIR}/Toolchain-build)
243 set(RunCMake_TEST_BINARY_DIR "${binary_dir}")
244 file(REMOVE_RECURSE "${binary_dir}")
246 # Test that we both search the binary dir for toolchain files, and it takes
247 # precedence over source dir
248 file(WRITE ${binary_dir}/toolchain.cmake [=[
249 set(CMAKE_SYSTEM_NAME Linux)
250 set(toolchain_file binary_dir)
252 run_cmake_with_options(toolchain-valid-rel-build-path -S ${source_dir} -B ${binary_dir} --toolchain toolchain.cmake)
256 function(run_BuildDir)
257 # Use a single build tree for a few tests without cleaning.
258 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/BuildDir-build)
259 set(RunCMake_TEST_NO_CLEAN 1)
260 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
261 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
264 run_cmake_command(BuildDir--build ${CMAKE_COMMAND} -E chdir ..
265 ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget)
266 run_cmake_command(BuildDir--build-multiple-targets ${CMAKE_COMMAND} -E chdir ..
267 ${CMAKE_COMMAND} --build BuildDir-build -t CustomTarget2 --target CustomTarget3)
268 run_cmake_command(BuildDir--build-multiple-targets-fail ${CMAKE_COMMAND} -E chdir ..
269 ${CMAKE_COMMAND} --build BuildDir-build -t CustomTargetFail --target CustomTarget3)
270 run_cmake_command(BuildDir--build-multiple-targets-jobs ${CMAKE_COMMAND} -E chdir ..
271 ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget CustomTarget2 -j2 --target CustomTarget3)
272 run_cmake_command(BuildDir--build-multiple-targets-with-clean-first ${CMAKE_COMMAND} -E chdir ..
273 ${CMAKE_COMMAND} --build BuildDir-build --target clean CustomTarget)
274 run_cmake_command(BuildDir--build-multiple-targets-with-clean-second ${CMAKE_COMMAND} -E chdir ..
275 ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget clean)
276 run_cmake_command(BuildDir--build-jobs-bad-number ${CMAKE_COMMAND} -E chdir ..
277 ${CMAKE_COMMAND} --build BuildDir-build -j 12ab)
278 run_cmake_command(BuildDir--build-jobs-good-number ${CMAKE_COMMAND} -E chdir ..
279 ${CMAKE_COMMAND} --build BuildDir-build -j 2)
280 run_cmake_command(BuildDir--build-jobs-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
281 ${CMAKE_COMMAND} --build BuildDir-build -j 2 --target CustomTarget)
282 run_cmake_command(BuildDir--build--parallel-bad-number ${CMAKE_COMMAND} -E chdir ..
283 ${CMAKE_COMMAND} --build BuildDir-build --parallel 12ab)
284 run_cmake_command(BuildDir--build--parallel-good-number ${CMAKE_COMMAND} -E chdir ..
285 ${CMAKE_COMMAND} --build BuildDir-build --parallel 2)
286 run_cmake_command(BuildDir--build--parallel-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
287 ${CMAKE_COMMAND} --build BuildDir-build --parallel 2 --target CustomTarget)
288 run_cmake_command(BuildDir--build-jobs-no-space-bad-number ${CMAKE_COMMAND} -E chdir ..
289 ${CMAKE_COMMAND} --build BuildDir-build -j12ab)
290 run_cmake_command(BuildDir--build-jobs-no-space-good-number ${CMAKE_COMMAND} -E chdir ..
291 ${CMAKE_COMMAND} --build BuildDir-build -j2)
292 run_cmake_command(BuildDir--build-jobs-no-space-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
293 ${CMAKE_COMMAND} --build BuildDir-build -j2 --target CustomTarget)
294 run_cmake_command(BuildDir--build--parallel-no-space-bad-number ${CMAKE_COMMAND} -E chdir ..
295 ${CMAKE_COMMAND} --build BuildDir-build --parallel12ab)
296 run_cmake_command(BuildDir--build--parallel-no-space-good-number ${CMAKE_COMMAND} -E chdir ..
297 ${CMAKE_COMMAND} --build BuildDir-build --parallel2)
298 run_cmake_command(BuildDir--build--parallel-no-space-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
299 ${CMAKE_COMMAND} --build BuildDir-build --parallel2 --target CustomTarget)
300 run_cmake_command(BuildDir--build-jobs-zero ${CMAKE_COMMAND} -E chdir ..
301 ${CMAKE_COMMAND} --build BuildDir-build -j 0)
302 run_cmake_command(BuildDir--build--parallel-zero ${CMAKE_COMMAND} -E chdir ..
303 ${CMAKE_COMMAND} --build BuildDir-build --parallel 0)
304 run_cmake_command(BuildDir--build-jobs-large ${CMAKE_COMMAND} -E chdir ..
305 ${CMAKE_COMMAND} --build BuildDir-build -j 4294967293)
306 run_cmake_command(BuildDir--build--parallel-large ${CMAKE_COMMAND} -E chdir ..
307 ${CMAKE_COMMAND} --build BuildDir-build --parallel 4294967293)
309 # No default jobs for FreeBSD build command
310 if(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
311 run_cmake_command(BuildDir--build-jobs-no-number ${CMAKE_COMMAND} -E chdir ..
312 ${CMAKE_COMMAND} --build BuildDir-build -j)
313 run_cmake_command(BuildDir--build-jobs-no-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
314 ${CMAKE_COMMAND} --build BuildDir-build -j --target CustomTarget)
315 if(RunCMake_GENERATOR MATCHES "Unix Makefiles" OR RunCMake_GENERATOR MATCHES "Ninja")
316 set(_backup_lang "$ENV{LANG}")
317 set(_backup_lc_messages "$ENV{LC_MESSAGES}")
319 set(ENV{LC_MESSAGES} "C")
320 run_cmake_command(BuildDir--build-jobs-no-number-trailing--invalid-target ${CMAKE_COMMAND} -E chdir ..
321 ${CMAKE_COMMAND} --build BuildDir-build -j --target invalid-target)
322 set(ENV{LANG} "${_backup_lang}")
323 set(ENV{LC_MESSAGES} "${_backup_lc_messages}")
325 run_cmake_command(BuildDir--build--parallel-no-number ${CMAKE_COMMAND} -E chdir ..
326 ${CMAKE_COMMAND} --build BuildDir-build --parallel)
327 run_cmake_command(BuildDir--build--parallel-no-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
328 ${CMAKE_COMMAND} --build BuildDir-build --parallel --target CustomTarget)
333 function(run_EnvironmentGenerator)
334 set(source_dir ${RunCMake_SOURCE_DIR}/EnvGenerator)
336 set(ENV{CMAKE_GENERATOR_INSTANCE} "instance")
337 set(ENV{CMAKE_GENERATOR_PLATFORM} "platform")
338 set(ENV{CMAKE_GENERATOR_TOOLSET} "toolset")
339 run_cmake_command(Envgen-warnings ${CMAKE_COMMAND} -G)
340 unset(ENV{CMAKE_GENERATOR_INSTANCE})
341 unset(ENV{CMAKE_GENERATOR_PLATFORM})
342 unset(ENV{CMAKE_GENERATOR_TOOLSET})
344 # Test CMAKE_GENERATOR without actual configuring
345 run_cmake_command(Envgen-unset ${CMAKE_COMMAND} -G)
346 set(ENV{CMAKE_GENERATOR} "Ninja")
347 run_cmake_command(Envgen-ninja ${CMAKE_COMMAND} -G)
348 set(ENV{CMAKE_GENERATOR} "NoSuchGenerator")
349 run_cmake_command(Envgen-bad ${CMAKE_COMMAND} -G)
350 unset(ENV{CMAKE_GENERATOR})
352 if(RunCMake_GENERATOR MATCHES "Visual Studio.*")
353 set(ENV{CMAKE_GENERATOR} "${RunCMake_GENERATOR}")
354 run_cmake_command(Envgen ${CMAKE_COMMAND} ${source_dir})
355 # Toolset is available since VS 2010.
356 if(RunCMake_GENERATOR MATCHES "Visual Studio [1-9][0-9]")
357 set(ENV{CMAKE_GENERATOR_TOOLSET} "invalid")
358 # Envvar shouldn't affect existing build tree
359 run_cmake_command(Envgen-toolset-existing ${CMAKE_COMMAND} -E chdir ..
360 ${CMAKE_COMMAND} --build Envgen-build)
361 run_cmake_command(Envgen-toolset-invalid ${CMAKE_COMMAND} ${source_dir})
362 # Command line -G implies -T""
363 run_cmake_command(Envgen-G-implicit-toolset ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir})
364 run_cmake_command(Envgen-T-toolset ${CMAKE_COMMAND} -T "fromcli" ${source_dir})
365 unset(ENV{CMAKE_GENERATOR_TOOLSET})
367 # Platform can be set only if not in generator name.
368 if(RunCMake_GENERATOR MATCHES "^Visual Studio [0-9]+ [0-9]+$")
369 set(ENV{CMAKE_GENERATOR_PLATFORM} "invalid")
370 # Envvar shouldn't affect existing build tree
371 run_cmake_command(Envgen-platform-existing ${CMAKE_COMMAND} -E chdir ..
372 ${CMAKE_COMMAND} --build Envgen-build)
373 if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
374 set(RunCMake-stderr-file "Envgen-platform-invalid-stderr-vs9.txt")
376 run_cmake_command(Envgen-platform-invalid ${CMAKE_COMMAND} ${source_dir})
377 unset(RunCMake-stderr-file)
378 # Command line -G implies -A""
379 run_cmake_command(Envgen-G-implicit-platform ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir})
380 if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
381 set(RunCMake-stderr-file "Envgen-A-platform-stderr-vs9.txt")
383 run_cmake_command(Envgen-A-platform ${CMAKE_COMMAND} -A "fromcli" ${source_dir})
384 unset(RunCMake-stderr-file)
385 unset(ENV{CMAKE_GENERATOR_PLATFORM})
387 # Instance is available since VS 2017.
388 if(RunCMake_GENERATOR MATCHES "Visual Studio 1[567].*")
389 set(ENV{CMAKE_GENERATOR_INSTANCE} "invalid")
390 # Envvar shouldn't affect existing build tree
391 run_cmake_command(Envgen-instance-existing ${CMAKE_COMMAND} -E chdir ..
392 ${CMAKE_COMMAND} --build Envgen-build)
393 run_cmake_command(Envgen-instance-invalid ${CMAKE_COMMAND} ${source_dir})
394 unset(ENV{CMAKE_GENERATOR_INSTANCE})
396 unset(ENV{CMAKE_GENERATOR})
399 run_EnvironmentGenerator()
401 function(run_EnvironmentExportCompileCommands)
402 set(RunCMake_TEST_SOURCE_DIR ${RunCMake_SOURCE_DIR}/env-export-compile-commands)
404 run_cmake(env-export-compile-commands-unset)
406 set(ENV{CMAKE_EXPORT_COMPILE_COMMANDS} ON)
407 run_cmake(env-export-compile-commands-set)
409 set(RunCMake_TEST_OPTIONS -DCMAKE_EXPORT_COMPILE_COMMANDS=OFF)
410 run_cmake(env-export-compile-commands-override)
412 unset(ENV{CMAKE_EXPORT_COMPILE_COMMANDS})
413 endfunction(run_EnvironmentExportCompileCommands)
415 if(RunCMake_GENERATOR MATCHES "Unix Makefiles" OR RunCMake_GENERATOR MATCHES "Ninja")
416 run_EnvironmentExportCompileCommands()
419 function(run_EnvironmentBuildType)
420 set(ENV{CMAKE_BUILD_TYPE} "BuildTypeEnv")
421 run_cmake(EnvBuildType)
422 run_cmake_with_options(EnvBuildTypeIgnore -DCMAKE_BUILD_TYPE=BuildTypeOpt)
423 unset(ENV{CMAKE_BUILD_TYPE})
426 function(run_EnvironmentConfigTypes)
427 set(ENV{CMAKE_CONFIGURATION_TYPES} "ConfigTypesEnv")
428 run_cmake(EnvConfigTypes)
429 run_cmake_with_options(EnvConfigTypesIgnore -DCMAKE_CONFIGURATION_TYPES=ConfigTypesOpt)
430 unset(ENV{CMAKE_CONFIGURATION_TYPES})
433 if(RunCMake_GENERATOR MATCHES "Make|^Ninja$")
434 run_EnvironmentBuildType()
435 elseif(RunCMake_GENERATOR MATCHES "Ninja Multi-Config|Visual Studio|Xcode")
436 run_EnvironmentConfigTypes()
439 function(run_EnvironmentToolchain)
440 set(ENV{CMAKE_TOOLCHAIN_FILE} "${RunCMake_SOURCE_DIR}/EnvToolchain-toolchain.cmake")
441 run_cmake(EnvToolchainAbsolute)
442 run_cmake_with_options(EnvToolchainIgnore -DCMAKE_TOOLCHAIN_FILE=)
443 unset(ENV{CMAKE_TOOLCHAIN_FILE})
445 set(ENV{CMAKE_TOOLCHAIN_FILE} "EnvToolchain-toolchain.cmake")
446 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/EnvToolchainRelative-build)
447 set(RunCMake_TEST_NO_CLEAN 1)
448 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
449 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
450 configure_file("${RunCMake_SOURCE_DIR}/EnvToolchain-toolchain.cmake" "${RunCMake_TEST_BINARY_DIR}/EnvToolchain-toolchain.cmake" COPYONLY)
451 run_cmake(EnvToolchainRelative)
452 unset(ENV{CMAKE_TOOLCHAIN_FILE})
453 unset(RunCMake_TEST_NO_CLEAN)
455 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/EnvToolchainNone-build)
456 run_cmake(EnvToolchainNone)
457 set(RunCMake_TEST_NO_CLEAN 1)
458 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles")
459 set(ENV{CMAKE_TOOLCHAIN_FILE} "${RunCMake_SOURCE_DIR}/EnvToolchain-toolchain.cmake")
460 run_cmake_command(EnvToolchainNoneExisting ${CMAKE_COMMAND} .)
461 unset(ENV{CMAKE_TOOLCHAIN_FILE})
462 unset(RunCMake_TEST_NO_CLEAN)
464 run_EnvironmentToolchain()
466 function(run_EnvironmentColor)
467 set(ENV{CMAKE_COLOR_DIAGNOSTICS} "ON")
468 run_cmake(EnvColorOn)
469 unset(ENV{CMAKE_COLOR_DIAGNOSTICS})
470 run_cmake(EnvColorDefault)
472 run_EnvironmentColor()
474 if(RunCMake_GENERATOR STREQUAL "Ninja")
475 # Use a single build tree for a few tests without cleaning.
476 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Build-build)
477 set(RunCMake_TEST_NO_CLEAN 1)
478 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
479 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
481 set(RunCMake_TEST_OPTIONS -DCMAKE_VERBOSE_MAKEFILE=1)
483 unset(RunCMake_TEST_OPTIONS)
484 run_cmake_command(Build-ninja-v ${CMAKE_COMMAND} --build .)
486 unset(RunCMake_TEST_BINARY_DIR)
487 unset(RunCMake_TEST_NO_CLEAN)
490 run_cmake_command(E_create_symlink-no-arg
491 ${CMAKE_COMMAND} -E create_symlink
493 run_cmake_command(E_create_symlink-missing-dir
494 ${CMAKE_COMMAND} -E create_symlink T missing-dir/L
497 # Use a single build tree for a few tests without cleaning.
498 # These tests are special on Windows since it will only fail if the user
499 # running the test does not have the priveldge to create symlinks. If this
500 # happens we clear the msg in the -check.cmake and say that the test passes
501 set(RunCMake_DEFAULT_stderr "(A required privilege is not held by the client)?")
502 set(RunCMake_TEST_BINARY_DIR
503 ${RunCMake_BINARY_DIR}/E_create_symlink-broken-build)
504 set(RunCMake_TEST_NO_CLEAN 1)
505 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
506 run_cmake_command(E_create_symlink-broken-create
507 ${CMAKE_COMMAND} -E create_symlink T L
509 run_cmake_command(E_create_symlink-broken-replace
510 ${CMAKE_COMMAND} -E create_symlink . L
512 unset(RunCMake_TEST_BINARY_DIR)
513 unset(RunCMake_TEST_NO_CLEAN)
514 unset(RunCMake_DEFAULT_stderr)
516 run_cmake_command(E_create_symlink-no-replace-dir
517 ${CMAKE_COMMAND} -E create_symlink T .
520 #create hard link tests
521 run_cmake_command(E_create_hardlink-no-arg
522 ${CMAKE_COMMAND} -E create_hardlink
525 set(dir ${RunCMake_BINARY_DIR}/hardlink_tests)
526 file(REMOVE_RECURSE "${dir}")
527 file(MAKE_DIRECTORY ${dir})
529 run_cmake_command(E_create_hardlink-non-existent-source
530 ${CMAKE_COMMAND} -E create_hardlink ${dir}/I_dont_exist ${dir}/link
535 run_cmake_command(E_create_hardlink-ok
536 ${CMAKE_COMMAND} -E create_hardlink ${dir}/1 ${dir}/1-link
539 run_cmake_command(E_create_hardlink-no-directory
540 ${CMAKE_COMMAND} -E create_hardlink ${dir}/1 ${dir}/a/1-link
543 #On Windows, if the user does not have sufficient privileges
544 #don't fail this test
545 set(RunCMake_DEFAULT_stderr "(A required privilege is not held by the client)?")
546 run_cmake_command(E_create_hardlink-unresolved-symlink-prereq
547 ${CMAKE_COMMAND} -E create_symlink ${dir}/1 ${dir}/1-symlink
549 file(REMOVE ${dir}/1)
551 run_cmake_command(E_create_hardlink-unresolved-symlink
552 ${CMAKE_COMMAND} -E create_hardlink ${dir}/1-symlink ${dir}/1s-link
554 unset(RunCMake_DEFAULT_stderr)
556 set(in ${RunCMake_SOURCE_DIR}/copy_input)
557 set(out ${RunCMake_BINARY_DIR}/copy_output)
558 file(REMOVE_RECURSE "${out}")
559 file(MAKE_DIRECTORY ${out})
560 run_cmake_command(E_copy-one-source-file
561 ${CMAKE_COMMAND} -E copy ${out}/f1.txt)
562 run_cmake_command(E_copy-one-source-directory-target-is-directory
563 ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${out})
564 run_cmake_command(E_copy-three-source-files-target-is-directory
565 ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out})
566 run_cmake_command(E_copy-three-source-files-target-is-file
567 ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}/f1.txt)
568 run_cmake_command(E_copy-two-good-and-one-bad-source-files-target-is-directory
569 ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/not_existing_file.bad ${in}/f3.txt ${out})
570 run_cmake_command(E_copy_if_different-one-source-directory-target-is-directory
571 ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${out})
572 run_cmake_command(E_copy_if_different-three-source-files-target-is-directory
573 ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out})
574 run_cmake_command(E_copy_if_different-three-source-files-target-is-file
575 ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}/f1.txt)
579 set(in ${RunCMake_SOURCE_DIR}/copy_input)
580 set(out ${RunCMake_BINARY_DIR}/copy_directory_output)
581 set(outfile ${out}/file_for_test.txt)
582 file(REMOVE_RECURSE "${out}")
583 file(MAKE_DIRECTORY ${out})
584 file(WRITE ${outfile} "")
585 run_cmake_command(E_copy_directory-three-source-files-target-is-directory
586 ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${out})
587 run_cmake_command(E_copy_directory-three-source-files-target-is-file
588 ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${outfile})
589 run_cmake_command(E_copy_directory-three-source-files-target-is-not-exist
590 ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${out}/not_existing_directory)
595 set(out ${RunCMake_BINARY_DIR}/make_directory_output)
596 set(outfile ${out}/file_for_test.txt)
597 file(REMOVE_RECURSE "${out}")
598 file(MAKE_DIRECTORY ${out})
599 file(WRITE ${outfile} "")
600 run_cmake_command(E_make_directory-three-directories
601 ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${out}/d2)
602 run_cmake_command(E_remove_directory-three-directories
603 ${CMAKE_COMMAND} -E remove_directory ${out}/d1 ${out}/d2 ${out}/d2)
604 run_cmake_command(E_make_directory-directory-with-parent
605 ${CMAKE_COMMAND} -E make_directory ${out}/parent/child)
606 run_cmake_command(E_remove_directory-directory-with-parent
607 ${CMAKE_COMMAND} -E remove_directory ${out}/parent)
608 run_cmake_command(E_make_directory-two-directories-and-file
609 ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${outfile})
610 run_cmake_command(E_remove_directory-two-directories-and-file
611 ${CMAKE_COMMAND} -E remove_directory ${out}/d1 ${out}/d2 ${outfile})
614 file(MAKE_DIRECTORY ${out}/dir)
615 file(CREATE_LINK ${out}/dir ${out}/link_dir SYMBOLIC)
616 file(CREATE_LINK ${outfile} ${out}/link_file_for_test.txt SYMBOLIC)
617 run_cmake_command(E_remove_directory-symlink-dir
618 ${CMAKE_COMMAND} -E remove_directory ${out}/link_dir)
619 run_cmake_command(E_remove_directory-symlink-file
620 ${CMAKE_COMMAND} -E remove_directory ${out}/link_file_for_test.txt)
626 set(out ${RunCMake_BINARY_DIR}/rm_tests)
627 file(REMOVE_RECURSE "${out}")
628 file(MAKE_DIRECTORY ${out})
629 file(TOUCH ${out}/existing.txt)
630 run_cmake_command(E_rm_file_force_existing
631 ${CMAKE_COMMAND} -E rm -f ${out}/existing.txt)
632 file(TOUCH ${out}/existing.txt)
633 run_cmake_command(E_rm_file_non_force_existing
634 ${CMAKE_COMMAND} -E rm ${out}/existing.txt)
635 run_cmake_command(E_rm_file_force_non_existing
636 ${CMAKE_COMMAND} -E rm -f ${out}/not_existing.txt)
637 run_cmake_command(E_rm_file_non_force_non_existing
638 ${CMAKE_COMMAND} -E rm ${out}/not_existing.txt)
640 file(TOUCH ${out}/existing.txt)
641 run_cmake_command(E_rm_file_recursive_existing
642 ${CMAKE_COMMAND} -E rm -r ${out}/existing.txt)
643 run_cmake_command(E_rm_file_recursive_non_existing
644 ${CMAKE_COMMAND} -E rm -r ${out}/not_existing.txt)
646 file(MAKE_DIRECTORY ${out}/d1 ${out}/d2)
647 run_cmake_command(E_rm_non_recursive_directory-two-directories
648 ${CMAKE_COMMAND} -E rm ${out}/d1 ${out}/d2)
650 run_cmake_command(E_rm_recursive_directory-two-directories
651 ${CMAKE_COMMAND} -E rm -R ${out}/d1 ${out}/d2)
653 run_cmake_command(E_rm_no_file_specified
654 ${CMAKE_COMMAND} -E rm -rf)
656 run_cmake_command(E_rm_empty_file_specified
657 ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_rm_empty_file_specified.cmake)
659 run_cmake_command(E_rm_bad_argument
660 ${CMAKE_COMMAND} -E rm -rd ${out}/d1 ${out}/d2)
662 file(MAKE_DIRECTORY ${out}/d1 ${out}/d2)
663 file(WRITE ${out}/test.txt "")
664 run_cmake_command(E_rm_force_recursive_directory_with_files
665 ${CMAKE_COMMAND} -E rm -rf ${out}/)
667 run_cmake_command(E_rm_force_recursive_non_existing_file
668 ${CMAKE_COMMAND} -E rm -Rf ${out}/test.txt)
670 if(NOT WIN32 AND NOT CYGWIN)
671 file(MAKE_DIRECTORY ${out})
672 file(TOUCH ${out}/existing.txt)
673 file(MAKE_DIRECTORY ${out}/dir)
674 file(TOUCH ${out}/dir/existing.txt) # add a file in the folder
675 file(CREATE_LINK ${out}/dir ${out}/link_dir SYMBOLIC)
676 file(CREATE_LINK ${out}/existing.txt ${out}/existing_file_link.txt SYMBOLIC)
677 file(CREATE_LINK ${out}/non_existing.txt ${out}/non_existing_file_link.txt SYMBOLIC)
678 run_cmake_command(E_rm_file_link_existing
679 ${CMAKE_COMMAND} -E rm ${out}/existing_file_link.txt)
680 run_cmake_command(E_rm_directory_link_existing
681 ${CMAKE_COMMAND} -E rm ${out}/link_dir)
682 run_cmake_command(E_rm_file_link_non_existing
683 ${CMAKE_COMMAND} -E rm ${out}/non_existing_file_link.txt)
685 file(CREATE_LINK ${out}/dir ${out}/link_dir SYMBOLIC)
686 file(CREATE_LINK ${out}/existing.txt ${out}/existing_file_link.txt SYMBOLIC)
687 file(CREATE_LINK ${out}/non_existing.txt ${out}/non_existing_file_link.txt SYMBOLIC)
688 run_cmake_command(E_rm_recursive_file_link_existing
689 ${CMAKE_COMMAND} -E rm -R ${out}/existing_file_link.txt)
690 run_cmake_command(E_rm_recursive_directory_link_existing
691 ${CMAKE_COMMAND} -E rm -r ${out}/link_dir)
692 run_cmake_command(E_rm_recursive_file_link_non_existing
693 ${CMAKE_COMMAND} -E rm -r ${out}/non_existing_file_link.txt)
698 set(out ${RunCMake_BINARY_DIR}/cat_tests)
699 file(REMOVE_RECURSE "${out}")
700 file(MAKE_DIRECTORY ${out})
701 run_cmake_command(E_cat_non_existing_file
702 ${CMAKE_COMMAND} -E cat ${out}/non-existing-file.txt)
704 if(UNIX AND NOT MSYS)
705 # test non readable file only if not root
707 COMMAND id -u $ENV{USER}
709 OUTPUT_STRIP_TRAILING_WHITESPACE)
711 if(NOT "${uid}" STREQUAL "0")
712 # Create non readable file
713 set(inside_folder "${out}/in")
714 file(MAKE_DIRECTORY ${inside_folder})
715 file(WRITE "${inside_folder}/non_readable_file.txt" "first file to append\n")
716 file(COPY "${inside_folder}/non_readable_file.txt" DESTINATION "${out}" FILE_PERMISSIONS OWNER_WRITE)
717 run_cmake_command(E_cat_non_readable_file
718 ${CMAKE_COMMAND} -E cat "${out}/non_readable_file.txt")
722 run_cmake_command(E_cat_option_not_handled
723 ${CMAKE_COMMAND} -E cat -f)
725 run_cmake_command(E_cat_directory
726 ${CMAKE_COMMAND} -E cat ${out})
728 file(WRITE "${out}/first_file.txt" "first file to append\n")
729 file(WRITE "${out}/second_file.txt" "second file to append\n")
730 file(WRITE "${out}/empty_file.txt" "")
731 file(WRITE "${out}/unicode_file.txt" "à éùç - í•œêµì–´") # Korean in Korean
732 run_cmake_command(E_cat_good_cat
733 ${CMAKE_COMMAND} -E cat "${out}/first_file.txt" "${out}/second_file.txt" "${out}/empty_file.txt" "${out}/unicode_file.txt")
735 run_cmake_command(E_cat_good_binary_cat
736 ${CMAKE_COMMAND} -E cat "${RunCMake_SOURCE_DIR}/E_cat_binary_files/binary.obj" "${RunCMake_SOURCE_DIR}/E_cat_binary_files/binary.obj")
738 # To test whether the double dash (--) works, we need to control the working directory
739 # in order to be able to pass a relative path that starts with a dash.
740 file(WRITE "${out}/-file-starting-with-dash.txt" "file starting with dash, not an option\n")
741 set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${out}")
742 run_cmake_command(E_cat-with-double-dash ${CMAKE_COMMAND} -E cat -- "-file-starting-with-dash.txt")
743 run_cmake_command(E_cat-without-double-dash ${CMAKE_COMMAND} -E cat "-file-starting-with-dash.txt")
744 unset(RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
747 run_cmake_command(E_env-no-command0 ${CMAKE_COMMAND} -E env)
748 run_cmake_command(E_env-no-command1 ${CMAKE_COMMAND} -E env TEST_ENV=1)
749 run_cmake_command(E_env-bad-arg1 ${CMAKE_COMMAND} -E env -bad-arg1)
750 run_cmake_command(E_env-set ${CMAKE_COMMAND} -E env TEST_ENV=1 ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_env-set.cmake)
751 run_cmake_command(E_env-unset ${CMAKE_COMMAND} -E env TEST_ENV=1 ${CMAKE_COMMAND} -E env --unset=TEST_ENV ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_env-unset.cmake)
753 # To test whether the double dash (--) works for the env command, we need a command that e.g. contains an equals sign (=)
754 # and would normally be interpreted as an NAME=VALUE environment variable.
755 # Ensuring such a command is done by simply copying the trivial exit_code executable with a different name.
756 cmake_path(GET EXIT_CODE_EXE FILENAME exit_code)
757 file(COPY_FILE "${EXIT_CODE_EXE}" "${RunCMake_BINARY_DIR}/env=${exit_code}")
758 run_cmake_command(E_env-with-double-dash ${CMAKE_COMMAND} -E env TEST_ENV=1 -- "${RunCMake_BINARY_DIR}/env=${exit_code}" zero_exit)
759 run_cmake_command(E_env-without-double-dash ${CMAKE_COMMAND} -E env TEST_ENV=1 "${RunCMake_BINARY_DIR}/env=${exit_code}" zero_exit)
761 run_cmake_command(E_md5sum-dir ${CMAKE_COMMAND} -E md5sum .)
762 run_cmake_command(E_sha1sum-dir ${CMAKE_COMMAND} -E sha1sum .)
763 run_cmake_command(E_sha224sum-dir ${CMAKE_COMMAND} -E sha224sum .)
764 run_cmake_command(E_sha256sum-dir ${CMAKE_COMMAND} -E sha256sum .)
765 run_cmake_command(E_sha384sum-dir ${CMAKE_COMMAND} -E sha384sum .)
766 run_cmake_command(E_sha512sum-dir ${CMAKE_COMMAND} -E sha512sum .)
768 run_cmake_command(E_md5sum-no-file ${CMAKE_COMMAND} -E md5sum nonexisting)
769 run_cmake_command(E_sha1sum-no-file ${CMAKE_COMMAND} -E sha1sum nonexisting)
770 run_cmake_command(E_sha224sum-no-file ${CMAKE_COMMAND} -E sha224sum nonexisting)
771 run_cmake_command(E_sha256sum-no-file ${CMAKE_COMMAND} -E sha256sum nonexisting)
772 run_cmake_command(E_sha384sum-no-file ${CMAKE_COMMAND} -E sha384sum nonexisting)
773 run_cmake_command(E_sha512sum-no-file ${CMAKE_COMMAND} -E sha512sum nonexisting)
775 file(WRITE "${RunCMake_BINARY_DIR}/dummy" "dummy")
776 run_cmake_command(E_md5sum ${CMAKE_COMMAND} -E md5sum ../dummy)
777 run_cmake_command(E_md5sum-mixed ${CMAKE_COMMAND} -E md5sum . ../dummy nonexisting)
778 run_cmake_command(E_sha1sum ${CMAKE_COMMAND} -E sha1sum ../dummy)
779 run_cmake_command(E_sha224sum ${CMAKE_COMMAND} -E sha224sum ../dummy)
780 run_cmake_command(E_sha256sum ${CMAKE_COMMAND} -E sha256sum ../dummy)
781 run_cmake_command(E_sha384sum ${CMAKE_COMMAND} -E sha384sum ../dummy)
782 run_cmake_command(E_sha512sum ${CMAKE_COMMAND} -E sha512sum ../dummy)
783 file(REMOVE "${RunCMake_BINARY_DIR}/dummy")
785 set(RunCMake_DEFAULT_stderr ".")
786 run_cmake_command(E_sleep-no-args ${CMAKE_COMMAND} -E sleep)
787 unset(RunCMake_DEFAULT_stderr)
788 run_cmake_command(E_sleep-bad-arg1 ${CMAKE_COMMAND} -E sleep x)
789 run_cmake_command(E_sleep-bad-arg2 ${CMAKE_COMMAND} -E sleep 1 -1)
790 run_cmake_command(E_sleep-one-tenth ${CMAKE_COMMAND} -E sleep 0.1)
792 run_cmake_command(P_directory ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR})
793 run_cmake_command(P_working-dir ${CMAKE_COMMAND} -DEXPECTED_WORKING_DIR=${RunCMake_BINARY_DIR}/P_working-dir-build -P ${RunCMake_SOURCE_DIR}/P_working-dir.cmake)
794 # Documented to return the same result as above even if -S and -B are set to something else.
795 # Tests the values of CMAKE_BINARY_DIR CMAKE_CURRENT_BINARY_DIR CMAKE_SOURCE_DIR CMAKE_CURRENT_SOURCE_DIR.
796 run_cmake_command(P_working-dir ${CMAKE_COMMAND} -DEXPECTED_WORKING_DIR=${RunCMake_BINARY_DIR}/P_working-dir-build -P ${RunCMake_SOURCE_DIR}/P_working-dir.cmake -S something_else -B something_else_1)
798 # Place an initial cache where C_basic will find it when passed the relative path "..".
799 file(COPY ${RunCMake_SOURCE_DIR}/C_basic_initial-cache.txt DESTINATION ${RunCMake_BINARY_DIR})
800 run_cmake_with_options(C_basic -C ../C_basic_initial-cache.txt)
801 run_cmake_with_options(C_basic_fullpath -C ${RunCMake_BINARY_DIR}/C_basic_initial-cache.txt)
803 set(RunCMake_TEST_OPTIONS
804 "-DFOO=-DBAR:BOOL=BAZ")
805 run_cmake(D_nested_cache)
807 set(RunCMake_TEST_OPTIONS
808 "-DFOO:STRING=-DBAR:BOOL=BAZ")
809 run_cmake(D_typed_nested_cache)
811 set(RunCMake_TEST_OPTIONS -Wno-dev)
813 unset(RunCMake_TEST_OPTIONS)
815 set(RunCMake_TEST_OPTIONS -Wdev)
817 unset(RunCMake_TEST_OPTIONS)
819 set(RunCMake_TEST_OPTIONS -Werror=dev)
820 run_cmake(Werror_dev)
821 unset(RunCMake_TEST_OPTIONS)
823 set(RunCMake_TEST_OPTIONS -Wno-error=dev)
824 run_cmake(Wno-error_deprecated)
825 unset(RunCMake_TEST_OPTIONS)
827 # -Wdev should not override deprecated options if specified
828 set(RunCMake_TEST_OPTIONS -Wdev -Wno-deprecated)
829 run_cmake(Wno-deprecated)
830 unset(RunCMake_TEST_OPTIONS)
831 set(RunCMake_TEST_OPTIONS -Wno-deprecated -Wdev)
832 run_cmake(Wno-deprecated)
833 unset(RunCMake_TEST_OPTIONS)
835 # -Wdev should enable deprecated warnings as well
836 set(RunCMake_TEST_OPTIONS -Wdev)
837 run_cmake(Wdeprecated)
838 unset(RunCMake_TEST_OPTIONS)
840 # -Werror=dev should enable deprecated errors as well
841 set(RunCMake_TEST_OPTIONS -Werror=dev)
842 run_cmake(Werror_deprecated)
843 unset(RunCMake_TEST_OPTIONS)
845 set(RunCMake_TEST_OPTIONS -Wdeprecated)
846 run_cmake(Wdeprecated)
847 unset(RunCMake_TEST_OPTIONS)
849 set(RunCMake_TEST_OPTIONS -Wno-deprecated)
850 run_cmake(Wno-deprecated)
851 unset(RunCMake_TEST_OPTIONS)
853 set(RunCMake_TEST_OPTIONS -Werror=deprecated)
854 run_cmake(Werror_deprecated)
855 unset(RunCMake_TEST_OPTIONS)
857 set(RunCMake_TEST_OPTIONS -Wno-error=deprecated)
858 run_cmake(Wno-error_deprecated)
859 unset(RunCMake_TEST_OPTIONS)
861 set(RunCMake_TEST_OPTIONS -Werror=deprecated -Wno-error=deprecated)
862 run_cmake(Wno-error_deprecated)
863 unset(RunCMake_TEST_OPTIONS)
865 # Dev warnings should be on by default
868 # Deprecated warnings should be on by default
869 run_cmake(Wdeprecated)
871 # Conflicting -W options should honor the last value
872 set(RunCMake_TEST_OPTIONS -Wno-dev -Wdev)
874 unset(RunCMake_TEST_OPTIONS)
875 set(RunCMake_TEST_OPTIONS -Wdev -Wno-dev)
877 unset(RunCMake_TEST_OPTIONS)
879 run_cmake_command(W_bad-arg1 ${CMAKE_COMMAND} -B DummyBuildDir -W)
880 run_cmake_command(W_bad-arg2 ${CMAKE_COMMAND} -B DummyBuildDir -Wno-)
881 run_cmake_command(W_bad-arg3 ${CMAKE_COMMAND} -B DummyBuildDir -Werror=)
883 set(RunCMake_TEST_OPTIONS --debug-output)
884 run_cmake(debug-output)
885 unset(RunCMake_TEST_OPTIONS)
887 set(RunCMake_TEST_OPTIONS --trace)
889 unset(RunCMake_TEST_OPTIONS)
891 set(RunCMake_TEST_OPTIONS --trace-expand)
892 run_cmake(trace-expand)
893 unset(RunCMake_TEST_OPTIONS)
895 set(RunCMake_TEST_OPTIONS --trace-expand --warn-uninitialized)
896 run_cmake(trace-expand-warn-uninitialized)
897 unset(RunCMake_TEST_OPTIONS)
899 set(RunCMake_TEST_OPTIONS --trace-redirect=${RunCMake_BINARY_DIR}/redirected.trace)
900 run_cmake(trace-redirect)
901 unset(RunCMake_TEST_OPTIONS)
903 set(RunCMake_TEST_OPTIONS --trace-redirect=/no/such/file.txt)
904 run_cmake(trace-redirect-nofile)
905 unset(RunCMake_TEST_OPTIONS)
907 set(RunCMake_TEST_OPTIONS --trace --trace-format=json-v1 --trace-redirect=${RunCMake_BINARY_DIR}/json-v1.trace)
908 run_cmake(trace-json-v1)
909 unset(RunCMake_TEST_OPTIONS)
911 set(RunCMake_TEST_OPTIONS --trace-expand --trace-format=json-v1 --trace-redirect=${RunCMake_BINARY_DIR}/json-v1-expand.trace)
912 run_cmake(trace-json-v1-expand)
913 unset(RunCMake_TEST_OPTIONS)
915 set(RunCMake_TEST_OPTIONS -Wno-deprecated --warn-uninitialized)
916 run_cmake(warn-uninitialized)
917 unset(RunCMake_TEST_OPTIONS)
919 set(RunCMake_TEST_OPTIONS --trace-source=trace-only-this-file.cmake)
920 run_cmake(trace-source)
921 unset(RunCMake_TEST_OPTIONS)
923 set(RunCMake_TEST_OPTIONS --debug-trycompile)
924 run_cmake(debug-trycompile)
925 unset(RunCMake_TEST_OPTIONS)
927 function(run_cmake_depends)
928 set(RunCMake_TEST_SOURCE_DIR "${RunCMake_SOURCE_DIR}/cmake_depends")
929 set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/cmake_depends-build")
930 set(RunCMake_TEST_NO_CLEAN 1)
931 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
932 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
933 file(WRITE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/DependInfo.cmake" "
934 set(CMAKE_DEPENDS_LANGUAGES \"C\")
935 set(CMAKE_DEPENDS_CHECK_C
936 \"${RunCMake_TEST_SOURCE_DIR}/test.c\"
937 \"${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/test.c.o\"
940 file(WRITE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/CMakeDirectoryInformation.cmake" "
941 set(CMAKE_RELATIVE_PATH_TOP_SOURCE \"${RunCMake_TEST_SOURCE_DIR}\")
942 set(CMAKE_RELATIVE_PATH_TOP_BINARY \"${RunCMake_TEST_BINARY_DIR}\")
944 run_cmake_command(cmake_depends ${CMAKE_COMMAND} -E cmake_depends
946 ${RunCMake_TEST_SOURCE_DIR} ${RunCMake_TEST_SOURCE_DIR}
947 ${RunCMake_TEST_BINARY_DIR} ${RunCMake_TEST_BINARY_DIR}
948 ${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/DependInfo.cmake
953 function(reject_fifo)
954 find_program(BASH_EXECUTABLE bash)
956 set(BASH_COMMAND_ARGUMENT "'${CMAKE_COMMAND}' -P <(echo 'return()')")
957 run_cmake_command(reject_fifo ${BASH_EXECUTABLE} -c ${BASH_COMMAND_ARGUMENT})
960 if(CMAKE_HOST_UNIX AND NOT CMAKE_SYSTEM_NAME STREQUAL "CYGWIN" AND NOT CMAKE_SYSTEM_NAME STREQUAL "MSYS")
962 run_cmake_command(closed_stdin sh -c "\"${CMAKE_COMMAND}\" --version <&-")
963 run_cmake_command(closed_stdout sh -c "\"${CMAKE_COMMAND}\" --version >&-")
964 run_cmake_command(closed_stderr sh -c "\"${CMAKE_COMMAND}\" --version 2>&-")
965 run_cmake_command(closed_stdall sh -c "\"${CMAKE_COMMAND}\" --version <&- >&- 2>&-")
968 function(run_llvm_rc)
969 set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/llvm_rc-build")
970 set(RunCMake_TEST_NO_CLEAN 1)
971 file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
972 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
973 run_cmake_command(llvm_rc_no_args ${CMAKE_COMMAND} -E cmake_llvm_rc)
974 run_cmake_command(llvm_rc_no_-- ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ${CMAKE_COMMAND} -E echo "This is a test")
975 run_cmake_command(llvm_rc_empty_preprocessor ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ++ ${CMAKE_COMMAND} -E echo "This is a test")
976 run_cmake_command(llvm_rc_failing_first_command ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ${CMAKE_COMMAND} -P FailedProgram.cmake ++ ${CMAKE_COMMAND} -E echo "This is a test")
977 run_cmake_command(llvm_rc_failing_second_command ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ${CMAKE_COMMAND} -E echo "This is a test" ++ ${CMAKE_COMMAND} -P FailedProgram.cmake )
978 if(EXISTS ${RunCMake_TEST_BINARY_DIR}/test.tmp)
979 message(SEND_ERROR "${test} - FAILED:\n"
980 "test.tmp was not deleted")
982 file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir")
983 run_cmake_command(llvm_rc_full_run ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir/source_file test.tmp ${CMAKE_COMMAND} -E echo "This is a test" ++ ${LLVM_RC} -bad /FO SOURCE_DIR/llvmrc.result test.tmp )
984 if(EXISTS ${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir/test.tmp)
985 message(SEND_ERROR "${test} - FAILED:\n"
986 "test.tmp was not deleted")
988 file(READ ${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir/llvmrc.result LLVMRC_RESULT)
989 if(NOT "${LLVMRC_RESULT}" STREQUAL "This is a test\n")
990 message(SEND_ERROR "${test} - FAILED:\n"
991 "llvmrc.result was not created")
997 set(RunCMake_TEST_OPTIONS --profiling-output=/no/such/file.txt --profiling-format=google-trace)
998 run_cmake(profiling-all-params)
999 unset(RunCMake_TEST_OPTIONS)
1001 set(RunCMake_TEST_OPTIONS --profiling-output=/no/such/file.txt --profiling-format=invalid-format)
1002 run_cmake(profiling-invalid-format)
1003 unset(RunCMake_TEST_OPTIONS)
1005 set(RunCMake_TEST_OPTIONS --profiling-output=/no/such/file.txt)
1006 run_cmake(profiling-missing-format)
1007 unset(RunCMake_TEST_OPTIONS)
1009 set(RunCMake_TEST_OPTIONS --profiling-format=google-trace)
1010 run_cmake(profiling-missing-output)
1011 unset(RunCMake_TEST_OPTIONS)
1013 set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/profiling-test")
1014 set(ProfilingTestOutput ${RunCMake_TEST_BINARY_DIR}/output.json)
1015 set(RunCMake_TEST_OPTIONS --profiling-format=google-trace --profiling-output=${ProfilingTestOutput})
1016 run_cmake(ProfilingTest)
1017 unset(RunCMake_TEST_OPTIONS)
1019 if(RunCMake_GENERATOR MATCHES "^Visual Studio 10 2010")
1020 run_cmake_with_options(DeprecateVS10-WARN-ON -DCMAKE_WARN_VS10=ON)
1021 unset(ENV{CMAKE_WARN_VS10})
1022 run_cmake(DeprecateVS10-WARN-ON)
1023 run_cmake_with_options(DeprecateVS10-WARN-OFF -DCMAKE_WARN_VS10=OFF)