Skip to content

Commit

Permalink
CMake: rename cmake_* with cg_*
Browse files Browse the repository at this point in the history
  • Loading branch information
sogartar committed Dec 1, 2021
1 parent ce7e88a commit 1f94358
Show file tree
Hide file tree
Showing 67 changed files with 355 additions and 355 deletions.
30 changes: 15 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/
)

include(cmake_macros)
include(cmake_copts)
include(cmake_genrule)
include(cmake_cc_binary)
include(cmake_cc_library)
include(cmake_cc_test)
include(cmake_py_binary)
include(cmake_py_library)
include(cmake_py_test)
include(cmake_python)
include(cmake_lit_test)
include(cmake_add_all_subdirs)
include(cmake_check_test)
include(cmake_run_binary_test)
include(cmake_filegroup)
include(cg_macros)
include(cg_copts)
include(cg_genrule)
include(cg_cc_binary)
include(cg_cc_library)
include(cg_cc_test)
include(cg_py_binary)
include(cg_py_library)
include(cg_py_test)
include(cg_python)
include(cg_lit_test)
include(cg_add_all_subdirs)
include(cg_check_test)
include(cg_run_binary_test)
include(cg_filegroup)
include(grpc)
include(protobuf)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copied from https://github.com/google/iree/blob/main/build_tools/cmake/cmake_add_all_subdirs.cmake
# Copied from https://github.com/google/iree/blob/main/build_tools/cmake/cg_add_all_subdirs.cmake
# Copyright 2020 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# cmake_add_all_subidrs
# cg_add_all_subidrs
#
# CMake function to add all subdirectories of the current directory that contain
# a CMakeLists.txt file
#
# Takes no arguments.
function(cmake_add_all_subdirs)
function(cg_add_all_subdirs)
FILE(GLOB _CHILDREN RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
SET(_DIRLIST "")
foreach(_CHILD ${_CHILDREN})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copied from https://github.com/google/iree/blob/main/build_tools/cmake/cmake_cc_binary.cmake[
# Copied from https://github.com/google/iree/blob/main/build_tools/cmake/cg_cc_binary.cmake[
# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
Expand All @@ -7,7 +7,7 @@

include(CMakeParseArguments)

# cmake_cc_binary()
# cg_cc_binary()
#
# CMake function to imitate Bazel's cc_binary rule.
#
Expand All @@ -23,13 +23,13 @@ include(CMakeParseArguments)
# HOSTONLY: host only; compile using host toolchain when cross-compiling
#
# Note:
# cmake_cc_binary will create a binary called ${PACKAGE_NAME}_${NAME}, e.g.
# cg_cc_binary will create a binary called ${PACKAGE_NAME}_${NAME}, e.g.
# cmake_base_foo with two alias (readonly) targets, a qualified
# ${PACKAGE_NS}::${NAME} and an unqualified ${NAME}. Thus NAME must be globally
# unique in the project.
#
# Usage:
# cmake_cc_library(
# cg_cc_library(
# NAME
# awesome
# HDRS
Expand All @@ -39,15 +39,15 @@ include(CMakeParseArguments)
# PUBLIC
# )
#
# cmake_cc_binary(
# cg_cc_binary(
# NAME
# awesome_tool
# SRCS
# "awesome-tool-main.cc"
# DEPS
# iree::awesome
# )
function(cmake_cc_binary)
function(cg_cc_binary)
cmake_parse_arguments(
_RULE
"HOSTONLY;TESTONLY"
Expand All @@ -60,8 +60,8 @@ function(cmake_cc_binary)
return()
endif()

cmake_package_ns(_PACKAGE_NS)
# Prefix the library with the package name, so we get: cmake_package_name
cg_package_ns(_PACKAGE_NS)
# Prefix the library with the package name, so we get: cg_package_name
rename_bazel_targets(_NAME "${_RULE_NAME}")

add_executable(${_NAME} "")
Expand All @@ -74,7 +74,7 @@ function(cmake_cc_binary)
# example, foo/bar/ library 'bar' would end up as 'foo::bar'. This isn't
# likely to be common for binaries, but is consistent with the behavior for
# libraries and in Bazel.
cmake_package_dir(_PACKAGE_DIR)
cg_package_dir(_PACKAGE_DIR)
if(${_RULE_NAME} STREQUAL ${_PACKAGE_DIR})
add_executable(${_PACKAGE_NS} ALIAS ${_NAME})
endif()
Expand Down Expand Up @@ -131,7 +131,7 @@ function(cmake_cc_binary)
${_RULE_ABS_DEPS}
)

cmake_add_data_dependencies(NAME ${_RULE_NAME} DATA ${_RULE_DATA})
cg_add_data_dependencies(NAME ${_RULE_NAME} DATA ${_RULE_DATA})

# Add all IREE targets to a folder in the IDE for organization.
set_target_properties(${_NAME} PROPERTIES
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copied from https://github.com/google/iree/blob/main/build_tools/cmake/cmake_cc_library.cmake
# Copied from https://github.com/google/iree/blob/main/build_tools/cmake/cg_cc_library.cmake
# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
Expand All @@ -7,7 +7,7 @@

include(CMakeParseArguments)

# cmake_cc_library()
# cg_cc_library()
#
# CMake function to imitate Bazel's cc_library rule.
#
Expand All @@ -28,19 +28,19 @@ include(CMakeParseArguments)
# SHARED: If set, will compile to a shared object.
#
# Note:
# By default, cmake_cc_library will always create a library named cmake_${NAME},
# By default, cg_cc_library will always create a library named cg_${NAME},
# and alias target iree::${NAME}. The iree:: form should always be used.
# This is to reduce namespace pollution.
#
# cmake_cc_library(
# cg_cc_library(
# NAME
# awesome
# HDRS
# "a.h"
# SRCS
# "a.cc"
# )
# cmake_cc_library(
# cg_cc_library(
# NAME
# fantastic_lib
# SRCS
Expand All @@ -50,14 +50,14 @@ include(CMakeParseArguments)
# PUBLIC
# )
#
# cmake_cc_library(
# cg_cc_library(
# NAME
# main_lib
# ...
# DEPS
# iree::package::fantastic_lib
# )
function(cmake_cc_library)
function(cg_cc_library)
cmake_parse_arguments(
_RULE
"PUBLIC;TESTONLY;SHARED"
Expand All @@ -70,11 +70,11 @@ function(cmake_cc_library)
return()
endif()

cmake_package_ns(_PACKAGE_NS)
cg_package_ns(_PACKAGE_NS)
rename_bazel_targets(_DEPS "${_RULE_DEPS}")
list(APPEND _DEPS ${_RULE_ABS_DEPS})

# Prefix the library with the package name, so we get: cmake_package_name.
# Prefix the library with the package name, so we get: cg_package_name.
rename_bazel_targets(_NAME "${_RULE_NAME}")

# Check if this is a header-only library.
Expand Down Expand Up @@ -174,22 +174,22 @@ function(cmake_cc_library)
)
endif()

cmake_add_data_dependencies(NAME ${_RULE_NAME} DATA ${_RULE_DATA})
cg_add_data_dependencies(NAME ${_RULE_NAME} DATA ${_RULE_DATA})

if (_RULE_NON_LIB_DEPS)
rename_bazel_targets(_NON_LIB_DEPS "${_RULE_NON_LIB_DEPS}")
add_dependencies(${_NAME} ${_NON_LIB_DEPS})
endif()

# Alias the cmake_package_name library to iree::package::name.
# Alias the cg_package_name library to iree::package::name.
# This lets us more clearly map to Bazel and makes it possible to
# disambiguate the underscores in paths vs. the separators.
add_library(${_PACKAGE_NS}::${_RULE_NAME} ALIAS ${_NAME})

# If the library name matches the final component of the package then treat
# it as a default. For example, foo/bar/ library 'bar' would end up as
# 'foo::bar'.
cmake_package_dir(_PACKAGE_DIR)
cg_package_dir(_PACKAGE_DIR)
if(${_RULE_NAME} STREQUAL ${_PACKAGE_DIR})
add_library(${_PACKAGE_NS} ALIAS ${_NAME})
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copied from https://github.com/google/iree/blob/main/build_tools/cmake/cmake_cc_test.cmake
# Copied from https://github.com/google/iree/blob/main/build_tools/cmake/cg_cc_test.cmake
# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

include(CMakeParseArguments)
include(cmake_installed_test)
include(cg_installed_test)

# cmake_cc_test()
# cg_cc_test()
#
# CMake function to imitate Bazel's cc_test rule.
#
Expand All @@ -24,12 +24,12 @@ include(cmake_installed_test)
# automatically.
#
# Note:
# cmake_cc_test will create a binary called ${PACKAGE_NAME}_${NAME}, e.g.
# cmake_base_foo_test.
# cg_cc_test will create a binary called ${PACKAGE_NAME}_${NAME}, e.g.
# cg_base_foo_test.
#
#
# Usage:
# cmake_cc_library(
# cg_cc_library(
# NAME
# awesome
# HDRS
Expand All @@ -39,7 +39,7 @@ include(cmake_installed_test)
# PUBLIC
# )
#
# cmake_cc_test(
# cg_cc_test(
# NAME
# awesome_test
# SRCS
Expand All @@ -48,7 +48,7 @@ include(cmake_installed_test)
# gtest_main
# iree::awesome
# )
function(cmake_cc_test)
function(cg_cc_test)
if(NOT IREE_BUILD_TESTS)
return()
endif()
Expand All @@ -61,12 +61,12 @@ function(cmake_cc_test)
${ARGN}
)

cmake_package_ns(_PACKAGE_NS)
# Prefix the library with the package name, so we get: cmake_package_name
cg_package_ns(_PACKAGE_NS)
# Prefix the library with the package name, so we get: cg_package_name
rename_bazel_targets(_NAME "${_RULE_NAME}")

add_executable(${_NAME} "")
# Alias the cmake_package_name test binary to iree::package::name.
# Alias the cg_package_name test binary to iree::package::name.
# This lets us more clearly map to Bazel and makes it possible to
# disambiguate the underscores in paths vs. the separators.
add_executable(${_PACKAGE_NS}::${_RULE_NAME} ALIAS ${_NAME})
Expand All @@ -75,7 +75,7 @@ function(cmake_cc_test)
# For example, foo/bar/ library 'bar' would end up as 'foo::bar'. This isn't
# likely to be common for tests, but is consistent with the behavior for
# libraries.
cmake_package_dir(_PACKAGE_DIR)
cg_package_dir(_PACKAGE_DIR)
if(${_RULE_NAME} STREQUAL ${_PACKAGE_DIR})
add_executable(${_PACKAGE_NS} ALIAS ${_NAME})
endif()
Expand Down Expand Up @@ -111,7 +111,7 @@ function(cmake_cc_test)
PUBLIC
${_RULE_DEPS}
)
cmake_add_data_dependencies(NAME ${_RULE_NAME} DATA ${_RULE_DATA})
cg_add_data_dependencies(NAME ${_RULE_NAME} DATA ${_RULE_DATA})

# Add all IREE targets to a folder in the IDE for organization.
set_property(TARGET ${_NAME} PROPERTY FOLDER ${IREE_IDE_FOLDER}/test)
Expand Down Expand Up @@ -152,7 +152,7 @@ function(cmake_cc_test)
set_property(TEST ${_TEST_NAME} PROPERTY ENVIRONMENT ${_ENVIRONMENT_VARS})
set_property(TEST ${_TEST_NAME} PROPERTY LABELS "${_RULE_LABELS}")
else(ANDROID)
cmake_add_installed_test(
cg_add_installed_test(
TEST_NAME "${_TEST_NAME}"
LABELS "${_RULE_LABELS}"
COMMAND
Expand Down
Loading

0 comments on commit 1f94358

Please sign in to comment.