CheckIPOSupported: Creates common name 'result' as cache entry
After some discussion, we traced this down to an issue in CheckIPOSupported
. Original issue description is as follows:
Strange set(...)
behavior when setting new variable to undefined variable
TL;DR
In some circumstances, set(SOME_VAR ${UNDEFINED_VAR})
seems to set SOME_VAR
to TRUE
.
I'm trying to debug a problem with the TBB CMake build scripts. I've narrowed it down to this line: https://github.com/oneapi-src/oneTBB/blob/427c252e0bb9e191767a62d8a744b21950c343f6/cmake/TBBBuild.cmake#L57.
This looks fine to me, but for some reason, it gives a very strange result, so I added some print statements:
function(tbb_get_make_args)
set(oneValueArgs RESULT)
set(multiValueArgs USER_DEFINED_ARGS)
cmake_parse_arguments(tbb_GMA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (DEFINED tbb_GMA_USER_DEFINED_ARGS) # < Added by me
message(STATUS "tbb_GMA_USER_DEFINED_ARGS defined") # < Added by me
else() # < Added by me
message(STATUS "tbb_GMA_USER_DEFINED_ARGS <<NOT>> defined") # < Added by me
endif() # < Added by me
message(STATUS "tbb_GMA_USER_DEFINED_ARGS='${tbb_GMA_USER_DEFINED_ARGS}'") # < Added by me
set(result ${tbb_GMA_USER_DEFINED_ARGS})
message(STATUS "result='${result}'") # < Added by me
# ...
endfunction()
In most cases, the output seems to be as expected:
-- tbb_GMA_USER_DEFINED_ARGS <<NOT>> defined
-- tbb_GMA_USER_DEFINED_ARGS=''
-- result=''
However, for one specific project I have, it outputs the following:
-- tbb_GMA_USER_DEFINED_ARGS <<NOT>> defined
-- tbb_GMA_USER_DEFINED_ARGS=''
-- result='TRUE'
Subsequently, result
containing a string 'TRUE'
breaks the build process.
The very strange thing is that I'm unable to reproduce this in other projects, it only happens when building this specific project, it works fine on the very first build (after removing the build directory entirely) and it only occurs when building the CMake project as a Python module from within setup.py
(using the pybind11/cmake_example template).
I've tried creating a small CMake project with just pybind11 and TBB, but I can only reproduce it in the large project.
Adding quotes seems to fix the problem, but I'm unsure why, and I'm afraid it might trigger some other problems (result is a list, maybe quotes mess up the list separators etc.)
set(result "${tbb_GMA_USER_DEFINED_ARGS}") # > result is now always empty or equal to tbb_GMA_USER_DEFINED_ARGS
The project is in a private repository, because it's a university project, so we're not allowed to use public GitHub repositories. I attached our main CMakeLists.txt file, if you would like more details, I'm sure I can attach a more or less working project (without the main C++ code included).
I'm using CMake 3.16.4 on Ubuntu 19.10.
I guess my main question is: Is there any situation or configuration where setting a variable to an undefined variable results in that variable containing TRUE
?