diff --git a/CMakeLists.txt b/CMakeLists.txt index b8e58472ff..66c8b35327 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,9 @@ foreach(dir examples include source test tools) endforeach() file(GLOB_RECURSE format_src ${format_glob}) +# check for licence +VerifyLicence(${format_src}) + # Add code formatter target add_custom_target(cppformat) diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake index f355592370..e647576e88 100644 --- a/cmake/helpers.cmake +++ b/cmake/helpers.cmake @@ -128,3 +128,14 @@ function(FetchContentSparse_Declare name GIT_REPOSITORY GIT_TAG GIT_DIR) WORKING_DIRECTORY ${content-build-dir}) FetchContent_Declare(${name} SOURCE_DIR ${content-build-dir}/${GIT_DIR}) endfunction() + + +# Checks that every input file includes an appropriate license notice. +function(VerifyLicence) + foreach(file ${ARGN}) + file(READ ${file} file_contents LIMIT 300) + if(NOT "${file_contents}" MATCHES "SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception") + message(FATAL_ERROR "${file} does not contain an appropriate license comment.") + endif() + endforeach() +endfunction()