cmake: tidy-ups

- tidy-up comments.
- use lowercase, underscore prefixed names for internal variables.
- use `IN LISTS` and `IN ITEMS` in `foreach()` loops.
- rename variable name `OUTPUT` to a more distinctive one.
- tidy-up `STREQUAL` syntax.
- delete commented code.
- indent/whitespace.

Closes #14197
This commit is contained in:
Viktor Szakats 2024-07-12 21:10:57 +02:00
parent b64d9d7d81
commit acbc6b703f
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
26 changed files with 401 additions and 487 deletions

View file

@ -33,11 +33,11 @@ function(add_runtests targetname test_flags)
# replaced by the contents of the environment variable in runtests.pl.
# This is a workaround for CMake's limitation where commands executed by
# 'make' or 'ninja' cannot portably reference environment variables.
string(REPLACE " " ";" test_flags_list "${test_flags}")
string(REPLACE " " ";" _test_flags_list "${test_flags}")
add_custom_target(${targetname}
COMMAND
"${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/runtests.pl"
${test_flags_list}
${_test_flags_list}
"\$TFLAGS"
DEPENDS testdeps
VERBATIM USES_TERMINAL
@ -86,7 +86,7 @@ use vars qw(
add_runtests(test-quiet "-a -s")
add_runtests(test-am "-a -am")
add_runtests(test-full "-a -p -r")
# ~flaky means that it'll ignore results of tests using the flaky keyword
# ~flaky means that it ignores results of tests using the flaky keyword
add_runtests(test-nonflaky "-a -p ~flaky ~timing-dependent")
add_runtests(test-ci "-a -p ~flaky ~timing-dependent -r -rm -j2")
add_runtests(test-torture "-a -t")

View file

@ -23,49 +23,49 @@
###########################################################################
set(TARGET_LABEL_PREFIX "Test ")
function(setup_test TEST_NAME) # ARGN are the files in the test
function(setup_test test_name) # ARGN are the files in the test
if(LIB_SELECTED STREQUAL LIB_STATIC)
# These are part of the libcurl static lib. Do not compile/link them again.
list(REMOVE_ITEM ARGN ${WARNLESS} ${MULTIBYTE} ${TIMEDIFF})
endif()
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${ARGN})
add_dependencies(testdeps ${TEST_NAME})
string(TOUPPER ${TEST_NAME} UPPER_TEST_NAME)
add_executable(${test_name} EXCLUDE_FROM_ALL ${ARGN})
add_dependencies(testdeps ${test_name})
string(TOUPPER ${test_name} UPPER_TEST_NAME)
include_directories(
${CURL_SOURCE_DIR}/lib # for "curl_setup_once.h"
${CURL_BINARY_DIR}/lib # for "curl_config.h"
${CURL_BINARY_DIR}/include # for "curl/curl.h"
${CURL_SOURCE_DIR}/tests/libtest # to be able to build generated tests
)
)
if(USE_ARES)
include_directories(${CARES_INCLUDE_DIR})
endif()
target_link_libraries(${TEST_NAME} ${LIB_SELECTED} ${CURL_LIBS})
target_link_libraries(${test_name} ${LIB_SELECTED} ${CURL_LIBS})
set_target_properties(${TEST_NAME}
set_target_properties(${test_name}
PROPERTIES COMPILE_DEFINITIONS ${UPPER_TEST_NAME})
set_target_properties(${TEST_NAME}
PROPERTIES PROJECT_LABEL "${TARGET_LABEL_PREFIX}${TEST_NAME}")
set_target_properties(${test_name}
PROPERTIES PROJECT_LABEL "${TARGET_LABEL_PREFIX}${test_name}")
endfunction()
# Get 'noinst_PROGRAMS', '*_SOURCES' variables
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
foreach(TEST_NAME ${noinst_PROGRAMS})
if(DEFINED ${TEST_NAME}_SOURCES)
setup_test(${TEST_NAME} ${${TEST_NAME}_SOURCES})
foreach(_test_name IN LISTS noinst_PROGRAMS)
if(DEFINED ${_test_name}_SOURCES)
setup_test(${_test_name} ${${_test_name}_SOURCES})
else()
setup_test(${TEST_NAME} ${nodist_${TEST_NAME}_SOURCES})
setup_test(${_test_name} ${nodist_${_test_name}_SOURCES})
endif()
endforeach()
# Allows for hostname override to make tests machine independent.
# TODO this cmake build assumes a shared build, detect static linking here!
# TODO: this cmake build assumes a shared build, detect static linking here!
if(NOT WIN32)
add_library(hostname MODULE EXCLUDE_FROM_ALL sethostname.c)
add_dependencies(testdeps hostname)

View file

@ -27,55 +27,39 @@ if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4306")
endif()
function(SETUP_EXECUTABLE TEST_NAME) # ARGN are the files in the test
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${ARGN})
add_dependencies(testdeps ${TEST_NAME})
function(setup_executable test_name) # ARGN are the files in the test
add_executable(${test_name} EXCLUDE_FROM_ALL ${ARGN})
add_dependencies(testdeps ${test_name})
include_directories(
${CURL_SOURCE_DIR}/lib # for "curl_setup_once.h"
${CURL_BINARY_DIR}/lib # for "curl_config.h"
${CURL_BINARY_DIR}/include # for "curl/curl.h"
${CURL_SOURCE_DIR}/src # for "tool_xattr.h"
)
)
if(USE_ARES)
include_directories(${CARES_INCLUDE_DIR})
endif()
target_link_libraries(${TEST_NAME} ${CURL_LIBS})
target_link_libraries(${test_name} ${CURL_LIBS})
# Test servers simply are standalone programs that do not use libcurl
# library. For convenience and to ease portability of these servers,
# some source code files from the libcurl subdirectory are also used
# to build the servers. In order to achieve proper linkage of these
# files on Win32 targets it is necessary to build the test servers
# files on Windows targets it is necessary to build the test servers
# with CURL_STATICLIB defined, independently of how libcurl is built.
set_target_properties(${TEST_NAME} PROPERTIES
set_target_properties(${test_name} PROPERTIES
COMPILE_DEFINITIONS CURL_STATICLIB)
set_target_properties(${TEST_NAME} PROPERTIES
PROJECT_LABEL "${TARGET_LABEL_PREFIX}${TEST_NAME}")
set_target_properties(${test_name} PROPERTIES
PROJECT_LABEL "${TARGET_LABEL_PREFIX}${test_name}")
endfunction()
# Get 'noinst_PROGRAMS', '<target>_SOURCES' variables
transform_makefile_inc("Makefile.inc"
"${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
foreach(EXECUTABLE_NAME ${noinst_PROGRAMS})
setup_executable(${EXECUTABLE_NAME} ${${EXECUTABLE_NAME}_SOURCES})
foreach(_executable_name IN LISTS noinst_PROGRAMS)
setup_executable(${_executable_name} ${${_executable_name}_SOURCES})
endforeach()
# set(useful
# getpart.c getpart.h
# ${CURL_SOURCE_DIR}/lib/strequal.c
# ${CURL_SOURCE_DIR}/lib/base64.c
# ${CURL_SOURCE_DIR}/lib/mprintf.c
# ${CURL_SOURCE_DIR}/lib/memdebug.c
# ${CURL_SOURCE_DIR}/lib/timeval.c
# )
# setup_executable(sws sws.c util.c util.h ${useful})
# setup_executable(resolve resolve.c util.c util.h ${useful})
# setup_executable(sockfilt sockfilt.c util.c util.h ${useful} ${CURL_SOURCE_DIR}/lib/inet_pton.c)
# setup_executable(getpart testpart.c ${useful})
# setup_executable(tftpd tftpd.c util.c util.h ${useful} tftp.h)

View file

@ -22,6 +22,7 @@
#
###########################################################################
# Get 'UNITPROGS', 'UNITFILES' variables
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
@ -33,7 +34,7 @@ include_directories(
${CURL_BINARY_DIR}/include # for "curl/curl.h"
)
foreach(_testfile ${UNITPROGS})
foreach(_testfile IN LISTS UNITPROGS)
add_executable(${_testfile} EXCLUDE_FROM_ALL ${_testfile}.c ${UNITFILES})
add_dependencies(testdeps ${_testfile})
target_link_libraries(${_testfile} curltool curlu)