file(GLOB_RECURSE PROJECT_C_SOURCES "${SOURCE_DIR}/src/*.c" "${SOURCE_DIR}/src/*.h" ) foreach(source IN LISTS PROJECT_C_SOURCES) file(READ "${source}" contents) if(contents MATCHES "(^|[^A-Za-z0-9_])goto([^A-Za-z0-9_]|$)") message(FATAL_ERROR "goto is forbidden in project source: ${source}") endif() if(contents MATCHES "#define[ \t]+static" OR contents MATCHES "#include[ \t]+\"[^\"]+\\.c\"") message(FATAL_ERROR "test-only source visibility hack found: ${source}") endif() string(FIND "${source}" "/src/sys/" sys_position) if(sys_position EQUAL -1 AND contents MATCHES "windows\\.h|GetFullPathNameW|CreateFileW|ReadFile|WriteFile|MoveFileExW|BCryptGenRandom") message(FATAL_ERROR "OS-specific API reference outside src/sys: ${source}") endif() endforeach() if(NOT CLANG_FORMAT_EXECUTABLE STREQUAL "") execute_process( COMMAND "${CLANG_FORMAT_EXECUTABLE}" --dry-run --Werror ${PROJECT_C_SOURCES} RESULT_VARIABLE format_result OUTPUT_VARIABLE format_output ERROR_VARIABLE format_error ) if(NOT format_result EQUAL 0) message(FATAL_ERROR "clang-format check failed:\n${format_output}${format_error}") endif() endif() execute_process( COMMAND "${GIT_EXECUTABLE}" diff --check WORKING_DIRECTORY "${SOURCE_DIR}" RESULT_VARIABLE diff_result OUTPUT_VARIABLE diff_output ERROR_VARIABLE diff_error ) if(NOT diff_result EQUAL 0) message(FATAL_ERROR "git diff --check failed:\n${diff_output}${diff_error}") endif()