Tidy up CMake style across the project. (#9000)
This change _should_ be an NFC, just going through and aligning our CMake files on a consistent style for items like:
* No spaces between commands and the opening parenthesis: use `if(...)`, instead of `if (...)`
* No variable references when not needed: use `if(VARIABLE_NAME)` / `if(NOT VARIABLE_NAME)`, instead of `if(${VARIABLE_NAME})` / `if(NOT ${VARIABLE_NAME})`
* Local variables use `_UPPER_CASE`, instead of `_lower_case` or `UPPER_CASE`
* Parsed arguments use the `_RULE` prefix, not `ARG` (LLVM mostly uses `ARG`, but we've been using `_RULE`)
Individual commits have the details for how they were generated (surprise surprise, it's a pile of regex find/replaces with some manual cleanup sprinkled on top), as well as the rationale where applicable. I may have missed some cases in my search, and we have no automated formatting or enforcement.
---
Inspired by https://github.com/google/iree/pull/8933#discussion_r853526858:
> Use if(IREE_ENABLE_CPUINFO)
> (we're super inconsistent on this but I try to get it right going forward)diff --git a/build_tools/cmake/iree_python.cmake b/build_tools/cmake/iree_python.cmake
index 64e9143..0dc833b 100644
--- a/build_tools/cmake/iree_python.cmake
+++ b/build_tools/cmake/iree_python.cmake
@@ -70,27 +70,26 @@
"COMPONENT;PACKAGE_NAME;MODULE_PATH"
"DEPS;ADDL_PACKAGE_FILES;FILES_MATCHING"
${ARGN})
- set(_install_component ${ARG_COMPONENT})
- set(_install_packages_dir "python_packages/${ARG_PACKAGE_NAME}")
- set(_install_module_dir "${_install_packages_dir}/${ARG_MODULE_PATH}")
- set(_target_name install-${_install_component})
+ set(_INSTALL_COMPONENT ${ARG_COMPONENT})
+ set(_INSTALL_PACKAGES_DIR "python_packages/${ARG_PACKAGE_NAME}")
+ set(_INSTALL_MODULE_DIR "${_INSTALL_PACKAGES_DIR}/${ARG_MODULE_PATH}")
if(NOT FILES_MATCHING)
- set(_files_matching PATTERN "*.py")
+ set(_FILES_MATCHING PATTERN "*.py")
else()
- set(_files_matching ${ARG_FILES_MATCHING})
+ set(_FILES_MATCHING ${ARG_FILES_MATCHING})
endif()
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
- COMPONENT ${_install_component}
- DESTINATION "${_install_module_dir}"
- FILES_MATCHING ${_files_matching}
+ COMPONENT ${_INSTALL_COMPONENT}
+ DESTINATION "${_INSTALL_MODULE_DIR}"
+ FILES_MATCHING ${_FILES_MATCHING}
)
- set(PY_INSTALL_COMPONENT ${_install_component} PARENT_SCOPE)
- set(PY_INSTALL_PACKAGES_DIR "${_install_packages_dir}" PARENT_SCOPE)
- set(PY_INSTALL_MODULE_DIR "${_install_module_dir}" PARENT_SCOPE)
+ set(PY_INSTALL_COMPONENT ${_INSTALL_COMPONENT} PARENT_SCOPE)
+ set(PY_INSTALL_PACKAGES_DIR "${_INSTALL_PACKAGES_DIR}" PARENT_SCOPE)
+ set(PY_INSTALL_MODULE_DIR "${_INSTALL_MODULE_DIR}" PARENT_SCOPE)
endfunction()
# iree_pyext_module()
@@ -204,7 +203,7 @@
# PYEXT_DEPS: List of deps of extensions built with iree_pyext_module
function(iree_py_library)
cmake_parse_arguments(
- ARG
+ _RULE
""
"NAME"
"SRCS;DEPS;PYEXT_DEPS"
@@ -213,36 +212,36 @@
iree_package_ns(_PACKAGE_NS)
# Replace dependencies passed by ::name with ::iree::package::name
- list(TRANSFORM ARG_DEPS REPLACE "^::" "${_PACKAGE_NS}::")
+ list(TRANSFORM _RULE_DEPS REPLACE "^::" "${_PACKAGE_NS}::")
iree_package_name(_PACKAGE_NAME)
- set(_NAME "${_PACKAGE_NAME}_${ARG_NAME}")
+ set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
add_custom_target(${_NAME} ALL
- DEPENDS ${ARG_DEPS}
+ DEPENDS ${_RULE_DEPS}
)
# Symlink each file as its own target.
- foreach(SRC_FILE ${ARG_SRCS})
- # SRC_FILE could have other path components in it, so we need to make a
+ foreach(_SRC_FILE ${_RULE_SRCS})
+ # _SRC_FILE could have other path components in it, so we need to make a
# directory for it. Ninja does this automatically, but make doesn't. See
# https://github.com/google/iree/issues/6801
- set(_SRC_BIN_PATH "${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE}")
+ set(_SRC_BIN_PATH "${CMAKE_CURRENT_BINARY_DIR}/${_SRC_FILE}")
get_filename_component(_SRC_BIN_DIR "${_SRC_BIN_PATH}" DIRECTORY)
add_custom_command(
TARGET ${_NAME}
COMMAND
${CMAKE_COMMAND} -E make_directory "${_SRC_BIN_DIR}"
COMMAND ${CMAKE_COMMAND} -E create_symlink
- "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FILE}" "${_SRC_BIN_PATH}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/${_SRC_FILE}" "${_SRC_BIN_PATH}"
BYPRODUCTS "${_SRC_BIN_PATH}"
)
endforeach()
# Add PYEXT_DEPS if any.
- if(ARG_PYEXT_DEPS)
- list(TRANSFORM ARG_PYEXT_DEPS REPLACE "^::" "${_PACKAGE_NS}::")
- add_dependencies(${_NAME} ${ARG_PYEXT_DEPS})
+ if(_RULE_PYEXT_DEPS)
+ list(TRANSFORM _RULE_PYEXT_DEPS REPLACE "^::" "${_PACKAGE_NS}::")
+ add_dependencies(${_NAME} ${_RULE_PYEXT_DEPS})
endif()
endfunction()