You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

969 lines
45 KiB

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