RunCMakeTest.cmake 52 KB

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