From: Viktor Szakats Date: Tue, 10 Jun 2025 16:25:57 +0000 (+0200) Subject: cmake: replace `cmakelint` with `cmake-lint` from `cmakelang`, fix issues X-Git-Tag: curl-8_15_0~296 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b761eb5addb9e29b2ee0e5841633c09d1fd77704;p=thirdparty%2Fcurl.git cmake: replace `cmakelint` with `cmake-lint` from `cmakelang`, fix issues This linter detects formatting and naming issues with minimal amount of noise. It seems to be an improvement over the existing linter which was only detecting line width overruns. Also: fix to exclude `CurlTests.c` from linter. Ref: https://cmake-format.readthedocs.io/en/latest/cmake-lint.html Ref: https://github.com/cheshirekow/cmake_format Closes #17576 --- diff --git a/.github/workflows/checksrc.yml b/.github/workflows/checksrc.yml index 63ea8b9806..c8535e7b8e 100644 --- a/.github/workflows/checksrc.yml +++ b/.github/workflows/checksrc.yml @@ -63,7 +63,7 @@ jobs: python3-toml python3-markupsafe python3-jinja2 python3-tabulate \ python3-typing-extensions python3-libcst python3-impacket \ python3-websockets python3-pytest python3-filelock python3-pytest-xdist - python3 -m pip install --break-system-packages cmakelint==1.4.3 pytype==2024.10.11 ruff==0.11.9 + python3 -m pip install --break-system-packages cmakelang==0.6.13 pytype==2024.10.11 ruff==0.11.9 - name: spellcheck run: | diff --git a/CMake/FindGSS.cmake b/CMake/FindGSS.cmake index c1802ee740..11206b0f93 100644 --- a/CMake/FindGSS.cmake +++ b/CMake/FindGSS.cmake @@ -58,6 +58,7 @@ if(NOT GSS_ROOT_DIR AND NOT "$ENV{GSS_ROOT_DIR}") find_package(PkgConfig QUIET) pkg_search_module(_GSS ${_gnu_modname} ${_mit_modname} ${_heimdal_modname}) list(APPEND _gss_root_hints "${_GSS_PREFIX}") + set(_gss_version "${_GSS_VERSION}") endif() if(WIN32) list(APPEND _gss_root_hints "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos;InstallDir]") @@ -135,14 +136,14 @@ if(NOT _GSS_FOUND) # Not found by pkg-config. Let us take more traditional appr execute_process( COMMAND ${_gss_configure_script} "--version" - OUTPUT_VARIABLE _GSS_VERSION + OUTPUT_VARIABLE _gss_version RESULT_VARIABLE _gss_configure_failed OUTPUT_STRIP_TRAILING_WHITESPACE ) # Older versions may not have the "--version" parameter. In this case we just do not care. if(_gss_configure_failed) - set(_GSS_VERSION 0) + set(_gss_version 0) endif() execute_process( @@ -269,23 +270,23 @@ else() if(_GSS_MODULE_NAME STREQUAL _gnu_modname OR _GSS_${_gnu_modname}_VERSION) set(GSS_FLAVOUR "GNU") set(GSS_PC_REQUIRES "gss") - if(NOT _GSS_VERSION) # for old CMake versions? - set(_GSS_VERSION ${_GSS_${_gnu_modname}_VERSION}) + if(NOT _gss_version) # for old CMake versions? + set(_gss_version ${_GSS_${_gnu_modname}_VERSION}) endif() elseif(_GSS_MODULE_NAME STREQUAL _mit_modname OR _GSS_${_mit_modname}_VERSION) set(GSS_FLAVOUR "MIT") set(GSS_PC_REQUIRES "mit-krb5-gssapi") - if(NOT _GSS_VERSION) # for old CMake versions? - set(_GSS_VERSION ${_GSS_${_mit_modname}_VERSION}) + if(NOT _gss_version) # for old CMake versions? + set(_gss_version ${_GSS_${_mit_modname}_VERSION}) endif() else() set(GSS_FLAVOUR "Heimdal") set(GSS_PC_REQUIRES "heimdal-gssapi") - if(NOT _GSS_VERSION) # for old CMake versions? - set(_GSS_VERSION ${_GSS_${_heimdal_modname}_VERSION}) + if(NOT _gss_version) # for old CMake versions? + set(_gss_version ${_GSS_${_heimdal_modname}_VERSION}) endif() endif() - message(STATUS "Found GSS/${GSS_FLAVOUR} (via pkg-config): ${_GSS_INCLUDE_DIRS} (found version \"${_GSS_VERSION}\")") + message(STATUS "Found GSS/${GSS_FLAVOUR} (via pkg-config): ${_GSS_INCLUDE_DIRS} (found version \"${_gss_version}\")") endif() string(REPLACE ";" " " _GSS_CFLAGS "${_GSS_CFLAGS}") @@ -294,7 +295,7 @@ set(GSS_INCLUDE_DIRS ${_GSS_INCLUDE_DIRS}) set(GSS_LIBRARIES ${_GSS_LIBRARIES}) set(GSS_LIBRARY_DIRS ${_GSS_LIBRARY_DIRS}) set(GSS_CFLAGS ${_GSS_CFLAGS}) -set(GSS_VERSION ${_GSS_VERSION}) +set(GSS_VERSION ${_gss_version}) if(GSS_FLAVOUR) if(NOT GSS_VERSION AND GSS_FLAVOUR STREQUAL "Heimdal") @@ -353,5 +354,5 @@ mark_as_advanced( _GSS_LIBRARY_DIRS _GSS_MODULE_NAME _GSS_PREFIX - _GSS_VERSION + _gss_version ) diff --git a/CMake/FindLibgsasl.cmake b/CMake/FindLibgsasl.cmake index c726ce1a49..878d651883 100644 --- a/CMake/FindLibgsasl.cmake +++ b/CMake/FindLibgsasl.cmake @@ -66,12 +66,12 @@ else() endif() include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(Libgsasl - REQUIRED_VARS - LIBGSASL_INCLUDE_DIR - LIBGSASL_LIBRARY - VERSION_VAR - LIBGSASL_VERSION + find_package_handle_standard_args(Libgsasl + REQUIRED_VARS + LIBGSASL_INCLUDE_DIR + LIBGSASL_LIBRARY + VERSION_VAR + LIBGSASL_VERSION ) if(LIBGSASL_FOUND) diff --git a/CMake/Macros.cmake b/CMake/Macros.cmake index e3a654b5f3..dfc0a95d93 100644 --- a/CMake/Macros.cmake +++ b/CMake/Macros.cmake @@ -65,6 +65,7 @@ macro(curl_internal_test _curl_test) endif() endmacro() +# Option for dependencies that accepts an 'AUTO' value, which enables the dependency if detected. macro(curl_dependency_option _option_name _find_name _desc_name) set(${_option_name} "AUTO" CACHE STRING "Build curl with ${_desc_name} support (AUTO, ON or OFF)") set_property(CACHE ${_option_name} PROPERTY STRINGS "AUTO" "ON" "OFF") diff --git a/CMake/OtherTests.cmake b/CMake/OtherTests.cmake index 26e9d821c2..0ccda61de6 100644 --- a/CMake/OtherTests.cmake +++ b/CMake/OtherTests.cmake @@ -25,6 +25,7 @@ include(CheckCSourceCompiles) include(CheckCSourceRuns) include(CheckTypeSize) +# #include header if condition is true macro(curl_add_header_include _check _header) if(${_check}) set(_source_epilogue "${_source_epilogue} diff --git a/CMake/PickyWarnings.cmake b/CMake/PickyWarnings.cmake index be26d05cb8..7838f6f8ba 100644 --- a/CMake/PickyWarnings.cmake +++ b/CMake/PickyWarnings.cmake @@ -316,8 +316,9 @@ if(PICKY_COMPILER) list(APPEND _picky "-wd4668") # 'M' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' (in winbase.h) list(APPEND _picky "-wd4710") # 'snprintf': function not inlined list(APPEND _picky "-wd4711") # function 'A' selected for automatic inline expansion - list(APPEND _picky "-wd4746") # volatile access of '' is subject to /volatile: setting; - # consider using __iso_volatile_load/store intrinsic functions (ARM64) + # volatile access of '' is subject to /volatile: setting; + # consider using __iso_volatile_load/store intrinsic functions (ARM64) + list(APPEND _picky "-wd4746") list(APPEND _picky "-wd4774") # 'snprintf': format string expected in argument 3 is not a string literal list(APPEND _picky "-wd4820") # 'A': 'N' bytes padding added after data member 'B' if(MSVC_VERSION GREATER_EQUAL 1900) @@ -340,7 +341,7 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND MSVC) list(APPEND _picky_tmp "-clang:${_ccopt}") endif() endforeach() - set("${_wlist}" ${_picky_tmp}) + set("${_wlist}" ${_picky_tmp}) # cmake-lint: disable=C0103 endforeach() endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index e8abce38d2..c1584cb13e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -520,7 +520,7 @@ if(PERL_EXECUTABLE) DEPENDS "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl" ) add_custom_target(curl-ca-firefox - COMMENT "generating a fresh ca-bundle.crt" VERBATIM USES_TERMINAL + COMMENT "Generating a fresh ca-bundle.crt" VERBATIM USES_TERMINAL COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh" "lib/ca-bundle.crt" DEPENDS "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh" ) @@ -1735,7 +1735,7 @@ foreach(_variable IN ITEMS HAVE_SYS_SOCKET_H HAVE_SYS_TYPES_H HAVE_UNISTD_H - ) +) if(${_variable}) string(APPEND CURL_TEST_DEFINES " -D${_variable}") endif() @@ -1900,7 +1900,7 @@ foreach(_curl_test IN ITEMS HAVE_BOOL_T STDC_HEADERS HAVE_ATOMIC - ) +) curl_internal_test(${_curl_test}) endforeach() @@ -2062,6 +2062,7 @@ endif() # (= regenerate it). function(curl_transform_makefile_inc _input_file _output_file) file(READ ${_input_file} _makefile_inc_text) + # cmake-lint: disable=W0106 string(REPLACE "$(top_srcdir)" "\${PROJECT_SOURCE_DIR}" _makefile_inc_text ${_makefile_inc_text}) string(REPLACE "$(top_builddir)" "\${PROJECT_BINARY_DIR}" _makefile_inc_text ${_makefile_inc_text}) diff --git a/docs/libcurl/CMakeLists.txt b/docs/libcurl/CMakeLists.txt index 53203647aa..56992da0de 100644 --- a/docs/libcurl/CMakeLists.txt +++ b/docs/libcurl/CMakeLists.txt @@ -25,6 +25,7 @@ curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") +# Generate man pages function(curl_add_manual_pages _listname) # Maximum number of files per command to stay within shell/OS limits if(CMAKE_HOST_UNIX) @@ -78,8 +79,8 @@ curl_add_manual_pages(man_MANS) add_custom_target(curl-man ALL DEPENDS ${man_MANS}) if(NOT CURL_DISABLE_INSTALL) set(_src "") - foreach(_f IN LISTS man_MANS) - list(APPEND _src "${CMAKE_CURRENT_BINARY_DIR}/${_f}") + foreach(_file IN LISTS man_MANS) + list(APPEND _src "${CMAKE_CURRENT_BINARY_DIR}/${_file}") endforeach() install(FILES ${_src} DESTINATION "${CMAKE_INSTALL_MANDIR}/man3") unset(_src) diff --git a/docs/libcurl/opts/CMakeLists.txt b/docs/libcurl/opts/CMakeLists.txt index 9e4523c1d4..f7632c49d5 100644 --- a/docs/libcurl/opts/CMakeLists.txt +++ b/docs/libcurl/opts/CMakeLists.txt @@ -30,8 +30,8 @@ add_custom_target(curl-opts-man DEPENDS ${man_MANS}) add_dependencies(curl-man curl-opts-man) if(NOT CURL_DISABLE_INSTALL) set(_src "") - foreach(_f IN LISTS man_MANS) - list(APPEND _src "${CMAKE_CURRENT_BINARY_DIR}/${_f}") + foreach(_file IN LISTS man_MANS) + list(APPEND _src "${CMAKE_CURRENT_BINARY_DIR}/${_file}") endforeach() install(FILES ${_src} DESTINATION "${CMAKE_INSTALL_MANDIR}/man3") endif() diff --git a/scripts/cmakelint.sh b/scripts/cmakelint.sh index 4d28fd45e9..5c5fc7040f 100755 --- a/scripts/cmakelint.sh +++ b/scripts/cmakelint.sh @@ -6,7 +6,7 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# Copyright (C) Dan Fandrich, , et al. +# Copyright (C) Dan Fandrich, , Viktor Szakats, et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms @@ -23,12 +23,16 @@ # ########################################################################### +# https://cmake-format.readthedocs.io/en/latest/cmake-lint.html +# https://cmake-format.readthedocs.io/en/latest/lint-usage.html +# https://github.com/cheshirekow/cmake_format/blob/master/cmakelang/configuration.py + # Run cmakelint on the curl source code. It will check all files given on the # command-line, or else all relevant files in git, or if not in a git # repository, all files starting in the tree rooted in the current directory. # -# cmakelint can be installed from PyPi with the command "python3 -m pip install -# cmakelint". +# cmake-lint can be installed from PyPi with the command "python3 -m pip +# install cmakelang". # # The xargs invocation is portable, but does not preserve spaces in file names. # If such a file is ever added, then this can be portably fixed by switching to @@ -43,8 +47,29 @@ # strip off the leading ./ to make the grep regexes work properly find . -type f | sed 's@^\./@@' fi -} | grep -E '(^CMake|/CMake|\.cmake$)' | grep -v -E '(\.h\.cmake|\.in)$' \ +} | grep -E '(^CMake|/CMake|\.cmake$)' | grep -v -E '(\.h\.cmake|\.in|\.c)$' \ | xargs \ - cmakelint \ - --spaces=2 --linelength=132 \ - --filter=-whitespace/indent,-convention/filename,-package/stdargs,-readability/wonkycase + cmake-lint \ + --suppress-decorations \ + --disable \ + --line-width 132 \ + --tab-size 2 \ + --use-tabchars false \ + --disabled-codes C0113 \ + --function-pattern 'curl_[0-9a-z_]+' \ + --macro-pattern '(curl_[0-9a-z_]+|check_include_file_concat_curl)' \ + --global-var-pattern '[A-Z][0-9A-Z_]+' \ + --internal-var-pattern '_[a-z][0-9a-z_]+' \ + --local-var-pattern '_[a-z][0-9a-z_]+' \ + --private-var-pattern '_[0-9a-z_]+' \ + --public-var-pattern '([A-Z][0-9A-Z_]+|[A-Z][A-Za-z0-9]+_FOUND|[a-z]+_SOURCES|prefix|exec_prefix|includedir|libdir|ssize_t|_FILE_OFFSET_BITS)' \ + --argument-var-pattern '_[a-z][0-9a-z_]+' \ + --keyword-pattern '[A-Z][0-9A-Z_]+' \ + --max-conditionals-custom-parser 2 \ + --min-statement-spacing 1 \ + --max-statement-spacing 2 \ + --max-returns 6 \ + --max-branches 12 \ + --max-arguments 5 \ + --max-localvars 15 \ + --max-statements 50 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d04d3de4c2..0c3474cc38 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -42,6 +42,7 @@ add_subdirectory(tunit) add_subdirectory(unit) add_subdirectory(certs) +# Add a runtests target with customized flags function(curl_add_runtests _targetname _test_flags) if(NOT BUILD_LIBCURL_DOCS) string(APPEND _test_flags " !documentation") @@ -68,6 +69,7 @@ function(curl_add_runtests _targetname _test_flags) ) endfunction() +# Add a pytests target with customized flags function(curl_add_pytests _targetname _test_flags) set(_depends "") if(NOT _targetname STREQUAL "pytest-ci") diff --git a/tests/cmake/CMakeLists.txt b/tests/cmake/CMakeLists.txt index d752023464..d40a6b25d9 100644 --- a/tests/cmake/CMakeLists.txt +++ b/tests/cmake/CMakeLists.txt @@ -47,15 +47,15 @@ if(TEST_INTEGRATION_MODE STREQUAL "find_package" OR TEST_INTEGRATION_MODE STREQUAL "ExternalProject") find_package(CURL REQUIRED CONFIG) find_package(CURL REQUIRED CONFIG) # Double-inclusion test - foreach(result_var IN ITEMS + foreach(_result_var IN ITEMS CURL_FOUND CURL_SUPPORTS_HTTPS CURL_SUPPORTS_Largefile CURL_VERSION CURL_VERSION_STRING - ) - if(NOT ${result_var}) - message(FATAL_ERROR "'${result_var}' variable expected, but not set by the CURL package.") + ) + if(NOT ${_result_var}) + message(FATAL_ERROR "'${_result_var}' variable expected, but not set by the CURL package.") endif() endforeach() # Show variables set by find_package()