[CMAKE] Fix cached variable that prevents testing for flag support
Summary:
The CHECK_C_COMPILER_FLAG() and CHECK_CXX_COMPILER_FLAG() functions
from CMake return the result of the test in a variable passed as an
argument.
This variable is cached internally, so that subsequent calls of the
function with the same variable return the result without performing the
test again.
The add_c_compiler_flag() and add_cxx_compiler_flag() functions are
calling CHECK_C_COMPILER_FLAG() and CHECK_CXX_COMPILER_FLAG() with
the same variable FLAG_IS_SUPPORTED, making the test ineffective.
This diffs fixes the issue by generating a new variable name based on
the flag name. This allow for keeping advantage of the caching
mechanisme while having a different variable for each flag, making the
test working as expected.
Test Plan:
At the end of src/CMakeLists.txt, add the following line:
add_cxx_compiler_flag(-foo)
Then run:
mkdir buildcmake && cd buildcmake cmake -GNinja .. ninja -v
Before the patch:
CMake will output a Performing Test FLAG_IS_SUPPORTED - Success line
and the -foo option will be added on the command lines, leading to a
build failure.
After the patch:
CMake will output a Performing Test have_cxx_foo - Failed line for
the -foo option and it will not be added on the command lines.
Reviewers: #bitcoin_abc, deadalnix, jasonbcox
Reviewed By: #bitcoin_abc, deadalnix, jasonbcox
Subscribers: teamcity, schancel
Differential Revision: https://reviews.bitcoinabc.org/D2653