[CMake] [Darwin] Add support for debugging tablegen dependencies
This patch adds an option to the build system LLVM_DEPENDENCY_DEBUGGING. Over time I plan to extend this to do more complex verifications, but the initial patch causes compile errors wherever there is missing a dependency on intrinsics_gen.
Because intrinsics_gen is a compile-time dependency not a link-time dependency, everything that relies on the headers generated in intrinsics_gen needs an explicit dependency.
llvm-svn: 287207
GitOrigin-RevId: 8036e0b21a9e62adb7aee9793ce0a90646e37b73
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f67fd23..1f301bd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -151,6 +151,20 @@
endif()
endif()
+option(LLVM_DEPENDENCY_DEBUGGING "Dependency debugging mode to verify correctly expressed library dependencies (Darwin only)" OFF)
+
+# Some features of the LLVM build may be disallowed when dependency debugging is
+# enabled. In particular you cannot use ccache because we want to force compile
+# operations to always happen.
+if(LLVM_DEPENDENCY_DEBUGGING)
+ if(NOT CMAKE_HOST_APPLE)
+ message(FATAL_ERROR "Dependency debugging is only currently supported on Darwin hosts.")
+ endif()
+ if(LLVM_CCACHE_BUILD)
+ message(FATAL_ERROR "Cannot enable dependency debugging while using ccache.")
+ endif()
+endif()
+
option(LLVM_BUILD_GLOBAL_ISEL "Experimental: Build GlobalISel" OFF)
if(LLVM_BUILD_GLOBAL_ISEL)
add_definitions(-DLLVM_BUILD_GLOBAL_ISEL)
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index e8e119b..ef0dbf4 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -377,6 +377,8 @@
endif()
endif()
+ setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
+
# Generate objlib
if((ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT)
# Generate an obj library for both targets.
@@ -645,9 +647,11 @@
macro(add_llvm_executable name)
- cmake_parse_arguments(ARG "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH" "" "" ${ARGN})
+ cmake_parse_arguments(ARG "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH" "" "DEPENDS" ${ARGN})
llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} )
+ list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
+
# Generate objlib
if(LLVM_ENABLE_OBJLIB)
# Generate an obj library for both targets.
@@ -669,6 +673,8 @@
list(APPEND ALL_FILES "${LLVM_MAIN_SRC_DIR}/cmake/dummy.cpp")
endif()
+ setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
+
if( EXCLUDE_FROM_ALL )
add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
else()
@@ -1377,3 +1383,19 @@
INSTALL_RPATH "${_install_rpath}"
${_install_name_dir})
endfunction()
+
+function(setup_dependency_debugging name)
+ if(NOT LLVM_DEPENDENCY_DEBUGGING)
+ return()
+ endif()
+
+ if("intrinsics_gen" IN_LIST ARGN)
+ return()
+ endif()
+
+ set(deny_attributes_gen "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Attributes.gen\"))")
+ set(deny_intrinsics_gen "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Intrinsics.gen\"))")
+
+ set(sandbox_command "sandbox-exec -p '(version 1) (allow default) ${deny_attributes_gen} ${deny_intrinsics_gen}'")
+ set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE ${sandbox_command})
+endfunction()