Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 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 | |
Chris Bieneman | 76864f9 | 2016-09-06 20:27:07 +0000 | [diff] [blame^] | 5 | include(LLVMExternalProjectUtils) |
| 6 | |
NAKAMURA Takumi | 93d4cda | 2014-01-26 12:41:33 +0000 | [diff] [blame] | 7 | function(tablegen project ofn) |
NAKAMURA Takumi | 04817e4 | 2014-02-12 11:50:11 +0000 | [diff] [blame] | 8 | # Validate calling context. |
| 9 | foreach(v |
| 10 | ${project}_TABLEGEN_EXE |
| 11 | LLVM_MAIN_SRC_DIR |
| 12 | LLVM_MAIN_INCLUDE_DIR |
| 13 | ) |
| 14 | if(NOT ${v}) |
| 15 | message(FATAL_ERROR "${v} not set") |
| 16 | endif() |
| 17 | endforeach() |
| 18 | |
NAKAMURA Takumi | e6bf06b | 2014-02-04 01:17:12 +0000 | [diff] [blame] | 19 | file(GLOB local_tds "*.td") |
| 20 | file(GLOB_RECURSE global_tds "${LLVM_MAIN_INCLUDE_DIR}/llvm/*.td") |
Douglas Gregor | d36792c | 2009-03-16 21:35:18 +0000 | [diff] [blame] | 21 | |
Douglas Gregor | 934ced7 | 2010-06-17 15:17:07 +0000 | [diff] [blame] | 22 | if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS}) |
| 23 | set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS}) |
| 24 | else() |
NAKAMURA Takumi | dba47bf | 2014-02-09 16:38:31 +0000 | [diff] [blame] | 25 | set(LLVM_TARGET_DEFINITIONS_ABSOLUTE |
Douglas Gregor | 934ced7 | 2010-06-17 15:17:07 +0000 | [diff] [blame] | 26 | ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS}) |
| 27 | endif() |
Oscar Fuentes | a522175 | 2010-10-22 17:37:42 +0000 | [diff] [blame] | 28 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp |
Oscar Fuentes | 861e51a | 2010-10-22 16:20:10 +0000 | [diff] [blame] | 29 | # Generate tablegen output in a temporary file. |
NAKAMURA Takumi | e6bf06b | 2014-02-04 01:17:12 +0000 | [diff] [blame] | 30 | COMMAND ${${project}_TABLEGEN_EXE} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR} |
| 31 | -I ${LLVM_MAIN_SRC_DIR}/lib/Target -I ${LLVM_MAIN_INCLUDE_DIR} |
NAKAMURA Takumi | dba47bf | 2014-02-09 16:38:31 +0000 | [diff] [blame] | 32 | ${LLVM_TARGET_DEFINITIONS_ABSOLUTE} |
Oscar Fuentes | 861e51a | 2010-10-22 16:20:10 +0000 | [diff] [blame] | 33 | -o ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp |
Oscar Fuentes | 0db031d | 2011-01-03 20:01:32 +0000 | [diff] [blame] | 34 | # The file in LLVM_TARGET_DEFINITIONS may be not in the current |
| 35 | # directory and local_tds may not contain it, so we must |
| 36 | # explicitly list it here: |
Chris Bieneman | 3eddcae | 2015-04-24 17:09:20 +0000 | [diff] [blame] | 37 | DEPENDS ${${project}_TABLEGEN_TARGET} ${local_tds} ${global_tds} |
Oscar Fuentes | f4202ba | 2011-02-03 20:57:36 +0000 | [diff] [blame] | 38 | ${LLVM_TARGET_DEFINITIONS_ABSOLUTE} |
Oscar Fuentes | a522175 | 2010-10-22 17:37:42 +0000 | [diff] [blame] | 39 | COMMENT "Building ${ofn}..." |
| 40 | ) |
| 41 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn} |
Oscar Fuentes | 861e51a | 2010-10-22 16:20:10 +0000 | [diff] [blame] | 42 | # Only update the real output file if there are any differences. |
| 43 | # This prevents recompilation of all the files depending on it if there |
| 44 | # aren't any. |
| 45 | COMMAND ${CMAKE_COMMAND} -E copy_if_different |
| 46 | ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp |
| 47 | ${CMAKE_CURRENT_BINARY_DIR}/${ofn} |
Oscar Fuentes | a522175 | 2010-10-22 17:37:42 +0000 | [diff] [blame] | 48 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.tmp |
NAKAMURA Takumi | 9668890 | 2014-01-12 17:42:43 +0000 | [diff] [blame] | 49 | COMMENT "Updating ${ofn}..." |
Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 50 | ) |
Oscar Fuentes | a6aa878 | 2011-02-04 03:47:50 +0000 | [diff] [blame] | 51 | |
| 52 | # `make clean' must remove all those generated files: |
| 53 | set_property(DIRECTORY APPEND |
| 54 | PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${ofn}.tmp ${ofn}) |
| 55 | |
NAKAMURA Takumi | 93d4cda | 2014-01-26 12:41:33 +0000 | [diff] [blame] | 56 | set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn} PARENT_SCOPE) |
NAKAMURA Takumi | d93593f | 2014-02-23 12:54:15 +0000 | [diff] [blame] | 57 | set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${ofn} PROPERTIES |
| 58 | GENERATED 1) |
| 59 | endfunction() |
Oscar Fuentes | a2e6274 | 2011-07-25 14:11:55 +0000 | [diff] [blame] | 60 | |
NAKAMURA Takumi | d93593f | 2014-02-23 12:54:15 +0000 | [diff] [blame] | 61 | # Creates a target for publicly exporting tablegen dependencies. |
| 62 | function(add_public_tablegen_target target) |
| 63 | if(NOT TABLEGEN_OUTPUT) |
| 64 | message(FATAL_ERROR "Requires tablegen() definitions as TABLEGEN_OUTPUT.") |
| 65 | endif() |
| 66 | add_custom_target(${target} |
| 67 | DEPENDS ${TABLEGEN_OUTPUT}) |
| 68 | if(LLVM_COMMON_DEPENDS) |
| 69 | add_dependencies(${target} ${LLVM_COMMON_DEPENDS}) |
| 70 | endif() |
| 71 | set_target_properties(${target} PROPERTIES FOLDER "Tablegenning") |
| 72 | set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${target} PARENT_SCOPE) |
| 73 | endfunction() |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 74 | |
Chris Bieneman | 8a3e6e19 | 2015-10-09 22:26:04 +0000 | [diff] [blame] | 75 | if(LLVM_USE_HOST_TOOLS) |
Chris Bieneman | 76864f9 | 2016-09-06 20:27:07 +0000 | [diff] [blame^] | 76 | llvm_ExternalProject_BuildCmd(tblgen_build_cmd LLVMSupport |
| 77 | ${LLVM_NATIVE_BUILD} |
| 78 | CONFIGURATION Release) |
Chris Bieneman | 9b058a6 | 2015-10-23 19:48:17 +0000 | [diff] [blame] | 79 | add_custom_command(OUTPUT LIB_LLVMTABLEGEN |
Chris Bieneman | 76864f9 | 2016-09-06 20:27:07 +0000 | [diff] [blame^] | 80 | COMMAND ${tblgen_build_cmd} |
Chris Bieneman | 9b058a6 | 2015-10-23 19:48:17 +0000 | [diff] [blame] | 81 | DEPENDS CONFIGURE_LLVM_NATIVE |
| 82 | WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} |
Chris Bieneman | 76864f9 | 2016-09-06 20:27:07 +0000 | [diff] [blame^] | 83 | COMMENT "Building libLLVMTableGen for native TableGen..." |
| 84 | USES_TERMINAL) |
Chris Bieneman | 9b058a6 | 2015-10-23 19:48:17 +0000 | [diff] [blame] | 85 | add_custom_target(NATIVE_LIB_LLVMTABLEGEN DEPENDS LIB_LLVMTABLEGEN) |
Chris Bieneman | 8a3e6e19 | 2015-10-09 22:26:04 +0000 | [diff] [blame] | 86 | endif(LLVM_USE_HOST_TOOLS) |
| 87 | |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 88 | macro(add_tablegen target project) |
Chandler Carruth | 39bf89b | 2011-11-02 05:03:06 +0000 | [diff] [blame] | 89 | set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS}) |
| 90 | set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen) |
NAKAMURA Takumi | e6bc093 | 2015-08-27 16:10:47 +0000 | [diff] [blame] | 91 | |
NAKAMURA Takumi | d4b2193 | 2015-09-02 10:11:26 +0000 | [diff] [blame] | 92 | if(NOT XCODE) |
| 93 | # FIXME: It leaks to user, callee of add_tablegen. |
| 94 | set(LLVM_ENABLE_OBJLIB ON) |
| 95 | endif() |
NAKAMURA Takumi | e6bc093 | 2015-08-27 16:10:47 +0000 | [diff] [blame] | 96 | |
Andrew Wilkins | bb6d95f | 2015-09-05 08:27:33 +0000 | [diff] [blame] | 97 | add_llvm_utility(${target} ${ARGN}) |
Chandler Carruth | 3198cc7 | 2011-11-02 16:55:57 +0000 | [diff] [blame] | 98 | set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS}) |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 99 | |
| 100 | set(${project}_TABLEGEN "${target}" CACHE |
| 101 | STRING "Native TableGen executable. Saves building one when cross-compiling.") |
| 102 | |
| 103 | # Upgrade existing LLVM_TABLEGEN setting. |
| 104 | if(${project} STREQUAL LLVM) |
| 105 | if(${LLVM_TABLEGEN} STREQUAL tblgen) |
| 106 | set(LLVM_TABLEGEN "${target}" CACHE |
| 107 | STRING "Native TableGen executable. Saves building one when cross-compiling." |
| 108 | FORCE) |
| 109 | endif() |
| 110 | endif() |
NAKAMURA Takumi | dba47bf | 2014-02-09 16:38:31 +0000 | [diff] [blame] | 111 | |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 112 | # Effective tblgen executable to be used: |
| 113 | set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN} PARENT_SCOPE) |
Chris Bieneman | 3eddcae | 2015-04-24 17:09:20 +0000 | [diff] [blame] | 114 | set(${project}_TABLEGEN_TARGET ${${project}_TABLEGEN} PARENT_SCOPE) |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 115 | |
Chris Bieneman | da91ceb | 2015-03-10 20:48:02 +0000 | [diff] [blame] | 116 | if(LLVM_USE_HOST_TOOLS) |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 117 | if( ${${project}_TABLEGEN} STREQUAL "${target}" ) |
Chris Bieneman | 7c445dd | 2015-05-29 18:34:41 +0000 | [diff] [blame] | 118 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| 119 | set(${project}_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/bin/${target}") |
| 120 | else() |
| 121 | set(${project}_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/Release/bin/${target}") |
| 122 | endif() |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 123 | set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN_EXE} PARENT_SCOPE) |
| 124 | |
Chris Bieneman | 76864f9 | 2016-09-06 20:27:07 +0000 | [diff] [blame^] | 125 | llvm_ExternalProject_BuildCmd(tblgen_build_cmd ${target} |
| 126 | ${LLVM_NATIVE_BUILD} |
| 127 | CONFIGURATION Release) |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 128 | add_custom_command(OUTPUT ${${project}_TABLEGEN_EXE} |
Chris Bieneman | 76864f9 | 2016-09-06 20:27:07 +0000 | [diff] [blame^] | 129 | COMMAND ${tblgen_build_cmd} |
| 130 | DEPENDS ${target} NATIVE_LIB_LLVMTABLEGEN |
Chris Bieneman | 5007741 | 2014-09-03 23:21:18 +0000 | [diff] [blame] | 131 | WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} |
Chris Bieneman | 76864f9 | 2016-09-06 20:27:07 +0000 | [diff] [blame^] | 132 | COMMENT "Building native TableGen..." |
| 133 | USES_TERMINAL) |
Chris Bieneman | 3eddcae | 2015-04-24 17:09:20 +0000 | [diff] [blame] | 134 | add_custom_target(${project}-tablegen-host DEPENDS ${${project}_TABLEGEN_EXE}) |
| 135 | set(${project}_TABLEGEN_TARGET ${project}-tablegen-host PARENT_SCOPE) |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 136 | endif() |
| 137 | endif() |
| 138 | |
Hans Wennborg | bac9d13 | 2013-09-10 18:35:14 +0000 | [diff] [blame] | 139 | if (${project} STREQUAL LLVM AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
NAKAMURA Takumi | ef97607 | 2014-02-09 16:36:03 +0000 | [diff] [blame] | 140 | install(TARGETS ${target} |
| 141 | EXPORT LLVMExports |
Chris Bieneman | 2724f14 | 2016-06-08 21:19:26 +0000 | [diff] [blame] | 142 | RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}) |
Hans Wennborg | bac9d13 | 2013-09-10 18:35:14 +0000 | [diff] [blame] | 143 | endif() |
NAKAMURA Takumi | 8faf660 | 2014-02-09 16:36:16 +0000 | [diff] [blame] | 144 | set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${target}) |
Peter Collingbourne | fb3d935 | 2011-10-06 01:51:51 +0000 | [diff] [blame] | 145 | endmacro() |