RunCMakeTest.cmake 52 KB

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