/3rd_party/llvm/cmake/modules/TableGen.cmake

https://code.google.com/p/softart/ · CMake · 143 lines · 106 code · 21 blank · 16 comment · 13 complexity · 09fab8bd086d077b960243e62e7bc1fc MD5 · raw file

  1. # LLVM_TARGET_DEFINITIONS must contain the name of the .td file to process.
  2. # Extra parameters for `tblgen' may come after `ofn' parameter.
  3. # Adds the name of the generated file to TABLEGEN_OUTPUT.
  4. macro(tablegen project ofn)
  5. file(GLOB local_tds "*.td")
  6. file(GLOB_RECURSE global_tds "${LLVM_MAIN_SRC_DIR}/include/llvm/*.td")
  7. if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS})
  8. set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS})
  9. else()
  10. set(LLVM_TARGET_DEFINITIONS_ABSOLUTE
  11. ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS})
  12. endif()
  13. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
  14. # Generate tablegen output in a temporary file.
  15. COMMAND ${${project}_TABLEGEN_EXE} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR}
  16. -I ${LLVM_MAIN_SRC_DIR}/lib/Target -I ${LLVM_MAIN_INCLUDE_DIR}
  17. ${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
  18. -o ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
  19. # The file in LLVM_TARGET_DEFINITIONS may be not in the current
  20. # directory and local_tds may not contain it, so we must
  21. # explicitly list it here:
  22. DEPENDS ${${project}_TABLEGEN_EXE} ${local_tds} ${global_tds}
  23. ${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
  24. COMMENT "Building ${ofn}..."
  25. )
  26. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
  27. # Only update the real output file if there are any differences.
  28. # This prevents recompilation of all the files depending on it if there
  29. # aren't any.
  30. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  31. ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
  32. ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
  33. DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp
  34. COMMENT ""
  35. )
  36. # `make clean' must remove all those generated files:
  37. set_property(DIRECTORY APPEND
  38. PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${ofn}.tmp ${ofn})
  39. set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn})
  40. set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${ofn}
  41. PROPERTIES GENERATED 1)
  42. endmacro(tablegen)
  43. function(add_public_tablegen_target target)
  44. # Creates a target for publicly exporting tablegen dependencies.
  45. if( TABLEGEN_OUTPUT )
  46. add_custom_target(${target}
  47. DEPENDS ${TABLEGEN_OUTPUT})
  48. if (LLVM_COMMON_DEPENDS)
  49. add_dependencies(${target} ${LLVM_COMMON_DEPENDS})
  50. endif ()
  51. set_target_properties(${target} PROPERTIES FOLDER "Tablegenning")
  52. endif( TABLEGEN_OUTPUT )
  53. endfunction()
  54. if(CMAKE_CROSSCOMPILING)
  55. set(CX_NATIVE_TG_DIR "${CMAKE_BINARY_DIR}/native")
  56. add_custom_command(OUTPUT ${CX_NATIVE_TG_DIR}
  57. COMMAND ${CMAKE_COMMAND} -E make_directory ${CX_NATIVE_TG_DIR}
  58. COMMENT "Creating ${CX_NATIVE_TG_DIR}...")
  59. add_custom_command(OUTPUT ${CX_NATIVE_TG_DIR}/CMakeCache.txt
  60. COMMAND ${CMAKE_COMMAND} -UMAKE_TOOLCHAIN_FILE -DCMAKE_BUILD_TYPE=Release
  61. -DLLVM_BUILD_POLLY=OFF
  62. -G "${CMAKE_GENERATOR}" ${CMAKE_SOURCE_DIR}
  63. WORKING_DIRECTORY ${CX_NATIVE_TG_DIR}
  64. DEPENDS ${CX_NATIVE_TG_DIR}
  65. COMMENT "Configuring native TableGen...")
  66. add_custom_target(ConfigureNativeTableGen DEPENDS ${CX_NATIVE_TG_DIR}/CMakeCache.txt)
  67. set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CX_NATIVE_TG_DIR})
  68. endif()
  69. macro(add_tablegen target project)
  70. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
  71. set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
  72. set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen)
  73. add_llvm_utility(${target} ${ARGN})
  74. set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS})
  75. # For Xcode builds, symlink bin/<target> to bin/<Config>/<target> so that
  76. # a separately-configured Clang project can still find llvm-tblgen.
  77. if (XCODE)
  78. add_custom_target(${target}-top ALL
  79. ${CMAKE_COMMAND} -E create_symlink
  80. ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}
  81. ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}${CMAKE_EXECUTABLE_SUFFIX}
  82. DEPENDS ${target})
  83. endif ()
  84. set(${project}_TABLEGEN "${target}" CACHE
  85. STRING "Native TableGen executable. Saves building one when cross-compiling.")
  86. # Upgrade existing LLVM_TABLEGEN setting.
  87. if(${project} STREQUAL LLVM)
  88. if(${LLVM_TABLEGEN} STREQUAL tblgen)
  89. set(LLVM_TABLEGEN "${target}" CACHE
  90. STRING "Native TableGen executable. Saves building one when cross-compiling."
  91. FORCE)
  92. endif()
  93. endif()
  94. # Effective tblgen executable to be used:
  95. set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN} PARENT_SCOPE)
  96. if(CMAKE_CROSSCOMPILING)
  97. if( ${${project}_TABLEGEN} STREQUAL "${target}" )
  98. set(${project}_TABLEGEN_EXE "${CX_NATIVE_TG_DIR}/bin/${target}")
  99. set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN_EXE} PARENT_SCOPE)
  100. add_custom_command(OUTPUT ${${project}_TABLEGEN_EXE}
  101. COMMAND ${CMAKE_BUILD_TOOL} ${target}
  102. DEPENDS ${CX_NATIVE_TG_DIR}/CMakeCache.txt
  103. WORKING_DIRECTORY ${CX_NATIVE_TG_DIR}
  104. COMMENT "Building native TableGen...")
  105. add_custom_target(${project}NativeTableGen DEPENDS ${${project}_TABLEGEN_EXE})
  106. add_dependencies(${project}NativeTableGen ConfigureNativeTableGen)
  107. add_dependencies(${target} ${project}NativeTableGen)
  108. endif()
  109. endif()
  110. if( MINGW )
  111. target_link_libraries(${target} imagehlp psapi shell32)
  112. if(CMAKE_SIZEOF_VOID_P MATCHES "8")
  113. set_target_properties(${target} PROPERTIES LINK_FLAGS -Wl,--stack,16777216)
  114. endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
  115. endif( MINGW )
  116. if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD AND NOT BEOS )
  117. target_link_libraries(${target} pthread)
  118. endif()
  119. if (${project} STREQUAL LLVM AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
  120. install(TARGETS ${target} RUNTIME DESTINATION bin)
  121. endif()
  122. endmacro()