diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake index 7fd6628ef55d3..0f6aa0c5d826a 100644 --- a/llvm/cmake/modules/TableGen.cmake +++ b/llvm/cmake/modules/TableGen.cmake @@ -19,19 +19,34 @@ function(tablegen project ofn) # Use depfile instead of globbing arbitrary *.td(s) for Ninja. if(CMAKE_GENERATOR MATCHES "Ninja") - # Make output path relative to build.ninja, assuming located on - # ${CMAKE_BINARY_DIR}. # CMake emits build targets as relative paths but Ninja doesn't identify - # absolute path (in *.d) as relative path (in build.ninja) - # Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory. - file(RELATIVE_PATH ofn_rel - ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}) - set(additional_cmdline - -o ${ofn_rel} - -d ${ofn_rel}.d - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d - ) + # absolute path (in *.d) as relative path (in build.ninja). If CMP0116 is + # NEW, CMake handles this discrepancy for us -- otherwise, we have to work + # around it ourselves. + if(POLICY CMP0116) + cmake_policy(GET CMP0116 cmp0116_state) + else() + set(cmp0116_state OLD) + endif() + if(cmp0116_state STREQUAL NEW) + set(additional_cmdline + -o ${ofn} + -d ${ofn}.d + DEPFILE ${ofn}.d + ) + else() + # Make output path relative to build.ninja, assuming located on + # ${CMAKE_BINARY_DIR}. + # Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory. + file(RELATIVE_PATH ofn_rel + ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}) + set(additional_cmdline + -o ${ofn_rel} + -d ${ofn_rel}.d + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d + ) + endif() set(local_tds) set(global_tds) else() diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake index 544abe4368882..714054f17515c 100644 --- a/mlir/cmake/modules/AddMLIR.cmake +++ b/mlir/cmake/modules/AddMLIR.cmake @@ -48,19 +48,34 @@ function(_pdll_tablegen project ofn) # Use depfile instead of globbing arbitrary *.td(s) for Ninja. if(CMAKE_GENERATOR MATCHES "Ninja") - # Make output path relative to build.ninja, assuming located on - # ${CMAKE_BINARY_DIR}. # CMake emits build targets as relative paths but Ninja doesn't identify - # absolute path (in *.d) as relative path (in build.ninja) - # Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory. - file(RELATIVE_PATH ofn_rel - ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}) - set(additional_cmdline - -o ${ofn_rel} - -d ${ofn_rel}.d - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d - ) + # absolute path (in *.d) as relative path (in build.ninja). If CMP0116 is + # NEW, CMake handles this discrepancy for us -- otherwise, we have to work + # around it ourselves. + if(POLICY CMP0116) + cmake_policy(GET CMP0116 cmp0116_state) + else() + set(cmp0116_state OLD) + endif() + if(cmp0116_state STREQUAL NEW) + set(additional_cmdline + -o ${ofn} + -d ${ofn}.d + DEPFILE ${ofn}.d + ) + else() + # Make output path relative to build.ninja, assuming located on + # ${CMAKE_BINARY_DIR}. + # Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory. + file(RELATIVE_PATH ofn_rel + ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}) + set(additional_cmdline + -o ${ofn_rel} + -d ${ofn_rel}.d + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d + ) + endif() set(local_tds) set(global_tds) else()