MantisBT - CMake
View Issue Details
0012628CMakeCMakepublic2011-12-15 06:202012-05-09 15:26
Colin Powers 
Brad King 
normalminoralways
closedfixed 
LinuxRHEL6
CMake 2.8.4 
CMake 2.8.7CMake 2.8.7 
0012628: CMake uses variable called ${OUTPUT}, causes problems when user tries to use a variable called ${OUTPUT}
I just found one of our CMakeLists.txt with the following line:

ADD_CUSTOM_TARGET(policy ALL echo
                         DEPENDS ${OUTPUT}
)

Where ${OUTPUT} was populated in a for loop like this:

list(APPEND OUTPUT ${target})

The value of ${target} is not really important. It seems ${OUTPUT} was also being manipulated by CMake, and we found that in one of the produced makefiles (./policy/CMakeFiles/policy.dir/build.make) the following content was there unexpectedly:

policy/CMakeFiles/policy: <build dir>/policy/Change\ Dir:\ <build dir>/CMakeFiles/CMakeTmp

Run\ Build\ Command:/usr/bin/gmake\ "cmTryCompileExec/fast"
/usr/bin/gmake\ -f\ CMakeFiles/cmTryCompileExec.dir/build.make\ CMakeFiles/cmTryCompileExec.dir/build
gmake[1]:\ Entering\ directory\ `<build dir>/CMakeFiles/CMakeTmp'
/usr/local/bin/cmake\ -E\ cmake_progress_report\ <build dir>/CMakeFiles/CMakeTmp/CMakeFiles\ 1
Building\ CXX\ object\ CMakeFiles/cmTryCompileExec.dir/testCXXCompiler.cxx.o
/usr/local/bin/c++\ \ \ \ \ -o\ CMakeFiles/cmTryCompileExec.dir/testCXXCompiler.cxx.o\ -c\ <build dir>/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking\ CXX\ executable\ cmTryCompileExec
/usr/local/bin/cmake\ -E\ cmake_link_script\ CMakeFiles/cmTryCompileExec.dir/link.txt\ --verbose=1
/usr/local/bin/c++\ \ \ \ \ \ \ \ \ CMakeFiles/cmTryCompileExec.dir/testCXXCompiler.cxx.o\ \ -o\ cmTryCompileExec\ -rdynamic\
gmake[1]:\ Leaving\ directory\ `<build dir>/CMakeFiles/CMakeTmp'

I guess this is perhaps content that ends up in ./CMakeFiles/CMakeOutput.log?

In any case, ${OUTPUT} was perhaps not the best choice of variable name for us, and I am able to solve the problem by doing something more sensible. However, is it sensible for CMake to be using this variable name itself? Is this variable name reserved and is that documented anywhere? I had a quick look around and couldn't find anything. Searching for other instances of the problem was also difficult, as you might expect when your keyword is "output".

For reference the actual error I was getting was on typing 'make': target pattern contains no `%'
Try adding somewhere sensible in your CMakeLists.txt:

message("-- OUTPUT IS: ${OUTPUT}")

Observe that it is populated with various content.
No tags attached.
Issue History
2011-12-15 06:20Colin PowersNew Issue
2011-12-15 06:29Colin PowersNote Added: 0027983
2011-12-15 08:00Brad KingNote Added: 0027984
2011-12-15 08:19Colin PowersNote Added: 0027985
2011-12-15 08:35Brad KingNote Added: 0027986
2011-12-15 08:35Brad KingStatusnew => resolved
2011-12-15 08:35Brad KingResolutionopen => fixed
2011-12-15 08:35Brad KingAssigned To => Brad King
2011-12-16 17:29David ColeFixed in Version => CMake 2.8.7
2011-12-16 17:29David ColeTarget Version => CMake 2.8.7
2012-05-09 15:26David ColeNote Added: 0029454
2012-05-09 15:26David ColeStatusresolved => closed

Notes
(0027983)
Colin Powers   
2011-12-15 06:29   
Error message:

policy/CMakeFiles/policy.dir/build.make:45: *** target pattern contains no `%'. Stop.

Contents of build.make line 45 are as specified in the description.
(0027984)
Brad King   
2011-12-15 08:00   
It's quite likely that one of the CMake language Modules uses this variable and could simply be fixed to use a better name. Run CMake with the --trace option to get verbose output about command processing. That should tell you where it is used.
(0027985)
Colin Powers   
2011-12-15 08:19   
Thanks Brad. It looks as though the variable appears in the following CMake Modules:

CMakeDetermineCompilerABI.cmake
CMakeTestCCompiler.cmake
CMakeTestCXXCompiler.cmake


It looks at first glance as though the variable is set by the first one and used in the latter two.
(0027986)
Brad King   
2011-12-15 08:35   
The use in CMakeDetermineCompilerABI.cmake is inside a FUNCTION() so it has its own scope.

The uses in CMakeTestCCompiler.cmake and CMakeTestCXXCompiler.cmake are the offenders. This should fix it:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5f6985ac [^]
(0029454)
David Cole   
2012-05-09 15:26   
Closing resolved issues that have not been updated in more than 4 months.