CMakeLists.txt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. WORKING_DIRECTORY "${TestWorkingDir_SOURCE_DIR}"
  19. )
  20. add_dependencies(working Custom)
  21. file(MAKE_DIRECTORY ${TestWorkingDir_BINARY_DIR}/work)
  22. add_custom_command(
  23. OUTPUT working2.c # Relative to build tree
  24. COMMAND "${CMAKE_COMMAND}" -E copy ${TestWorkingDir_SOURCE_DIR}/working.c.in ../working2.c
  25. DEPENDS ${TestWorkingDir_SOURCE_DIR}/working.c.in/ # trailing slash should be removed
  26. WORKING_DIRECTORY work/ # Relative to build tree, trailing slash
  27. )
  28. add_executable(working2 working2.c ${TestWorkingDir_BINARY_DIR}/customTarget2.c)
  29. add_custom_target(
  30. Custom2 ALL
  31. COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${TestWorkingDir_SOURCE_DIR}/customTarget.c ../customTarget2.c
  32. WORKING_DIRECTORY work/ # Relative to build tree, trailing slash
  33. )
  34. add_dependencies(working2 Custom2)