copy missing cmake modules from vtr project

This commit is contained in:
tangxifan 2020-01-03 21:57:19 -05:00
parent b728773159
commit 68bf7a9462
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,46 @@
include(ProcessorCount)
ProcessorCount(CPU_COUNT)
if(CPU_COUNT EQUAL 0)
message(FATAL_ERROR "Unknown number of CPUs!?")
endif()
#
# ----------------------- Code format --------------------------
#
set(FIND_TO_FORMAT_CPP
-name '*.cpp' -print -o -name '*.h' -print
-o -name '*.tpp' -print -o -name '*.hpp' -print)
list(APPEND DIRS_TO_FORMAT_CPP "")
#
# List the files which will be auto-formatted.
#
add_custom_target(format-cpp-files
COMMAND find ${DIRS_TO_FORMAT_CPP} ${FIND_TO_FORMAT_CPP})
#
# Use clang-format-7 for code format
#
add_custom_target(format-cpp
COMMAND find ${DIRS_TO_FORMAT_CPP} ${FIND_TO_FORMAT_CPP} |
xargs -P ${CPU_COUNT} clang-format-7 -style=file -i)
#
# Use simple python script for fixing C like boxed comments
#
add_custom_target(format-cpp-fix-comments DEPENDS format-cpp
COMMAND find ${DIRS_TO_FORMAT_CPP} ${FIND_TO_FORMAT_CPP} |
xargs -L 1 -P ${CPU_COUNT}
python3 ${PROJECT_SOURCE_DIR}/dev/code_format_fixup.py --inplace --fix-comments --input)
#
# Use simple python script for fixing template brackets e.g. <<>
#
add_custom_target(format-cpp-fix-template-operators DEPENDS format-cpp
COMMAND find ${DIRS_TO_FORMAT_CPP} ${FIND_TO_FORMAT_CPP} |
xargs -L 1 -P ${CPU_COUNT}
python3 ${PROJECT_SOURCE_DIR}/dev/code_format_fixup.py --inplace --fix-template-operators --input)
add_custom_target(format DEPENDS format-cpp-fix-comments format-cpp-fix-template-operators)

View File

@ -0,0 +1,27 @@
# Support ccache for faster builds.
#
# By default ccache will be used if it is found in your path.
#
# You can use `BUILD_USING_CCACHE=off` to disable it's usage.
# You can use `BUILD_USING_CCACHE=off` to make sure ccache is used.
#
set(BUILD_USING_CCACHE "auto")
if(NOT "$ENV{BUILD_USING_CCACHE}" STREQUAL "")
set(BUILD_USING_CCACHE $ENV{BUILD_USING_CCACHE})
endif()
find_program(CCACHE_PROGRAM ccache)
if (BUILD_USING_CCACHE STREQUAL "on")
if(NOT CCACHE_PROGRAM)
message(FATAL_ERROR "BUILD_USING_CCACHE set to on but ccache binary not found!")
endif()
endif()
if (NOT BUILD_USING_CCACHE STREQUAL "off")
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
message(STATUS "Using ccache binary found @ ${CCACHE_PROGRAM}")
endif()
else()
if(CCACHE_PROGRAM)
message(STATUS "**Not** using ccache binary found @ ${CCACHE_PROGRAM} (as BUILD_USING_CCACHE is off)")
endif()
endif()