ScriptMode.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. cmake_minimum_required(VERSION 3.29)
  2. cmake_policy(SET CMP0168 ${CMP0168})
  3. include(FetchContent)
  4. file(WRITE tmpFile.txt "Generated contents, not important")
  5. FetchContent_Populate(
  6. t1
  7. DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E copy
  8. ${CMAKE_CURRENT_BINARY_DIR}/tmpFile.txt
  9. <SOURCE_DIR>/done1.txt
  10. )
  11. if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/t1-src/done1.txt)
  12. message(FATAL_ERROR "Default SOURCE_DIR doesn't contain done1.txt")
  13. endif()
  14. if(CMP0168 STREQUAL "NEW" AND EXISTS ${CMAKE_CURRENT_BINARY_DIR}/t1-subbuild)
  15. message(FATAL_ERROR "t1 sub-build used when expected direct population")
  16. elseif(CMP0168 STREQUAL "OLD" AND NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/t1-subbuild)
  17. message(FATAL_ERROR "t1 used direct population when a sub-build was expected")
  18. endif()
  19. FetchContent_Populate(
  20. t2
  21. SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/mysrc
  22. DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E copy
  23. ${CMAKE_CURRENT_BINARY_DIR}/tmpFile.txt
  24. <SOURCE_DIR>/done2.txt
  25. )
  26. if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/mysrc/done2.txt)
  27. message(FATAL_ERROR "Specified SOURCE_DIR doesn't contain done2.txt")
  28. endif()
  29. if(CMP0168 STREQUAL "NEW" AND EXISTS ${CMAKE_CURRENT_BINARY_DIR}/t2-subbuild)
  30. message(FATAL_ERROR "t2 sub-build used when expected direct population")
  31. elseif(CMP0168 STREQUAL "OLD" AND NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/t2-subbuild)
  32. message(FATAL_ERROR "t2 used direct population when a sub-build was expected")
  33. endif()
  34. FetchContent_Populate(
  35. t3
  36. SOURCE_DIR myrelsrc
  37. DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E copy
  38. ${CMAKE_CURRENT_BINARY_DIR}/tmpFile.txt
  39. <SOURCE_DIR>/done3.txt
  40. )
  41. if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/myrelsrc/done3.txt)
  42. message(FATAL_ERROR "Relative SOURCE_DIR doesn't contain done3.txt")
  43. endif()
  44. if(CMP0168 STREQUAL "NEW" AND EXISTS ${CMAKE_CURRENT_BINARY_DIR}/t3-subbuild)
  45. message(FATAL_ERROR "t3 sub-build used when expected direct population")
  46. elseif(CMP0168 STREQUAL "OLD" AND NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/t3-subbuild)
  47. message(FATAL_ERROR "t3 used direct population when a sub-build was expected")
  48. endif()