RunCMakeTest.cmake 54 KB

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