summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorEvan Lojewski <github@meklort.com>2020-11-08 09:12:44 -0700
committerGitHub <noreply@github.com>2020-11-08 09:12:44 -0700
commit3ae918c8115b0496b98a978ffe2a64bd2d078f64 (patch)
treeb17cfc3c8f668a5a25d89175e678fd0853058887 /cmake
parente86f52c7073e3ce983c5e7e93286eb9a73fd8ba8 (diff)
downloadbcm5719-ortega-3ae918c8115b0496b98a978ffe2a64bd2d078f64.tar.gz
bcm5719-ortega-3ae918c8115b0496b98a978ffe2a64bd2d078f64.zip
build: Enable linting checkes (#165)
* build: Enable linting with wrapper. * build: Disable lint errors on libs/Network and stage1 until fixed.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/arm.cmake7
-rw-r--r--cmake/config.cmake3
-rw-r--r--cmake/lint-dummy.c0
-rw-r--r--cmake/lint.cmake90
-rw-r--r--cmake/mips.cmake12
5 files changed, 105 insertions, 7 deletions
diff --git a/cmake/arm.cmake b/cmake/arm.cmake
index 0d20e27..b01a78f 100644
--- a/cmake/arm.cmake
+++ b/cmake/arm.cmake
@@ -42,7 +42,7 @@
### @endcond
################################################################################
-SET(ARM_COMPILE_OPTIONS -nostdlib -nodefaultlibs
+SET(ARM_COMPILE_OPTIONS "-DLINT_FILE=clang-arm" -nostdlib -nodefaultlibs
-fomit-frame-pointer
-fno-builtin
-include "${CMAKE_SOURCE_DIR}/include/banned.h"
@@ -56,6 +56,10 @@ SET(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -x assembler-with-cpp <DEFINE
SET(CMAKE_arm_LINK_EXECUTABLE "${COMPILER_BASE}/bin/ld.lld <OBJECTS> <LINK_LIBRARIES> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> -Bstatic -o <TARGET>")
+SET(ARM_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+generate_lint_config("${ARM_COMPILE_OPTIONS}" ${CMAKE_BINARY_DIR}/.clang-arm.lnt ${CMAKE_BINARY_DIR}/.clang-arm.h)
+
# ARM-specific executables
function(arm_add_executable target)
add_executable(${target} ${ARGN})
@@ -87,6 +91,7 @@ function(arm_add_library target)
add_library(${target} ${ARGN})
target_compile_options(${target} PRIVATE ${ARM_COMPILE_OPTIONS})
+ set_target_properties(${target} PROPERTIES LINT_CONFIG ${CMAKE_BINARY_DIR}/clang-arm.lnt)
endfunction(arm_add_library)
function(arm_linker_script target script)
diff --git a/cmake/config.cmake b/cmake/config.cmake
index b22048c..afc903f 100644
--- a/cmake/config.cmake
+++ b/cmake/config.cmake
@@ -49,6 +49,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -O3 -ffunction-sections -fda
SET(CMAKE_C_IMPLICIT_LINK_LIBRARIES "")
SET(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
+# Rules for linting support
+include(${CMAKE_CURRENT_LIST_DIR}/lint.cmake)
+
# Settings and build rules for simulator targets
include(${CMAKE_CURRENT_LIST_DIR}/simulator.cmake)
diff --git a/cmake/lint-dummy.c b/cmake/lint-dummy.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cmake/lint-dummy.c
diff --git a/cmake/lint.cmake b/cmake/lint.cmake
new file mode 100644
index 0000000..6507a35
--- /dev/null
+++ b/cmake/lint.cmake
@@ -0,0 +1,90 @@
+################################################################################
+###
+### @file lint.cmake
+###
+### @project
+###
+### @brief Lint specific support routines
+###
+################################################################################
+###
+################################################################################
+###
+### @copyright Copyright (c) 2018-2020, Evan Lojewski
+### @cond
+###
+### All rights reserved.
+###
+### Redistribution and use in source and binary forms, with or without
+### modification, are permitted provided that the following conditions are met:
+### 1. Redistributions of source code must retain the above copyright notice,
+### this list of conditions and the following disclaimer.
+### 2. Redistributions in binary form must reproduce the above copyright notice,
+### this list of conditions and the following disclaimer in the documentation
+### and/or other materials provided with the distribution.
+### 3. Neither the name of the copyright holder nor the
+### names of its contributors may be used to endorse or promote products
+### derived from this software without specific prior written permission.
+###
+################################################################################
+###
+### THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+### AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+### IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+### ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+### LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+### CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+### SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+### INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+### CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+### ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+### POSSIBILITY OF SUCH DAMAGE.
+### @endcond
+################################################################################
+
+SET(LINT_DUMMY ${CMAKE_CURRENT_LIST_DIR}/lint-dummy.c)
+
+FUNCTION(generate_lint_config COMPILER_OPTIONS OUTPUT_LNT OUTPUT_H)
+ MESSAGE(STATUS "Generating ${OUTPUT_LNT}")
+ execute_process(
+ COMMAND "${CMAKE_C_COMPILER}" -DNO_FLINT ${COMPILER_OPTIONS} -dM -E "${LINT_DUMMY}"
+ OUTPUT_VARIABLE DEFINES
+ )
+
+ configure_file(".clang.h.in" ${OUTPUT_H})
+
+ execute_process(
+ COMMAND "${CMAKE_C_COMPILER}" -DNO_FLINT ${ARM_COMPILE_OPTIONS} -v "${LINT_DUMMY}"
+ ERROR_VARIABLE VERBOSE_OUT
+ ERROR_STRIP_TRAILING_WHITESPACE
+ )
+ STRING(REPLACE "\n" ";" VERBOSE_OUT "${VERBOSE_OUT}")
+ SET(SYSTEM_INCLUDES )
+ SET(ADD_INCLUDES False)
+
+ FOREACH(line IN LISTS VERBOSE_OUT)
+ IF("${line}" STREQUAL "End of search list.")
+ # End of list
+ break()
+ ENDIF()
+
+ IF(ADD_INCLUDES)
+ STRING(STRIP "${line}" line)
+ LIST(APPEND SYSTEM_INCLUDES ${line})
+ ENDIF()
+
+ IF("${line}" STREQUAL "#include <...> search starts here:")
+ # Beginning of list.
+ SET(ADD_INCLUDES True)
+ ENDIF()
+ ENDFOREACH()
+
+ SET(INCLUDES )
+ FOREACH(include IN LISTS SYSTEM_INCLUDES)
+ LIST(APPEND INCLUDES "+libdir(${include})")
+ LIST(APPEND INCLUDES "--i${include}")
+ ENDFOREACH()
+ STRING(REPLACE ";" "\n" INCLUDES "${INCLUDES}")
+
+ configure_file(".clang.lnt.in" ${OUTPUT_LNT})
+ENDFUNCTION()
diff --git a/cmake/mips.cmake b/cmake/mips.cmake
index 17c2f7b..014be4d 100644
--- a/cmake/mips.cmake
+++ b/cmake/mips.cmake
@@ -42,12 +42,10 @@
### @endcond
################################################################################
-SET(MIPS_COMPILE_OPTIONS
- -nostdlib -nodefaultlibs
- $<$<NOT:$<COMPILE_LANGUAGE:ASM>>:-fomit-frame-pointer> # Don't include for ASM sources
- -target mips -mcpu=mips2
- $<$<NOT:$<COMPILE_LANGUAGE:ASM>>:-include "${CMAKE_SOURCE_DIR}/include/banned.h">
-)
+SET(MIPS_COMPILE_OPTIONS "-DLINT_FILE=clang-mips" -nostdlib -nodefaultlibs
+ -fomit-frame-pointer
+ -include "${CMAKE_SOURCE_DIR}/include/banned.h"
+ -target mips -mcpu=mips2)
SET(MIPS_LINK_OPTIONS --gc-sections)
# SET(CMAKE_EXE_LINKER_FLAGS -static)
@@ -57,6 +55,8 @@ SET(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -x assembler-with-cpp <DEFINE
SET(CMAKE_mips_LINK_EXECUTABLE "${COMPILER_BASE}/bin/ld.lld <OBJECTS> <LINK_LIBRARIES> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> -Bstatic -o <TARGET>")
+generate_lint_config("${MIPS_COMPILE_OPTIONS}" ${CMAKE_BINARY_DIR}/.clang-mips.lnt ${CMAKE_BINARY_DIR}/.clang-mips.h)
+
# MIPS-specific executables
function(mips_add_executable target)
add_executable(${target} ${ARGN})
OpenPOWER on IntegriCloud