CMakeLists.txt 2.8 KB

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