RunCMakeTest.cmake 55 KB

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