curl-curl/CMake
Viktor Szakats 6828df7d21
cmake: improve passing build options to try_compile()
Pass build options directly via `COMPILE_DEFINTIONS` and
`LINK_LIBRARIES`, instead of "tunneling" them through `CMAKE_FLAGS`.
The latter method breaks when passing `Threads::Threads` as library via
`CMAKE_REQUIRED_LIBRARIES`, while also being complex and fragile.

Example:
```
-- Performing Test HAVE_FSETXATTR_5
CMake Error at bld/CMakeFiles/CMakeTmp/CMakeLists.txt:27 (target_link_libraries):
  Target "cmTC_3386e" links to:

    Threads::Threads

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

CMake Error at CMake/Macros.cmake:51 (try_compile):
  Failed to generate test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:1684 (curl_internal_test)
```
Ref: https://github.com/curl/curl/actions/runs/23792043930/job/69329796592?pr=21168#step:38:318

Note: a side-effect is no longer passing C compiler flags (e.g.
`CMAKE_REQUIRED_FLAGS`) to the _linker_. This should not be an issue,
though CMake is passing them during its built-in detections.

Ref: https://cmake.org/cmake/help/v3.18/command/try_compile.html

Closes #21176
2026-03-31 13:23:46 +02:00
..
cmake_uninstall.in.cmake cmake: match filename suffixes with file content 2025-12-20 11:34:27 +01:00
curl-config.in.cmake cmake: use Threads::Threads imported target for POSIX Threads 2026-03-31 00:51:04 +02:00
CurlSymbolHiding.cmake build: merge TrackMemory (CURLDEBUG) into debug-enabled option 2026-01-19 18:43:17 +01:00
CurlTests.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
FindBrotli.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindCares.cmake cmake: add CMake Config-based dependency detection for c-ares, wolfSSL 2026-03-26 11:20:03 +01:00
FindGnuTLS.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindGSS.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindLDAP.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindLibbacktrace.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindLibgsasl.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindLibidn2.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindLibpsl.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindLibssh2.cmake cmake: add CMake Config-based dependency detection 2026-03-21 18:52:31 +01:00
FindLibssh.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindLibuv.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindMbedTLS.cmake cmake: add CMake Config-based dependency detection 2026-03-21 18:52:31 +01:00
FindNettle.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindNGHTTP2.cmake cmake: add CMake Config-based dependency detection 2026-03-21 18:52:31 +01:00
FindNGHTTP3.cmake cmake: add CMake Config-based dependency detection 2026-03-21 18:52:31 +01:00
FindNGTCP2.cmake cmake: add CMake Config-based dependency detection 2026-03-21 18:52:31 +01:00
FindQuiche.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindRustls.cmake cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
FindWolfSSL.cmake cmake: add CMake Config-based dependency detection for c-ares, wolfSSL 2026-03-26 11:20:03 +01:00
FindZstd.cmake cmake: add CMake Config-based dependency detection 2026-03-21 18:52:31 +01:00
Macros.cmake cmake: improve passing build options to try_compile() 2026-03-31 13:23:46 +02:00
OtherTests.cmake cmake: use AIX built-in variable (with CMake 4.0+) 2026-03-30 13:05:17 +02:00
PickyWarnings.cmake spacecheck: check long lines and repeat spaces, fix fallouts 2026-03-25 11:02:08 +01:00
unix-cache.cmake src: drop detecting and redefining system symbol ftruncate 2026-03-30 13:46:14 +02:00
Utilities.cmake cmake: fix LOCATION property access condition (debug) 2026-03-06 15:35:27 +01:00
win32-cache.cmake src: drop detecting and redefining system symbol ftruncate 2026-03-30 13:46:14 +02:00