CMakeLists.txt 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. cmake_minimum_required (VERSION 2.6)
  2. project(TestWorkingDir)
  3. add_custom_command(
  4. OUTPUT "${TestWorkingDir_BINARY_DIR}/working.c"
  5. COMMAND "${CMAKE_COMMAND}" -E copy ./working.c.in "${TestWorkingDir_BINARY_DIR}/working.c"
  6. WORKING_DIRECTORY "${TestWorkingDir_SOURCE_DIR}"
  7. COMMENT "custom command"
  8. )
  9. set_source_files_properties(
  10. "${TestWorkingDir_BINARY_DIR}/customTarget.c"
  11. "${TestWorkingDir_BINARY_DIR}/customTarget2.c"
  12. PROPERTIES GENERATED 1)
  13. add_executable(working "${TestWorkingDir_BINARY_DIR}/working.c"
  14. "${TestWorkingDir_BINARY_DIR}/customTarget.c")
  15. add_custom_target(
  16. Custom ALL
  17. COMMAND "${CMAKE_COMMAND}" -E copy_if_different ./customTarget.c "${TestWorkingDir_BINARY_DIR}/customTarget.c"
  18. BYPRODUCTS "${TestWorkingDir_BINARY_DIR}/customTarget.c"
  19. WORKING_DIRECTORY "${TestWorkingDir_SOURCE_DIR}"
  20. )
  21. add_dependencies(working Custom)
  22. file(MAKE_DIRECTORY ${TestWorkingDir_BINARY_DIR}/work)
  23. add_custom_command(
  24. OUTPUT working2.c # Relative to build tree
  25. COMMAND "${CMAKE_COMMAND}" -E copy ${TestWorkingDir_SOURCE_DIR}/working.c.in ../working2.c
  26. DEPENDS ${TestWorkingDir_SOURCE_DIR}/working.c.in/ # trailing slash should be removed
  27. WORKING_DIRECTORY work/ # Relative to build tree, trailing slash
  28. )
  29. add_executable(working2 working2.c ${TestWorkingDir_BINARY_DIR}/customTarget2.c)
  30. add_custom_target(
  31. Custom2 ALL
  32. COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${TestWorkingDir_SOURCE_DIR}/customTarget.c ../customTarget2.c
  33. BYPRODUCTS "${TestWorkingDir_BINARY_DIR}/customTarget2.c"
  34. WORKING_DIRECTORY work/ # Relative to build tree, trailing slash
  35. )
  36. add_dependencies(working2 Custom2)
  37. file(MAKE_DIRECTORY ${TestWorkingDir_BINARY_DIR}/genex)
  38. add_custom_command(
  39. OUTPUT "${TestWorkingDir_BINARY_DIR}/genex/working.c"
  40. COMMAND "${CMAKE_COMMAND}" -E copy "${TestWorkingDir_SOURCE_DIR}/working.c.in" "${TestWorkingDir_BINARY_DIR}/genex/working.c"
  41. WORKING_DIRECTORY "${TestWorkingDir_BINARY_DIR}/$<1:genex>/"
  42. COMMENT "custom command"
  43. )
  44. add_executable(workinggenex "${TestWorkingDir_BINARY_DIR}/genex/working.c"
  45. "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c")
  46. add_custom_target(
  47. CustomGenex ALL
  48. COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${TestWorkingDir_SOURCE_DIR}/customTarget.c" "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c"
  49. BYPRODUCTS "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c"
  50. WORKING_DIRECTORY "${TestWorkingDir_BINARY_DIR}/$<1:genex>/"
  51. )
  52. add_dependencies(workinggenex CustomGenex)