RunCMakeTest.cmake 44 KB

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