CMakeLists.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. cmake_minimum_required(VERSION 2.6)
  2. project(testRebuild)
  3. function(test_for_xcode4 result_var)
  4. set(${result_var} 0 PARENT_SCOPE)
  5. if(APPLE)
  6. execute_process(COMMAND xcodebuild -version
  7. OUTPUT_VARIABLE ov RESULT_VARIABLE rv
  8. )
  9. if("${rv}" STREQUAL "0")
  10. if(ov MATCHES "^Xcode 4.[0-9].*$")
  11. set(${result_var} 1 PARENT_SCOPE)
  12. endif()
  13. endif()
  14. endif()
  15. endfunction()
  16. if(APPLE)
  17. # only use multi-arch if the sysroot exists on this machine
  18. # Ninja needs -M which could not be used with multiple -arch flags
  19. if(EXISTS "${CMAKE_OSX_SYSROOT}" AND NOT "${CMAKE_GENERATOR}" MATCHES "Ninja")
  20. set(CMAKE_OSX_ARCHITECTURES "ppc;i386")
  21. test_for_xcode4(is_xcode4)
  22. if(is_xcode4)
  23. # Xcode 4, use modern architectures as defaults
  24. # Arch 'ppc' no longer works: tools no longer available starting with Xcode 4
  25. set(CMAKE_OSX_ARCHITECTURES i386 x86_64)
  26. endif()
  27. endif(EXISTS "${CMAKE_OSX_SYSROOT}")
  28. endif(APPLE)
  29. add_library(foo STATIC ${testRebuild_BINARY_DIR}/foo.cxx)
  30. set_target_properties(foo PROPERTIES OUTPUT_NAME "foolib")
  31. # Add a generated header that regenerates when the generator is
  32. # rebuilt.
  33. add_custom_command(
  34. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/regen.h
  35. COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/regen.h regen
  36. DEPENDS generator # adds file-level dependency to re-run rule
  37. )
  38. # Add a generated header that does NOT regenerate when the generator
  39. # is rebuilt.
  40. add_custom_command(
  41. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
  42. COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/noregen.h noregen
  43. )
  44. # Test that the generator rebuilds when the static library source file
  45. # changes. This should cause regen.h to be recreated also.
  46. add_executable(generator generator.cxx)
  47. target_link_libraries(generator foo)
  48. set_target_properties(generator PROPERTIES OUTPUT_NAME "gen")
  49. # Build an executable to drive the build and rebuild.
  50. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  51. add_executable(bar bar.cxx
  52. ${CMAKE_CURRENT_BINARY_DIR}/regen.h
  53. ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
  54. )
  55. #-----------------------------------------------------------------------------
  56. IF("${CMAKE_GENERATOR}" MATCHES "Make")
  57. # Test the IMPLICIT_DEPENDS feature.
  58. SET(ZOT_DEPENDS IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep.cxx)
  59. SET(ZOT_CUSTOM_DEP
  60. IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep_custom.cxx)
  61. ELSE("${CMAKE_GENERATOR}" MATCHES "Make")
  62. # No IMPLICIT_DEPENDS...just depend directly.
  63. SET(ZOT_DEPENDS DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in)
  64. SET(ZOT_CUSTOM_DEP DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in)
  65. ENDIF("${CMAKE_GENERATOR}" MATCHES "Make")
  66. add_custom_command(
  67. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
  68. COMMAND ${CMAKE_COMMAND} -E copy
  69. ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in
  70. ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
  71. ${ZOT_DEPENDS}
  72. )
  73. add_custom_command(
  74. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
  75. COMMAND ${CMAKE_COMMAND} -E copy
  76. ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in
  77. ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
  78. ${ZOT_CUSTOM_DEP}
  79. )
  80. add_custom_target(zot_custom ALL DEPENDS
  81. ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx)
  82. add_executable(zot zot.cxx ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
  83. zot_macro_dir.cxx zot_macro_tgt.cxx)
  84. add_dependencies(zot zot_custom)
  85. # Test the #include line macro transformation rule support.
  86. set_property(
  87. TARGET zot
  88. PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_TGT(%)=<zot_%_tgt.hxx>"
  89. )
  90. set_property(
  91. DIRECTORY
  92. PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_DIR(%)=<zot_%_dir.hxx>"
  93. )
  94. if(TEST_LINK_DEPENDS)
  95. add_executable(linkdep linkdep.cxx)
  96. set_property(TARGET linkdep PROPERTY LINK_DEPENDS ${TEST_LINK_DEPENDS})
  97. endif()