MantisBT - CMake
View Issue Details
0009590CMakeCMakepublic2009-09-24 02:242010-12-14 18:49
Rolf Eike Beer 
David Cole 
normalminoralways
closedwon't fix 
CMake-2-6 
 
0009590: IF(VARIABLE) doesn't work inside Makro
I'll attach a CMakeLists.txt that is a stripped down version of one of our makros where it took me some hours only to find out that IF(VARIABLE) simply doesn't work inside the makro even if the variable is set.
Example output (running on Win32 using CMake 2.6.4)

-- BASE_DIR IS NOT! /usr/local/lib
-- BASE_DIR IS NOT! /usr/local/lib
-- BASE_DIR IS NOT! /usr/local/lib
-- BASE_DIR IS!
-- Lib_dirs: /usr/local/lib
-- TESTVAR IS!
-- TESTVAR IS!
-- TESTVAR IS NOT! /usr/local/lib
-- TESTVAR IS!
No tags attached.
has duplicate 0012398closed David Cole "IF" infamous <variable/string> functionality fails to work with macro arguments 
txt CMakeLists.txt (1,467) 2009-09-24 02:25
https://public.kitware.com/Bug/file/2484/CMakeLists.txt
Issue History
2009-09-24 02:24Rolf Eike BeerNew Issue
2009-09-24 02:25Rolf Eike BeerFile Added: CMakeLists.txt
2009-09-25 11:45David ColeStatusnew => assigned
2009-09-25 11:45David ColeAssigned To => David Cole
2009-09-25 11:50David ColeNote Added: 0017743
2009-09-25 11:50David ColeStatusassigned => resolved
2009-09-25 11:50David ColeResolutionopen => won't fix
2010-12-14 18:49David ColeNote Added: 0024084
2010-12-14 18:49David ColeStatusresolved => closed
2011-08-12 10:36David ColeRelationship addedhas duplicate 0012398

Notes
(0017743)
David Cole   
2009-09-25 11:50   
This behavior is intentional and the way that CMake works. Macro arguments are not CMake variables. They are substituted when dereferenced inside a macro, but the argument names used in the MACRO command are not CMake variables.

They can become CMake variables inside the macro if you do something like this at the very top of the macro:
  SET(BASE_DIR "${BASE_DIR}")
  SET(LIB_DIR "${LIB_DIR}")

Alternatively, you can change the MACRO to a FUNCTION. Function arguments *do* become CMake variables for the scope of the function...

From the cmake MACRO documentation:
http://www.cmake.org/cmake/help/cmake2.6docs.html#command:macro [^]

"Note that the parameters to a macro and values such as ARGN are not variables in the usual CMake sense. They are string replacements much like the c preprocessor would do with a macro. If you want true CMake variables you should look at the function command."
(0024084)
David Cole   
2010-12-14 18:49   
Closing bugs that have been resolved for more than 3 months without any further updates.