cmake: add fast example build-only target

This commit is contained in:
Viktor Szakats 2025-08-06 22:17:50 +02:00
parent 869506d2da
commit 70b0451338
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201

View file

@ -28,12 +28,27 @@ add_custom_target(curl-examples)
curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
foreach(_target IN LISTS check_PROGRAMS)
set(_all "all")
foreach(_target IN LISTS check_PROGRAMS _all)
set(_target_name "curl-example-${_target}")
add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c")
add_dependencies(curl-examples ${_target_name})
if(_target STREQUAL "all")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
set(_example_c "${check_PROGRAMS}")
list(TRANSFORM _example_c APPEND ".c")
add_library(${_target_name} OBJECT EXCLUDE_FROM_ALL ${_example_c})
message(STATUS "|${_example_c}|")
endif()
else()
set(_onetest ${_target_name}) # ends with a single, existing test for curl-examples-build target
add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c")
add_dependencies(curl-examples ${_target_name})
endif()
target_link_libraries(${_target_name} ${LIB_SELECTED} ${CURL_NETWORK_AND_TIME_LIBS})
target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES"
"$<$<BOOL:${WIN32}>:WIN32_LEAN_AND_MEAN>" "$<$<BOOL:${MSVC}>:_CRT_SECURE_NO_DEPRECATE>")
set_target_properties(${_target_name} PROPERTIES OUTPUT_NAME "${_target}" PROJECT_LABEL "Example ${_target}" UNITY_BUILD OFF)
endforeach()
# Special target to compile all tests quickly and build a single test to probe linkage
add_custom_target(curl-examples-build)
add_dependencies(curl-examples-build curl-example-all "${_onetest}")