RunCMakeTest.cmake 38 KB

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