RunCMakeTest.cmake 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. cmake_minimum_required(VERSION 3.1)
  2. include(RunCMake)
  3. run_cmake_command(NoArgs ${CMAKE_COMMAND})
  4. run_cmake_command(InvalidArg1 ${CMAKE_COMMAND} -invalid)
  5. run_cmake_command(InvalidArg2 ${CMAKE_COMMAND} --invalid)
  6. run_cmake_command(Wizard ${CMAKE_COMMAND} -i)
  7. run_cmake_command(C-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -C)
  8. run_cmake_command(C-no-file ${CMAKE_COMMAND} -B DummyBuildDir -C nosuchcachefile.txt)
  9. run_cmake_command(Cno-file ${CMAKE_COMMAND} -B DummyBuildDir -Cnosuchcachefile.txt)
  10. run_cmake_command(cache-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeCache.txt)
  11. run_cmake_command(lists-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeLists.txt)
  12. run_cmake_command(D-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -D)
  13. run_cmake_command(D-no-src ${CMAKE_COMMAND} -B DummyBuildDir -D VAR=VALUE)
  14. run_cmake_command(Dno-src ${CMAKE_COMMAND} -B DummyBuildDir -DVAR=VALUE)
  15. run_cmake_command(U-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -U)
  16. run_cmake_command(U-no-src ${CMAKE_COMMAND} -B DummyBuildDir -U VAR)
  17. run_cmake_command(Uno-src ${CMAKE_COMMAND} -B DummyBuildDir -UVAR)
  18. run_cmake_command(E-no-arg ${CMAKE_COMMAND} -E)
  19. run_cmake_command(E_capabilities ${CMAKE_COMMAND} -E capabilities)
  20. run_cmake_command(E_capabilities-arg ${CMAKE_COMMAND} -E capabilities --extra-arg)
  21. 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)
  22. 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)
  23. 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)
  24. run_cmake_command(E_compare_files-ignore-eol-nonexistent ${CMAKE_COMMAND} -E compare_files --ignore-eol nonexistent_a nonexistent_b)
  25. run_cmake_command(E_compare_files-invalid-arguments ${CMAKE_COMMAND} -E compare_files file1.txt file2.txt file3.txt)
  26. run_cmake_command(E_echo_append ${CMAKE_COMMAND} -E echo_append)
  27. run_cmake_command(E_rename-no-arg ${CMAKE_COMMAND} -E rename)
  28. run_cmake_command(E_server ${CMAKE_COMMAND} -E server)
  29. run_cmake_command(E_true ${CMAKE_COMMAND} -E true)
  30. run_cmake_command(E_true-extraargs ${CMAKE_COMMAND} -E true ignored)
  31. run_cmake_command(E_false ${CMAKE_COMMAND} -E false)
  32. run_cmake_command(E_false-extraargs ${CMAKE_COMMAND} -E false ignored)
  33. run_cmake_command(E_touch_nocreate-no-arg ${CMAKE_COMMAND} -E touch_nocreate)
  34. run_cmake_command(E_touch-nonexistent-dir ${CMAKE_COMMAND} -E touch "${RunCMake_BINARY_DIR}/touch-nonexistent-dir/foo")
  35. run_cmake_command(E_time ${CMAKE_COMMAND} -E time ${CMAKE_COMMAND} -E echo "hello world")
  36. run_cmake_command(E_time-no-arg ${CMAKE_COMMAND} -E time)
  37. run_cmake_command(E___run_co_compile-no-iwyu ${CMAKE_COMMAND} -E __run_co_compile -- command-does-not-exist)
  38. run_cmake_command(E___run_co_compile-bad-iwyu ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist -- command-does-not-exist)
  39. run_cmake_command(E___run_co_compile-no--- ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist command-does-not-exist)
  40. run_cmake_command(E___run_co_compile-no-cc ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist --)
  41. run_cmake_command(G_no-arg ${CMAKE_COMMAND} -B DummyBuildDir -G)
  42. run_cmake_command(G_bad-arg ${CMAKE_COMMAND} -B DummyBuildDir -G NoSuchGenerator)
  43. run_cmake_command(P_no-arg ${CMAKE_COMMAND} -P)
  44. run_cmake_command(P_no-file ${CMAKE_COMMAND} -P nosuchscriptfile.cmake)
  45. run_cmake_command(P_arbitrary_args ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_DIR}/P_arbitrary_args.cmake" -- -DFOO)
  46. run_cmake_command(build-no-dir
  47. ${CMAKE_COMMAND} --build)
  48. run_cmake_command(build-no-cache
  49. ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR})
  50. run_cmake_command(build-unknown-command-short
  51. ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} -invalid-command)
  52. run_cmake_command(build-unknown-command-long
  53. ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} --invalid-command)
  54. run_cmake_command(build-unknown-command-partial-match
  55. ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} --targetinvalid)
  56. run_cmake_command(build-invalid-target-syntax
  57. ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} --target=invalid)
  58. run_cmake_command(build-no-generator
  59. ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-no-generator)
  60. run_cmake_command(build-bad-dir
  61. ${CMAKE_COMMAND} --build dir-does-not-exist)
  62. run_cmake_command(build-bad-generator
  63. ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-generator)
  64. run_cmake_command(install-prefix-no-arg ${CMAKE_COMMAND} -B DummyBuildDir --install-prefix)
  65. run_cmake_command(install-no-dir
  66. ${CMAKE_COMMAND} --install)
  67. run_cmake_command(install-bad-dir
  68. ${CMAKE_COMMAND} --install dir-does-not-exist)
  69. run_cmake_command(install-unknown-command-short
  70. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR} -invalid-command)
  71. run_cmake_command(install-unknown-command-long
  72. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR} --invalid-command)
  73. run_cmake_command(install-options-to-vars
  74. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-install-options-to-vars
  75. --strip --prefix /var/test --config sample --component pack)
  76. run_cmake_command(install-default-dir-permissions-all
  77. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
  78. --default-directory-permissions u=rwx,g=rx,o=rx)
  79. run_cmake_command(install-default-dir-permissions-afew
  80. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
  81. --default-directory-permissions u=rwx,g=rx)
  82. run_cmake_command(install-default-dir-permissions-none
  83. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars)
  84. run_cmake_command(install-default-dir-permissions-invalid-comma1
  85. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
  86. --default-directory-permissions u=rwxg=,x)
  87. run_cmake_command(install-default-dir-permissions-invalid-comma2
  88. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
  89. --default-directory-permissions u=rwxg,=x)
  90. run_cmake_command(install-default-dir-permissions-comma-at-the-end
  91. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
  92. --default-directory-permissions u=rwx,)
  93. run_cmake_command(install-default-dir-permissions-invalid-assignment
  94. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
  95. --default-directory-permissions u=rwx,=x)
  96. run_cmake_command(install-default-dir-permissions-assignment-at-the-end
  97. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
  98. --default-directory-permissions u=rwx,g=)
  99. run_cmake_command(install-default-dir-permissions-assignment-at-the-beginning
  100. ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-permissions-install-options-to-vars
  101. --default-directory-permissions =u=rwx,g=rx)
  102. run_cmake_command(cache-bad-entry
  103. ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-entry/)
  104. run_cmake_command(cache-empty-entry
  105. ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-empty-entry/)
  106. function(run_ExplicitDirs)
  107. set(RunCMake_TEST_NO_CLEAN 1)
  108. set(RunCMake_TEST_NO_SOURCE_DIR 1)
  109. set(source_dir ${RunCMake_BINARY_DIR}/ExplicitDirsMissing)
  110. file(REMOVE_RECURSE "${source_dir}")
  111. file(MAKE_DIRECTORY "${source_dir}")
  112. file(WRITE ${source_dir}/CMakeLists.txt [=[
  113. cmake_minimum_required(VERSION 3.13)
  114. project(ExplicitDirsMissing LANGUAGES NONE)
  115. ]=])
  116. set(RunCMake_TEST_SOURCE_DIR "${source_dir}")
  117. set(RunCMake_TEST_BINARY_DIR "${source_dir}")
  118. run_cmake_with_options(no-S-B -DFOO=BAR)
  119. set(source_dir ${RunCMake_SOURCE_DIR}/ExplicitDirs)
  120. set(binary_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-build)
  121. set(RunCMake_TEST_SOURCE_DIR "${source_dir}")
  122. set(RunCMake_TEST_BINARY_DIR "${binary_dir}")
  123. file(REMOVE_RECURSE "${binary_dir}")
  124. run_cmake_with_options(S-arg -S ${source_dir} ${binary_dir})
  125. run_cmake_with_options(S-arg-reverse-order ${binary_dir} -S${source_dir} )
  126. run_cmake_with_options(S-no-arg -S )
  127. run_cmake_with_options(S-no-arg2 -S -T)
  128. run_cmake_with_options(S-B -S ${source_dir} -B ${binary_dir})
  129. # make sure that -B can explicitly construct build directories
  130. file(REMOVE_RECURSE "${binary_dir}")
  131. run_cmake_with_options(B-arg -B ${binary_dir} ${source_dir})
  132. file(REMOVE_RECURSE "${binary_dir}")
  133. run_cmake_with_options(B-arg-reverse-order ${source_dir} -B${binary_dir})
  134. run_cmake_with_options(B-no-arg -B )
  135. run_cmake_with_options(B-no-arg2 -B -T)
  136. file(REMOVE_RECURSE "${binary_dir}")
  137. run_cmake_with_options(B-S -B${binary_dir} -S${source_dir})
  138. message("copied to ${RunCMake_TEST_BINARY_DIR}/initial-cache.txt")
  139. file(COPY ${RunCMake_SOURCE_DIR}/C_buildsrcdir/initial-cache.txt DESTINATION ${RunCMake_TEST_BINARY_DIR})
  140. # CMAKE_BINARY_DIR should be determined by -B if specified, and CMAKE_SOURCE_DIR determined by -S if specified.
  141. # Path to initial-cache.txt is relative to the $PWD, which is normally set to ${RunCMake_TEST_BINARY_DIR}.
  142. run_cmake_with_options(C_buildsrcdir -B DummyBuildDir -S ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C initial-cache.txt)
  143. # Test that full path works, too.
  144. run_cmake_with_options(C_buildsrcdir -B DummyBuildDir -S ${RunCMake_SOURCE_DIR}/C_buildsrcdir/src -C ${RunCMake_TEST_BINARY_DIR}/initial-cache.txt)
  145. endfunction()
  146. run_ExplicitDirs()
  147. function(run_Toolchain)
  148. set(RunCMake_TEST_NO_SOURCE_DIR 1)
  149. set(source_dir ${RunCMake_SOURCE_DIR}/Toolchain)
  150. run_cmake_with_options(toolchain-no-arg -S ${source_dir} --toolchain=)
  151. run_cmake_with_options(toolchain-valid-abs-path -S ${source_dir} --toolchain "${source_dir}/toolchain.cmake")
  152. run_cmake_with_options(toolchain-valid-rel-src-path -S ${source_dir} --toolchain=toolchain.cmake)
  153. set(RunCMake_TEST_NO_CLEAN 1)
  154. set(binary_dir ${RunCMake_BINARY_DIR}/Toolchain-build)
  155. set(RunCMake_TEST_BINARY_DIR "${binary_dir}")
  156. file(REMOVE_RECURSE "${binary_dir}")
  157. # Test that we both search the binary dir for toolchain files, and it takes
  158. # precedence over source dir
  159. file(WRITE ${binary_dir}/toolchain.cmake [=[
  160. set(CMAKE_SYSTEM_NAME Linux)
  161. set(toolchain_file binary_dir)
  162. ]=])
  163. run_cmake_with_options(toolchain-valid-rel-build-path ${CMAKE_COMMAND} -S ${source_dir} -B ${binary_dir} --toolchain toolchain.cmake)
  164. endfunction()
  165. run_Toolchain()
  166. function(run_BuildDir)
  167. # Use a single build tree for a few tests without cleaning.
  168. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/BuildDir-build)
  169. set(RunCMake_TEST_NO_CLEAN 1)
  170. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  171. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  172. run_cmake(BuildDir)
  173. run_cmake_command(BuildDir--build ${CMAKE_COMMAND} -E chdir ..
  174. ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget)
  175. run_cmake_command(BuildDir--build-multiple-targets ${CMAKE_COMMAND} -E chdir ..
  176. ${CMAKE_COMMAND} --build BuildDir-build -t CustomTarget2 --target CustomTarget3)
  177. run_cmake_command(BuildDir--build-multiple-targets-fail ${CMAKE_COMMAND} -E chdir ..
  178. ${CMAKE_COMMAND} --build BuildDir-build -t CustomTargetFail --target CustomTarget3)
  179. run_cmake_command(BuildDir--build-multiple-targets-jobs ${CMAKE_COMMAND} -E chdir ..
  180. ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget CustomTarget2 -j2 --target CustomTarget3)
  181. run_cmake_command(BuildDir--build-multiple-targets-with-clean-first ${CMAKE_COMMAND} -E chdir ..
  182. ${CMAKE_COMMAND} --build BuildDir-build --target clean CustomTarget)
  183. run_cmake_command(BuildDir--build-multiple-targets-with-clean-second ${CMAKE_COMMAND} -E chdir ..
  184. ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget clean)
  185. run_cmake_command(BuildDir--build-jobs-bad-number ${CMAKE_COMMAND} -E chdir ..
  186. ${CMAKE_COMMAND} --build BuildDir-build -j 12ab)
  187. run_cmake_command(BuildDir--build-jobs-good-number ${CMAKE_COMMAND} -E chdir ..
  188. ${CMAKE_COMMAND} --build BuildDir-build -j 2)
  189. run_cmake_command(BuildDir--build-jobs-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
  190. ${CMAKE_COMMAND} --build BuildDir-build -j 2 --target CustomTarget)
  191. run_cmake_command(BuildDir--build--parallel-bad-number ${CMAKE_COMMAND} -E chdir ..
  192. ${CMAKE_COMMAND} --build BuildDir-build --parallel 12ab)
  193. run_cmake_command(BuildDir--build--parallel-good-number ${CMAKE_COMMAND} -E chdir ..
  194. ${CMAKE_COMMAND} --build BuildDir-build --parallel 2)
  195. run_cmake_command(BuildDir--build--parallel-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
  196. ${CMAKE_COMMAND} --build BuildDir-build --parallel 2 --target CustomTarget)
  197. run_cmake_command(BuildDir--build-jobs-no-space-bad-number ${CMAKE_COMMAND} -E chdir ..
  198. ${CMAKE_COMMAND} --build BuildDir-build -j12ab)
  199. run_cmake_command(BuildDir--build-jobs-no-space-good-number ${CMAKE_COMMAND} -E chdir ..
  200. ${CMAKE_COMMAND} --build BuildDir-build -j2)
  201. run_cmake_command(BuildDir--build-jobs-no-space-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
  202. ${CMAKE_COMMAND} --build BuildDir-build -j2 --target CustomTarget)
  203. run_cmake_command(BuildDir--build--parallel-no-space-bad-number ${CMAKE_COMMAND} -E chdir ..
  204. ${CMAKE_COMMAND} --build BuildDir-build --parallel12ab)
  205. run_cmake_command(BuildDir--build--parallel-no-space-good-number ${CMAKE_COMMAND} -E chdir ..
  206. ${CMAKE_COMMAND} --build BuildDir-build --parallel2)
  207. run_cmake_command(BuildDir--build--parallel-no-space-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
  208. ${CMAKE_COMMAND} --build BuildDir-build --parallel2 --target CustomTarget)
  209. run_cmake_command(BuildDir--build-jobs-zero ${CMAKE_COMMAND} -E chdir ..
  210. ${CMAKE_COMMAND} --build BuildDir-build -j 0)
  211. run_cmake_command(BuildDir--build--parallel-zero ${CMAKE_COMMAND} -E chdir ..
  212. ${CMAKE_COMMAND} --build BuildDir-build --parallel 0)
  213. run_cmake_command(BuildDir--build-jobs-large ${CMAKE_COMMAND} -E chdir ..
  214. ${CMAKE_COMMAND} --build BuildDir-build -j 4294967293)
  215. run_cmake_command(BuildDir--build--parallel-large ${CMAKE_COMMAND} -E chdir ..
  216. ${CMAKE_COMMAND} --build BuildDir-build --parallel 4294967293)
  217. # No default jobs for FreeBSD build command
  218. if(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  219. run_cmake_command(BuildDir--build-jobs-no-number ${CMAKE_COMMAND} -E chdir ..
  220. ${CMAKE_COMMAND} --build BuildDir-build -j)
  221. run_cmake_command(BuildDir--build-jobs-no-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
  222. ${CMAKE_COMMAND} --build BuildDir-build -j --target CustomTarget)
  223. if(RunCMake_GENERATOR MATCHES "Unix Makefiles" OR RunCMake_GENERATOR MATCHES "Ninja")
  224. run_cmake_command(BuildDir--build-jobs-no-number-trailing--invalid-target ${CMAKE_COMMAND} -E chdir ..
  225. ${CMAKE_COMMAND} --build BuildDir-build -j --target invalid-target)
  226. endif()
  227. run_cmake_command(BuildDir--build--parallel-no-number ${CMAKE_COMMAND} -E chdir ..
  228. ${CMAKE_COMMAND} --build BuildDir-build --parallel)
  229. run_cmake_command(BuildDir--build--parallel-no-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
  230. ${CMAKE_COMMAND} --build BuildDir-build --parallel --target CustomTarget)
  231. endif()
  232. endfunction()
  233. run_BuildDir()
  234. function(run_EnvironmentGenerator)
  235. set(source_dir ${RunCMake_SOURCE_DIR}/EnvGenerator)
  236. set(ENV{CMAKE_GENERATOR_INSTANCE} "instance")
  237. set(ENV{CMAKE_GENERATOR_PLATFORM} "platform")
  238. set(ENV{CMAKE_GENERATOR_TOOLSET} "toolset")
  239. run_cmake_command(Envgen-warnings ${CMAKE_COMMAND} -G)
  240. unset(ENV{CMAKE_GENERATOR_INSTANCE})
  241. unset(ENV{CMAKE_GENERATOR_PLATFORM})
  242. unset(ENV{CMAKE_GENERATOR_TOOLSET})
  243. # Test CMAKE_GENERATOR without actual configuring
  244. run_cmake_command(Envgen-unset ${CMAKE_COMMAND} -G)
  245. set(ENV{CMAKE_GENERATOR} "Ninja")
  246. run_cmake_command(Envgen-ninja ${CMAKE_COMMAND} -G)
  247. set(ENV{CMAKE_GENERATOR} "NoSuchGenerator")
  248. run_cmake_command(Envgen-bad ${CMAKE_COMMAND} -G)
  249. unset(ENV{CMAKE_GENERATOR})
  250. if(RunCMake_GENERATOR MATCHES "Visual Studio.*")
  251. set(ENV{CMAKE_GENERATOR} "${RunCMake_GENERATOR}")
  252. run_cmake_command(Envgen ${CMAKE_COMMAND} ${source_dir})
  253. # Toolset is available since VS 2010.
  254. if(RunCMake_GENERATOR MATCHES "Visual Studio [1-9][0-9]")
  255. set(ENV{CMAKE_GENERATOR_TOOLSET} "invalid")
  256. # Envvar shouldn't affect existing build tree
  257. run_cmake_command(Envgen-toolset-existing ${CMAKE_COMMAND} -E chdir ..
  258. ${CMAKE_COMMAND} --build Envgen-build)
  259. run_cmake_command(Envgen-toolset-invalid ${CMAKE_COMMAND} ${source_dir})
  260. # Command line -G implies -T""
  261. run_cmake_command(Envgen-G-implicit-toolset ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir})
  262. run_cmake_command(Envgen-T-toolset ${CMAKE_COMMAND} -T "fromcli" ${source_dir})
  263. unset(ENV{CMAKE_GENERATOR_TOOLSET})
  264. endif()
  265. # Platform can be set only if not in generator name.
  266. if(RunCMake_GENERATOR MATCHES "^Visual Studio [0-9]+ [0-9]+$")
  267. set(ENV{CMAKE_GENERATOR_PLATFORM} "invalid")
  268. # Envvar shouldn't affect existing build tree
  269. run_cmake_command(Envgen-platform-existing ${CMAKE_COMMAND} -E chdir ..
  270. ${CMAKE_COMMAND} --build Envgen-build)
  271. if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
  272. set(RunCMake-stderr-file "Envgen-platform-invalid-stderr-vs9.txt")
  273. endif()
  274. run_cmake_command(Envgen-platform-invalid ${CMAKE_COMMAND} ${source_dir})
  275. unset(RunCMake-stderr-file)
  276. # Command line -G implies -A""
  277. run_cmake_command(Envgen-G-implicit-platform ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir})
  278. if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
  279. set(RunCMake-stderr-file "Envgen-A-platform-stderr-vs9.txt")
  280. endif()
  281. run_cmake_command(Envgen-A-platform ${CMAKE_COMMAND} -A "fromcli" ${source_dir})
  282. unset(RunCMake-stderr-file)
  283. unset(ENV{CMAKE_GENERATOR_PLATFORM})
  284. endif()
  285. # Instance is available since VS 2017.
  286. if(RunCMake_GENERATOR MATCHES "Visual Studio (15|16).*")
  287. set(ENV{CMAKE_GENERATOR_INSTANCE} "invalid")
  288. # Envvar shouldn't affect existing build tree
  289. run_cmake_command(Envgen-instance-existing ${CMAKE_COMMAND} -E chdir ..
  290. ${CMAKE_COMMAND} --build Envgen-build)
  291. run_cmake_command(Envgen-instance-invalid ${CMAKE_COMMAND} ${source_dir})
  292. unset(ENV{CMAKE_GENERATOR_INSTANCE})
  293. endif()
  294. unset(ENV{CMAKE_GENERATOR})
  295. endif()
  296. endfunction()
  297. run_EnvironmentGenerator()
  298. function(run_EnvironmentExportCompileCommands)
  299. set(RunCMake_TEST_SOURCE_DIR ${RunCMake_SOURCE_DIR}/env-export-compile-commands)
  300. run_cmake(env-export-compile-commands-unset)
  301. set(ENV{CMAKE_EXPORT_COMPILE_COMMANDS} ON)
  302. run_cmake(env-export-compile-commands-set)
  303. set(RunCMake_TEST_OPTIONS -DCMAKE_EXPORT_COMPILE_COMMANDS=OFF)
  304. run_cmake(env-export-compile-commands-override)
  305. unset(ENV{CMAKE_EXPORT_COMPILE_COMMANDS})
  306. endfunction(run_EnvironmentExportCompileCommands)
  307. if(RunCMake_GENERATOR MATCHES "Unix Makefiles" OR RunCMake_GENERATOR MATCHES "Ninja")
  308. run_EnvironmentExportCompileCommands()
  309. endif()
  310. function(run_EnvironmentToolchain)
  311. set(ENV{CMAKE_TOOLCHAIN_FILE} "${RunCMake_SOURCE_DIR}/EnvToolchain-toolchain.cmake")
  312. run_cmake(EnvToolchainAbsolute)
  313. run_cmake_with_options(EnvToolchainIgnore -DCMAKE_TOOLCHAIN_FILE=)
  314. unset(ENV{CMAKE_TOOLCHAIN_FILE})
  315. set(ENV{CMAKE_TOOLCHAIN_FILE} "EnvToolchain-toolchain.cmake")
  316. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/EnvToolchainRelative-build)
  317. set(RunCMake_TEST_NO_CLEAN 1)
  318. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  319. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  320. configure_file("${RunCMake_SOURCE_DIR}/EnvToolchain-toolchain.cmake" "${RunCMake_TEST_BINARY_DIR}/EnvToolchain-toolchain.cmake" COPYONLY)
  321. run_cmake(EnvToolchainRelative)
  322. unset(ENV{CMAKE_TOOLCHAIN_FILE})
  323. unset(RunCMake_TEST_NO_CLEAN)
  324. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/EnvToolchainNone-build)
  325. run_cmake(EnvToolchainNone)
  326. set(RunCMake_TEST_NO_CLEAN 1)
  327. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles")
  328. set(ENV{CMAKE_TOOLCHAIN_FILE} "${RunCMake_SOURCE_DIR}/EnvToolchain-toolchain.cmake")
  329. run_cmake_command(EnvToolchainNoneExisting ${CMAKE_COMMAND} .)
  330. unset(ENV{CMAKE_TOOLCHAIN_FILE})
  331. unset(RunCMake_TEST_NO_CLEAN)
  332. endfunction()
  333. run_EnvironmentToolchain()
  334. if(RunCMake_GENERATOR STREQUAL "Ninja")
  335. # Use a single build tree for a few tests without cleaning.
  336. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Build-build)
  337. set(RunCMake_TEST_NO_CLEAN 1)
  338. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  339. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  340. set(RunCMake_TEST_OPTIONS -DCMAKE_VERBOSE_MAKEFILE=1)
  341. run_cmake(Build)
  342. unset(RunCMake_TEST_OPTIONS)
  343. run_cmake_command(Build-ninja-v ${CMAKE_COMMAND} --build .)
  344. unset(RunCMake_TEST_BINARY_DIR)
  345. unset(RunCMake_TEST_NO_CLEAN)
  346. endif()
  347. run_cmake_command(E_create_symlink-no-arg
  348. ${CMAKE_COMMAND} -E create_symlink
  349. )
  350. run_cmake_command(E_create_symlink-missing-dir
  351. ${CMAKE_COMMAND} -E create_symlink T missing-dir/L
  352. )
  353. # Use a single build tree for a few tests without cleaning.
  354. # These tests are special on Windows since it will only fail if the user
  355. # running the test does not have the priveldge to create symlinks. If this
  356. # happens we clear the msg in the -check.cmake and say that the test passes
  357. set(RunCMake_DEFAULT_stderr "(A required privilege is not held by the client)?")
  358. set(RunCMake_TEST_BINARY_DIR
  359. ${RunCMake_BINARY_DIR}/E_create_symlink-broken-build)
  360. set(RunCMake_TEST_NO_CLEAN 1)
  361. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  362. run_cmake_command(E_create_symlink-broken-create
  363. ${CMAKE_COMMAND} -E create_symlink T L
  364. )
  365. run_cmake_command(E_create_symlink-broken-replace
  366. ${CMAKE_COMMAND} -E create_symlink . L
  367. )
  368. unset(RunCMake_TEST_BINARY_DIR)
  369. unset(RunCMake_TEST_NO_CLEAN)
  370. unset(RunCMake_DEFAULT_stderr)
  371. run_cmake_command(E_create_symlink-no-replace-dir
  372. ${CMAKE_COMMAND} -E create_symlink T .
  373. )
  374. #create hard link tests
  375. run_cmake_command(E_create_hardlink-no-arg
  376. ${CMAKE_COMMAND} -E create_hardlink
  377. )
  378. set(dir ${RunCMake_BINARY_DIR}/hardlink_tests)
  379. file(REMOVE_RECURSE "${dir}")
  380. file(MAKE_DIRECTORY ${dir})
  381. run_cmake_command(E_create_hardlink-non-existent-source
  382. ${CMAKE_COMMAND} -E create_hardlink ${dir}/I_dont_exist ${dir}/link
  383. )
  384. file(TOUCH ${dir}/1)
  385. run_cmake_command(E_create_hardlink-ok
  386. ${CMAKE_COMMAND} -E create_hardlink ${dir}/1 ${dir}/1-link
  387. )
  388. run_cmake_command(E_create_hardlink-no-directory
  389. ${CMAKE_COMMAND} -E create_hardlink ${dir}/1 ${dir}/a/1-link
  390. )
  391. #On Windows, if the user does not have sufficient privileges
  392. #don't fail this test
  393. set(RunCMake_DEFAULT_stderr "(A required privilege is not held by the client)?")
  394. run_cmake_command(E_create_hardlink-unresolved-symlink-prereq
  395. ${CMAKE_COMMAND} -E create_symlink ${dir}/1 ${dir}/1-symlink
  396. )
  397. file(REMOVE ${dir}/1)
  398. run_cmake_command(E_create_hardlink-unresolved-symlink
  399. ${CMAKE_COMMAND} -E create_hardlink ${dir}/1-symlink ${dir}/1s-link
  400. )
  401. unset(RunCMake_DEFAULT_stderr)
  402. set(in ${RunCMake_SOURCE_DIR}/copy_input)
  403. set(out ${RunCMake_BINARY_DIR}/copy_output)
  404. file(REMOVE_RECURSE "${out}")
  405. file(MAKE_DIRECTORY ${out})
  406. run_cmake_command(E_copy-one-source-file
  407. ${CMAKE_COMMAND} -E copy ${out}/f1.txt)
  408. run_cmake_command(E_copy-one-source-directory-target-is-directory
  409. ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${out})
  410. run_cmake_command(E_copy-three-source-files-target-is-directory
  411. ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out})
  412. run_cmake_command(E_copy-three-source-files-target-is-file
  413. ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}/f1.txt)
  414. run_cmake_command(E_copy-two-good-and-one-bad-source-files-target-is-directory
  415. ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/not_existing_file.bad ${in}/f3.txt ${out})
  416. run_cmake_command(E_copy_if_different-one-source-directory-target-is-directory
  417. ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${out})
  418. run_cmake_command(E_copy_if_different-three-source-files-target-is-directory
  419. ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out})
  420. run_cmake_command(E_copy_if_different-three-source-files-target-is-file
  421. ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}/f1.txt)
  422. unset(in)
  423. unset(out)
  424. set(in ${RunCMake_SOURCE_DIR}/copy_input)
  425. set(out ${RunCMake_BINARY_DIR}/copy_directory_output)
  426. set(outfile ${out}/file_for_test.txt)
  427. file(REMOVE_RECURSE "${out}")
  428. file(MAKE_DIRECTORY ${out})
  429. file(WRITE ${outfile} "")
  430. run_cmake_command(E_copy_directory-three-source-files-target-is-directory
  431. ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${out})
  432. run_cmake_command(E_copy_directory-three-source-files-target-is-file
  433. ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${outfile})
  434. run_cmake_command(E_copy_directory-three-source-files-target-is-not-exist
  435. ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${out}/not_existing_directory)
  436. unset(in)
  437. unset(out)
  438. unset(outfile)
  439. set(out ${RunCMake_BINARY_DIR}/make_directory_output)
  440. set(outfile ${out}/file_for_test.txt)
  441. file(REMOVE_RECURSE "${out}")
  442. file(MAKE_DIRECTORY ${out})
  443. file(WRITE ${outfile} "")
  444. run_cmake_command(E_make_directory-three-directories
  445. ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${out}/d2)
  446. run_cmake_command(E_remove_directory-three-directories
  447. ${CMAKE_COMMAND} -E remove_directory ${out}/d1 ${out}/d2 ${out}/d2)
  448. run_cmake_command(E_make_directory-directory-with-parent
  449. ${CMAKE_COMMAND} -E make_directory ${out}/parent/child)
  450. run_cmake_command(E_remove_directory-directory-with-parent
  451. ${CMAKE_COMMAND} -E remove_directory ${out}/parent)
  452. run_cmake_command(E_make_directory-two-directories-and-file
  453. ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${outfile})
  454. run_cmake_command(E_remove_directory-two-directories-and-file
  455. ${CMAKE_COMMAND} -E remove_directory ${out}/d1 ${out}/d2 ${outfile})
  456. if(UNIX)
  457. file(MAKE_DIRECTORY ${out}/dir)
  458. file(CREATE_LINK ${out}/dir ${out}/link_dir SYMBOLIC)
  459. file(CREATE_LINK ${outfile} ${out}/link_file_for_test.txt SYMBOLIC)
  460. run_cmake_command(E_remove_directory-symlink-dir
  461. ${CMAKE_COMMAND} -E remove_directory ${out}/link_dir)
  462. run_cmake_command(E_remove_directory-symlink-file
  463. ${CMAKE_COMMAND} -E remove_directory ${out}/link_file_for_test.txt)
  464. endif()
  465. unset(out)
  466. unset(outfile)
  467. set(out ${RunCMake_BINARY_DIR}/rm_tests)
  468. file(REMOVE_RECURSE "${out}")
  469. file(MAKE_DIRECTORY ${out})
  470. file(TOUCH ${out}/existing.txt)
  471. run_cmake_command(E_rm_file_force_existing
  472. ${CMAKE_COMMAND} -E rm -f ${out}/existing.txt)
  473. file(TOUCH ${out}/existing.txt)
  474. run_cmake_command(E_rm_file_non_force_existing
  475. ${CMAKE_COMMAND} -E rm ${out}/existing.txt)
  476. run_cmake_command(E_rm_file_force_non_existing
  477. ${CMAKE_COMMAND} -E rm -f ${out}/not_existing.txt)
  478. run_cmake_command(E_rm_file_non_force_non_existing
  479. ${CMAKE_COMMAND} -E rm ${out}/not_existing.txt)
  480. file(TOUCH ${out}/existing.txt)
  481. run_cmake_command(E_rm_file_recursive_existing
  482. ${CMAKE_COMMAND} -E rm -r ${out}/existing.txt)
  483. run_cmake_command(E_rm_file_recursive_non_existing
  484. ${CMAKE_COMMAND} -E rm -r ${out}/not_existing.txt)
  485. file(MAKE_DIRECTORY ${out}/d1 ${out}/d2)
  486. run_cmake_command(E_rm_non_recursive_directory-two-directories
  487. ${CMAKE_COMMAND} -E rm ${out}/d1 ${out}/d2)
  488. run_cmake_command(E_rm_recursive_directory-two-directories
  489. ${CMAKE_COMMAND} -E rm -R ${out}/d1 ${out}/d2)
  490. run_cmake_command(E_rm_no_file_specified
  491. ${CMAKE_COMMAND} -E rm -rf)
  492. run_cmake_command(E_rm_empty_file_specified
  493. ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_rm_empty_file_specified.cmake)
  494. run_cmake_command(E_rm_bad_argument
  495. ${CMAKE_COMMAND} -E rm -rd ${out}/d1 ${out}/d2)
  496. file(MAKE_DIRECTORY ${out}/d1 ${out}/d2)
  497. file(WRITE ${out}/test.txt "")
  498. run_cmake_command(E_rm_force_recursive_directory_with_files
  499. ${CMAKE_COMMAND} -E rm -rf ${out}/)
  500. run_cmake_command(E_rm_force_recursive_non_existing_file
  501. ${CMAKE_COMMAND} -E rm -Rf ${out}/test.txt)
  502. if(NOT WIN32 AND NOT CYGWIN)
  503. file(MAKE_DIRECTORY ${out})
  504. file(TOUCH ${out}/existing.txt)
  505. file(MAKE_DIRECTORY ${out}/dir)
  506. file(TOUCH ${out}/dir/existing.txt) # add a file in the folder
  507. file(CREATE_LINK ${out}/dir ${out}/link_dir SYMBOLIC)
  508. file(CREATE_LINK ${out}/existing.txt ${out}/existing_file_link.txt SYMBOLIC)
  509. file(CREATE_LINK ${out}/non_existing.txt ${out}/non_existing_file_link.txt SYMBOLIC)
  510. run_cmake_command(E_rm_file_link_existing
  511. ${CMAKE_COMMAND} -E rm ${out}/existing_file_link.txt)
  512. run_cmake_command(E_rm_directory_link_existing
  513. ${CMAKE_COMMAND} -E rm ${out}/link_dir)
  514. run_cmake_command(E_rm_file_link_non_existing
  515. ${CMAKE_COMMAND} -E rm ${out}/non_existing_file_link.txt)
  516. file(CREATE_LINK ${out}/dir ${out}/link_dir SYMBOLIC)
  517. file(CREATE_LINK ${out}/existing.txt ${out}/existing_file_link.txt SYMBOLIC)
  518. file(CREATE_LINK ${out}/non_existing.txt ${out}/non_existing_file_link.txt SYMBOLIC)
  519. run_cmake_command(E_rm_recursive_file_link_existing
  520. ${CMAKE_COMMAND} -E rm -R ${out}/existing_file_link.txt)
  521. run_cmake_command(E_rm_recursive_directory_link_existing
  522. ${CMAKE_COMMAND} -E rm -r ${out}/link_dir)
  523. run_cmake_command(E_rm_recursive_file_link_non_existing
  524. ${CMAKE_COMMAND} -E rm -r ${out}/non_existing_file_link.txt)
  525. endif()
  526. unset(out)
  527. # cat tests
  528. set(out ${RunCMake_BINARY_DIR}/cat_tests)
  529. file(REMOVE_RECURSE "${out}")
  530. file(MAKE_DIRECTORY ${out})
  531. run_cmake_command(E_cat_non_existing_file
  532. ${CMAKE_COMMAND} -E cat ${out}/non-existing-file.txt)
  533. if(UNIX AND NOT MSYS)
  534. # test non readable file only if not root
  535. execute_process(
  536. COMMAND id -u $ENV{USER}
  537. OUTPUT_VARIABLE uid
  538. OUTPUT_STRIP_TRAILING_WHITESPACE)
  539. if(NOT "${uid}" STREQUAL "0")
  540. # Create non readable file
  541. set(inside_folder "${out}/in")
  542. file(MAKE_DIRECTORY ${inside_folder})
  543. file(WRITE "${inside_folder}/non_readable_file.txt" "first file to append\n")
  544. file(COPY "${inside_folder}/non_readable_file.txt" DESTINATION "${out}" FILE_PERMISSIONS OWNER_WRITE)
  545. run_cmake_command(E_cat_non_readable_file
  546. ${CMAKE_COMMAND} -E cat "${out}/non_readable_file.txt")
  547. endif()
  548. endif()
  549. run_cmake_command(E_cat_option_not_handled
  550. ${CMAKE_COMMAND} -E cat -f)
  551. run_cmake_command(E_cat_directory
  552. ${CMAKE_COMMAND} -E cat ${out})
  553. file(WRITE "${out}/first_file.txt" "first file to append\n")
  554. file(WRITE "${out}/second_file.txt" "second file to append\n")
  555. file(WRITE "${out}/unicode_file.txt" "àéùç - 한국어") # Korean in Korean
  556. run_cmake_command(E_cat_good_cat
  557. ${CMAKE_COMMAND} -E cat "${out}/first_file.txt" "${out}/second_file.txt" "${out}/unicode_file.txt")
  558. unset(out)
  559. run_cmake_command(E_cat_good_binary_cat
  560. ${CMAKE_COMMAND} -E cat "${RunCMake_SOURCE_DIR}/E_cat_binary_files/binary.obj" "${RunCMake_SOURCE_DIR}/E_cat_binary_files/binary.obj")
  561. run_cmake_command(E_env-no-command0 ${CMAKE_COMMAND} -E env)
  562. run_cmake_command(E_env-no-command1 ${CMAKE_COMMAND} -E env TEST_ENV=1)
  563. run_cmake_command(E_env-bad-arg1 ${CMAKE_COMMAND} -E env -bad-arg1)
  564. run_cmake_command(E_env-set ${CMAKE_COMMAND} -E env TEST_ENV=1 ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_env-set.cmake)
  565. 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)
  566. run_cmake_command(E_md5sum-dir ${CMAKE_COMMAND} -E md5sum .)
  567. run_cmake_command(E_sha1sum-dir ${CMAKE_COMMAND} -E sha1sum .)
  568. run_cmake_command(E_sha224sum-dir ${CMAKE_COMMAND} -E sha224sum .)
  569. run_cmake_command(E_sha256sum-dir ${CMAKE_COMMAND} -E sha256sum .)
  570. run_cmake_command(E_sha384sum-dir ${CMAKE_COMMAND} -E sha384sum .)
  571. run_cmake_command(E_sha512sum-dir ${CMAKE_COMMAND} -E sha512sum .)
  572. run_cmake_command(E_md5sum-no-file ${CMAKE_COMMAND} -E md5sum nonexisting)
  573. run_cmake_command(E_sha1sum-no-file ${CMAKE_COMMAND} -E sha1sum nonexisting)
  574. run_cmake_command(E_sha224sum-no-file ${CMAKE_COMMAND} -E sha224sum nonexisting)
  575. run_cmake_command(E_sha256sum-no-file ${CMAKE_COMMAND} -E sha256sum nonexisting)
  576. run_cmake_command(E_sha384sum-no-file ${CMAKE_COMMAND} -E sha384sum nonexisting)
  577. run_cmake_command(E_sha512sum-no-file ${CMAKE_COMMAND} -E sha512sum nonexisting)
  578. file(WRITE "${RunCMake_BINARY_DIR}/dummy" "dummy")
  579. run_cmake_command(E_md5sum ${CMAKE_COMMAND} -E md5sum ../dummy)
  580. run_cmake_command(E_md5sum-mixed ${CMAKE_COMMAND} -E md5sum . ../dummy nonexisting)
  581. run_cmake_command(E_sha1sum ${CMAKE_COMMAND} -E sha1sum ../dummy)
  582. run_cmake_command(E_sha224sum ${CMAKE_COMMAND} -E sha224sum ../dummy)
  583. run_cmake_command(E_sha256sum ${CMAKE_COMMAND} -E sha256sum ../dummy)
  584. run_cmake_command(E_sha384sum ${CMAKE_COMMAND} -E sha384sum ../dummy)
  585. run_cmake_command(E_sha512sum ${CMAKE_COMMAND} -E sha512sum ../dummy)
  586. file(REMOVE "${RunCMake_BINARY_DIR}/dummy")
  587. set(RunCMake_DEFAULT_stderr ".")
  588. run_cmake_command(E_sleep-no-args ${CMAKE_COMMAND} -E sleep)
  589. unset(RunCMake_DEFAULT_stderr)
  590. run_cmake_command(E_sleep-bad-arg1 ${CMAKE_COMMAND} -E sleep x)
  591. run_cmake_command(E_sleep-bad-arg2 ${CMAKE_COMMAND} -E sleep 1 -1)
  592. run_cmake_command(E_sleep-one-tenth ${CMAKE_COMMAND} -E sleep 0.1)
  593. run_cmake_command(P_directory ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR})
  594. 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)
  595. # Documented to return the same result as above even if -S and -B are set to something else.
  596. # Tests the values of CMAKE_BINARY_DIR CMAKE_CURRENT_BINARY_DIR CMAKE_SOURCE_DIR CMAKE_CURRENT_SOURCE_DIR.
  597. 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)
  598. # Place an initial cache where C_basic will find it when passed the relative path "..".
  599. file(COPY ${RunCMake_SOURCE_DIR}/C_basic_initial-cache.txt DESTINATION ${RunCMake_BINARY_DIR})
  600. run_cmake_with_options(C_basic -C ../C_basic_initial-cache.txt)
  601. run_cmake_with_options(C_basic_fullpath -C ${RunCMake_BINARY_DIR}/C_basic_initial-cache.txt)
  602. set(RunCMake_TEST_OPTIONS
  603. "-DFOO=-DBAR:BOOL=BAZ")
  604. run_cmake(D_nested_cache)
  605. set(RunCMake_TEST_OPTIONS
  606. "-DFOO:STRING=-DBAR:BOOL=BAZ")
  607. run_cmake(D_typed_nested_cache)
  608. set(RunCMake_TEST_OPTIONS -Wno-dev)
  609. run_cmake(Wno-dev)
  610. unset(RunCMake_TEST_OPTIONS)
  611. set(RunCMake_TEST_OPTIONS -Wdev)
  612. run_cmake(Wdev)
  613. unset(RunCMake_TEST_OPTIONS)
  614. set(RunCMake_TEST_OPTIONS -Werror=dev)
  615. run_cmake(Werror_dev)
  616. unset(RunCMake_TEST_OPTIONS)
  617. set(RunCMake_TEST_OPTIONS -Wno-error=dev)
  618. run_cmake(Wno-error_deprecated)
  619. unset(RunCMake_TEST_OPTIONS)
  620. # -Wdev should not override deprecated options if specified
  621. set(RunCMake_TEST_OPTIONS -Wdev -Wno-deprecated)
  622. run_cmake(Wno-deprecated)
  623. unset(RunCMake_TEST_OPTIONS)
  624. set(RunCMake_TEST_OPTIONS -Wno-deprecated -Wdev)
  625. run_cmake(Wno-deprecated)
  626. unset(RunCMake_TEST_OPTIONS)
  627. # -Wdev should enable deprecated warnings as well
  628. set(RunCMake_TEST_OPTIONS -Wdev)
  629. run_cmake(Wdeprecated)
  630. unset(RunCMake_TEST_OPTIONS)
  631. # -Werror=dev should enable deprecated errors as well
  632. set(RunCMake_TEST_OPTIONS -Werror=dev)
  633. run_cmake(Werror_deprecated)
  634. unset(RunCMake_TEST_OPTIONS)
  635. set(RunCMake_TEST_OPTIONS -Wdeprecated)
  636. run_cmake(Wdeprecated)
  637. unset(RunCMake_TEST_OPTIONS)
  638. set(RunCMake_TEST_OPTIONS -Wno-deprecated)
  639. run_cmake(Wno-deprecated)
  640. unset(RunCMake_TEST_OPTIONS)
  641. set(RunCMake_TEST_OPTIONS -Werror=deprecated)
  642. run_cmake(Werror_deprecated)
  643. unset(RunCMake_TEST_OPTIONS)
  644. set(RunCMake_TEST_OPTIONS -Wno-error=deprecated)
  645. run_cmake(Wno-error_deprecated)
  646. unset(RunCMake_TEST_OPTIONS)
  647. set(RunCMake_TEST_OPTIONS -Werror=deprecated -Wno-error=deprecated)
  648. run_cmake(Wno-error_deprecated)
  649. unset(RunCMake_TEST_OPTIONS)
  650. # Dev warnings should be on by default
  651. run_cmake(Wdev)
  652. # Deprecated warnings should be on by default
  653. run_cmake(Wdeprecated)
  654. # Conflicting -W options should honor the last value
  655. set(RunCMake_TEST_OPTIONS -Wno-dev -Wdev)
  656. run_cmake(Wdev)
  657. unset(RunCMake_TEST_OPTIONS)
  658. set(RunCMake_TEST_OPTIONS -Wdev -Wno-dev)
  659. run_cmake(Wno-dev)
  660. unset(RunCMake_TEST_OPTIONS)
  661. run_cmake_command(W_bad-arg1 ${CMAKE_COMMAND} -B DummyBuildDir -W)
  662. run_cmake_command(W_bad-arg2 ${CMAKE_COMMAND} -B DummyBuildDir -Wno-)
  663. run_cmake_command(W_bad-arg3 ${CMAKE_COMMAND} -B DummyBuildDir -Werror=)
  664. set(RunCMake_TEST_OPTIONS --debug-output)
  665. run_cmake(debug-output)
  666. unset(RunCMake_TEST_OPTIONS)
  667. set(RunCMake_TEST_OPTIONS --trace)
  668. run_cmake(trace)
  669. unset(RunCMake_TEST_OPTIONS)
  670. set(RunCMake_TEST_OPTIONS --trace-expand)
  671. run_cmake(trace-expand)
  672. unset(RunCMake_TEST_OPTIONS)
  673. set(RunCMake_TEST_OPTIONS --trace-expand --warn-uninitialized)
  674. run_cmake(trace-expand-warn-uninitialized)
  675. unset(RunCMake_TEST_OPTIONS)
  676. set(RunCMake_TEST_OPTIONS --trace-redirect=${RunCMake_BINARY_DIR}/redirected.trace)
  677. run_cmake(trace-redirect)
  678. unset(RunCMake_TEST_OPTIONS)
  679. set(RunCMake_TEST_OPTIONS --trace-redirect=/no/such/file.txt)
  680. run_cmake(trace-redirect-nofile)
  681. unset(RunCMake_TEST_OPTIONS)
  682. set(RunCMake_TEST_OPTIONS --trace --trace-format=json-v1 --trace-redirect=${RunCMake_BINARY_DIR}/json-v1.trace)
  683. run_cmake(trace-json-v1)
  684. unset(RunCMake_TEST_OPTIONS)
  685. set(RunCMake_TEST_OPTIONS --trace-expand --trace-format=json-v1 --trace-redirect=${RunCMake_BINARY_DIR}/json-v1-expand.trace)
  686. run_cmake(trace-json-v1-expand)
  687. unset(RunCMake_TEST_OPTIONS)
  688. set(RunCMake_TEST_OPTIONS -Wno-deprecated --warn-uninitialized)
  689. run_cmake(warn-uninitialized)
  690. unset(RunCMake_TEST_OPTIONS)
  691. set(RunCMake_TEST_OPTIONS --trace-source=trace-only-this-file.cmake)
  692. run_cmake(trace-source)
  693. unset(RunCMake_TEST_OPTIONS)
  694. set(RunCMake_TEST_OPTIONS --debug-trycompile)
  695. run_cmake(debug-trycompile)
  696. unset(RunCMake_TEST_OPTIONS)
  697. function(run_cmake_depends)
  698. set(RunCMake_TEST_SOURCE_DIR "${RunCMake_SOURCE_DIR}/cmake_depends")
  699. set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/cmake_depends-build")
  700. set(RunCMake_TEST_NO_CLEAN 1)
  701. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  702. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  703. file(WRITE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/DependInfo.cmake" "
  704. set(CMAKE_DEPENDS_LANGUAGES \"C\")
  705. set(CMAKE_DEPENDS_CHECK_C
  706. \"${RunCMake_TEST_SOURCE_DIR}/test.c\"
  707. \"${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/test.c.o\"
  708. )
  709. ")
  710. file(WRITE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/CMakeDirectoryInformation.cmake" "
  711. set(CMAKE_RELATIVE_PATH_TOP_SOURCE \"${RunCMake_TEST_SOURCE_DIR}\")
  712. set(CMAKE_RELATIVE_PATH_TOP_BINARY \"${RunCMake_TEST_BINARY_DIR}\")
  713. ")
  714. run_cmake_command(cmake_depends ${CMAKE_COMMAND} -E cmake_depends
  715. "Unix Makefiles"
  716. ${RunCMake_TEST_SOURCE_DIR} ${RunCMake_TEST_SOURCE_DIR}
  717. ${RunCMake_TEST_BINARY_DIR} ${RunCMake_TEST_BINARY_DIR}
  718. ${RunCMake_TEST_BINARY_DIR}/CMakeFiles/DepTarget.dir/DependInfo.cmake
  719. )
  720. endfunction()
  721. run_cmake_depends()
  722. function(reject_fifo)
  723. find_program(BASH_EXECUTABLE bash)
  724. if(BASH_EXECUTABLE)
  725. set(BASH_COMMAND_ARGUMENT "'${CMAKE_COMMAND}' -P <(echo 'return()')")
  726. run_cmake_command(reject_fifo ${BASH_EXECUTABLE} -c ${BASH_COMMAND_ARGUMENT})
  727. endif()
  728. endfunction()
  729. if(CMAKE_HOST_UNIX AND NOT CMAKE_SYSTEM_NAME STREQUAL "CYGWIN" AND NOT CMAKE_SYSTEM_NAME STREQUAL "MSYS")
  730. reject_fifo()
  731. run_cmake_command(closed_stdin sh -c "\"${CMAKE_COMMAND}\" --version <&-")
  732. run_cmake_command(closed_stdout sh -c "\"${CMAKE_COMMAND}\" --version >&-")
  733. run_cmake_command(closed_stderr sh -c "\"${CMAKE_COMMAND}\" --version 2>&-")
  734. run_cmake_command(closed_stdall sh -c "\"${CMAKE_COMMAND}\" --version <&- >&- 2>&-")
  735. endif()
  736. function(run_llvm_rc)
  737. set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/llvm_rc-build")
  738. set(RunCMake_TEST_NO_CLEAN 1)
  739. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  740. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  741. run_cmake_command(llvm_rc_no_args ${CMAKE_COMMAND} -E cmake_llvm_rc)
  742. 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")
  743. 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")
  744. 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")
  745. 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 )
  746. if(EXISTS ${RunCMake_TEST_BINARY_DIR}/test.tmp)
  747. message(SEND_ERROR "${test} - FAILED:\n"
  748. "test.tmp was not deleted")
  749. endif()
  750. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir")
  751. 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 )
  752. if(EXISTS ${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir/test.tmp)
  753. message(SEND_ERROR "${test} - FAILED:\n"
  754. "test.tmp was not deleted")
  755. endif()
  756. file(READ ${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir/llvmrc.result LLVMRC_RESULT)
  757. if(NOT "${LLVMRC_RESULT}" STREQUAL "This is a test\n")
  758. message(SEND_ERROR "${test} - FAILED:\n"
  759. "llvmrc.result was not created")
  760. endif()
  761. unset(LLVMRC_RESULT)
  762. endfunction()
  763. run_llvm_rc()
  764. set(RunCMake_TEST_OPTIONS --profiling-output=/no/such/file.txt --profiling-format=google-trace)
  765. run_cmake(profiling-all-params)
  766. unset(RunCMake_TEST_OPTIONS)
  767. set(RunCMake_TEST_OPTIONS --profiling-output=/no/such/file.txt --profiling-format=invalid-format)
  768. run_cmake(profiling-invalid-format)
  769. unset(RunCMake_TEST_OPTIONS)
  770. set(RunCMake_TEST_OPTIONS --profiling-output=/no/such/file.txt)
  771. run_cmake(profiling-missing-format)
  772. unset(RunCMake_TEST_OPTIONS)
  773. set(RunCMake_TEST_OPTIONS --profiling-format=google-trace)
  774. run_cmake(profiling-missing-output)
  775. unset(RunCMake_TEST_OPTIONS)
  776. set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/profiling-test")
  777. set(ProfilingTestOutput ${RunCMake_TEST_BINARY_DIR}/output.json)
  778. set(RunCMake_TEST_OPTIONS --profiling-format=google-trace --profiling-output=${ProfilingTestOutput})
  779. run_cmake(ProfilingTest)
  780. unset(RunCMake_TEST_OPTIONS)