CMakeLists.txt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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)