cmake: sync code between test/example targets

- reuse local variable names.
- sync `PROJECT_LABEL`, add where missing.
- namespace all target names.
- bind header directories to each target.
- tests/server: limit `CURL_STATICLIB` to Windows (as in autotools.)
- drop functions with a single caller.

Closes #14660
This commit is contained in:
Viktor Szakats 2024-08-22 09:10:07 +02:00
parent f73f6bf9f8
commit a2ef5d36b3
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
5 changed files with 80 additions and 79 deletions

View file

@ -26,18 +26,19 @@
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
foreach(_example IN LISTS check_PROGRAMS)
set(_example_target "curl-example-${_example}")
add_executable(${_example_target} "${_example}.c")
target_link_libraries(${_example_target} ${LIB_SELECTED} ${CURL_LIBS})
target_compile_definitions(${_example_target} PRIVATE "CURL_NO_OLDIES")
foreach(_target IN LISTS check_PROGRAMS)
set(_target_name "curl-example-${_target}")
add_executable(${_target_name} "${_target}.c")
target_link_libraries(${_target_name} ${LIB_SELECTED} ${CURL_LIBS})
target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES")
if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32)
set_property(TARGET ${_example_target} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
endif()
if(MINGW)
# For mingw-w64 7.0.0 and earlier to avoid '-Wformat='
set_property(TARGET ${_example_target} APPEND PROPERTY COMPILE_DEFINITIONS "__USE_MINGW_ANSI_STDIO=1")
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "__USE_MINGW_ANSI_STDIO=1")
endif()
set_target_properties(${_example_target} PROPERTIES
OUTPUT_NAME "${_example}" UNITY_BUILD OFF)
set_target_properties(${_target_name} PROPERTIES
OUTPUT_NAME "${_target}" UNITY_BUILD OFF
PROJECT_LABEL "Example ${_target}")
endforeach()