CMakeLists.txt 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. cmake_minimum_required(VERSION 2.6)
  2. project(testRebuild)
  3. add_library(foo STATIC ${testRebuild_BINARY_DIR}/foo.cxx)
  4. # Add a generated header that regenerates when the generator is
  5. # rebuilt.
  6. add_custom_command(
  7. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/regen.h
  8. COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/regen.h regen
  9. DEPENDS generator # adds file-level dependency to re-run rule
  10. )
  11. # Add a generated header that does NOT regenerate when the generator
  12. # is rebuilt.
  13. add_custom_command(
  14. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
  15. COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/noregen.h noregen
  16. )
  17. # Test that the generator rebuilds when the static library source file
  18. # changes. This should cause regen.h to be recreated also.
  19. add_executable(generator generator.cxx)
  20. target_link_libraries(generator foo)
  21. # Build an executable to drive the build and rebuild.
  22. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  23. add_executable(bar bar.cxx
  24. ${CMAKE_CURRENT_BINARY_DIR}/regen.h
  25. ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
  26. )
  27. #-----------------------------------------------------------------------------
  28. IF("${CMAKE_GENERATOR}" MATCHES "Make")
  29. # Test the IMPLICIT_DEPENDS feature.
  30. SET(ZOT_DEPENDS IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep.cxx)
  31. SET(ZOT_CUSTOM_DEP
  32. IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep_custom.cxx)
  33. ELSE("${CMAKE_GENERATOR}" MATCHES "Make")
  34. # No IMPLICIT_DEPENDS...just depend directly.
  35. SET(ZOT_DEPENDS DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in)
  36. SET(ZOT_CUSTOM_DEP DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in)
  37. ENDIF("${CMAKE_GENERATOR}" MATCHES "Make")
  38. add_custom_command(
  39. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
  40. COMMAND ${CMAKE_COMMAND} -E copy
  41. ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in
  42. ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
  43. ${ZOT_DEPENDS}
  44. )
  45. add_custom_command(
  46. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
  47. COMMAND ${CMAKE_COMMAND} -E copy
  48. ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in
  49. ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
  50. ${ZOT_CUSTOM_DEP}
  51. )
  52. add_custom_target(zot_custom ALL DEPENDS
  53. ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx)
  54. add_executable(zot zot.cxx ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
  55. zot_macro_dir.cxx zot_macro_tgt.cxx)
  56. add_dependencies(zot zot_custom)
  57. # Test the #include line macro transformation rule support.
  58. set_property(
  59. TARGET zot
  60. PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_TGT(%)=<zot_%_tgt.hxx>"
  61. )
  62. set_property(
  63. DIRECTORY
  64. PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_DIR(%)=<zot_%_dir.hxx>"
  65. )