undefined variable is defined

cmake version 3.28.1
MinGW: MSYS_NT-10.0-22631 DESKTOP-UH4OPKD 3.4.10.x86_64 2023-12-22 10:06 UTC x86_64 Msys

I’ve been debugging a problem related to CheckSymbolExists macro. It seems that the ‘try_compile’ test is never run. The test
“if(NOT DEFINED “${VARIABLE}” OR “x${${VARIABLE}}” STREQUAL “x${VARIABLE}”)” failed.

I inserted this code in “macro(__CHECK_SYMBOL_EXISTS_IMPL SOURCEFILE SYMBOL FILES VARIABLE)”

unset(_MBEDTLS_V2_OR_NEWER)
if (DEFINED _MBEDTLS_V2_OR_NEWER)
message(“_MBEDTLS_V2_OR_NEWER defined”)
endif()

and it prints. I am puzzled.

The symbol being checked for is defined in the header and library. I believe that the clause "NOT DEFINED “${VARIABLE}” should have triggered. As far as I can tell, the variable being used was never set, so it should be undefined, and the ‘try_compile’ test run.

The command unset(_MBEDTLS_V2_OR_NEWER) will clear a non-cache variable if one exists, but if there is a cache variable by that name, it will continue to exist after this call. The expression in if (DEFINED _MBEDTLS_V2_OR_NEWER) will be true if either a cache or non-cache variable by that name is defined.

1 Like

That in fact is the case. Somehow, the variable must have gotten into the cache. Inserting ‘unset(_MBEDTLS_V2_OR_NEWER CACHE)’ allows it to work.

Thanks.