[CMake] Passing Macro Arguments to "configure_file"
Not sure what I am doing wrong but here is my problem. I have a macro that takes a few arguments. Within the macro I am calling "configure_file" and in the file that gets configured I am using the values of the arguments. Unfortunately after the file is configured during cmake time the values are blank. Here is a concise test case. # CMakeLists.txt file Begin cmake_minimum_required(VERSION 2.6) macro(vartest variable) message(STATUS "--") message(STATUS "variable: ${variable}") SET (Test_Variable "${variable}/Test_Output.cmake") CONFIGURE_FILE("Test.txt.in" "Test.txt" @ONLY IMMEDIATE) endmacro(vartest variable) set (target "myTarget") vartest(${target}) # CMakeLists.txt file End # Test.txt.in Begin variable = @variable@ Test_Variable = @Test_Variable@ # Test. txt.in End The output I get from Cmake is: 509:[mjack...@shepard-2:Build]$ cmake ../ -- -- -- variable: myTarget -- Configuring done -- Generating done -- Build files have been written to: /Users/mjackson/Desktop/Test/Build and the txt file looks like this: variable = Test_Variable = myTarget/Test_Output.cmake Is this a bug or something I am doing wrong or am I just not understanding something basic about macros. (Probably the "dumb" part.. ) Thanks for any help _ Mike Jackson mike.jack...@bluequartz.net BlueQuartz Softwarewww.bluequartz.net Principal Software Engineer Dayton, Ohio ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Passing Macro Arguments to "configure_file"
There is no variable named "variable" inside your macro. There is sort of like a "pre-processor token" that gets substituted in every place ${variable} is referenced as the macro is expanded for use. (Not exactly alike, but very similar to the C pre-processor macro concept... (#define)) If you want a variable named the same as your macro parameter for use in configure_file or other things that require actual variables, simply do this inside your macro: set(variable ${variable}) HTH, David On Wed, Feb 4, 2009 at 9:04 AM, Michael Jackson wrote: > Not sure what I am doing wrong but here is my problem. > I have a macro that takes a few arguments. Within the macro I am calling > "configure_file" and in the file that gets configured I am using the values > of the arguments. Unfortunately after the file is configured during cmake > time the values are blank. Here is a concise test case. > > > # CMakeLists.txt file Begin > cmake_minimum_required(VERSION 2.6) > macro(vartest variable) > message(STATUS "--") > message(STATUS "variable: ${variable}") > SET (Test_Variable "${variable}/Test_Output.cmake") > CONFIGURE_FILE("Test.txt.in" "Test.txt" @ONLY IMMEDIATE) > endmacro(vartest variable) > set (target "myTarget") > vartest(${target}) > # CMakeLists.txt file End > > # Test.txt.in Begin > variable = @variable@ > Test_Variable = @Test_Variable@ > # Test. txt.in End > > The output I get from Cmake is: > 509:[mjack...@shepard-2:Build]$ cmake ../ > -- -- > -- variable: myTarget > -- Configuring done > -- Generating done > -- Build files have been written to: /Users/mjackson/Desktop/Test/Build > > > and the txt file looks like this: > variable = > Test_Variable = myTarget/Test_Output.cmake > > Is this a bug or something I am doing wrong or am I just not understanding > something basic about macros. (Probably the "dumb" part.. ) > > Thanks for any help > _ > Mike Jackson mike.jack...@bluequartz.net > BlueQuartz Softwarewww.bluequartz.net > Principal Software Engineer Dayton, Ohio > > > > ___ > CMake mailing list > CMake@cmake.org > http://www.cmake.org/mailman/listinfo/cmake > ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Passing Macro Arguments to "configure_file"
Thanks for the clarification on that. I did figure out the set (variable ${varaible}) part though as a work-around. Just my opinion but that is not very intuitive. Now that I know how to deal with it I guess it is ok. Thanks --- Mike Jackson www.bluequartz.net On Feb 4, 2009, at 10:04 AM, David Cole wrote: There is no variable named "variable" inside your macro. There is sort of like a "pre-processor token" that gets substituted in every place ${variable} is referenced as the macro is expanded for use. (Not exactly alike, but very similar to the C pre-processor macro concept... (#define)) If you want a variable named the same as your macro parameter for use in configure_file or other things that require actual variables, simply do this inside your macro: set(variable ${variable}) HTH, David On Wed, Feb 4, 2009 at 9:04 AM, Michael Jackson > wrote: Not sure what I am doing wrong but here is my problem. I have a macro that takes a few arguments. Within the macro I am calling "configure_file" and in the file that gets configured I am using the values of the arguments. Unfortunately after the file is configured during cmake time the values are blank. Here is a concise test case. # CMakeLists.txt file Begin cmake_minimum_required(VERSION 2.6) macro(vartest variable) message(STATUS "--") message(STATUS "variable: ${variable}") SET (Test_Variable "${variable}/Test_Output.cmake") CONFIGURE_FILE("Test.txt.in" "Test.txt" @ONLY IMMEDIATE) endmacro(vartest variable) set (target "myTarget") vartest(${target}) # CMakeLists.txt file End # Test.txt.in Begin variable = @variable@ Test_Variable = @Test_Variable@ # Test. txt.in End The output I get from Cmake is: 509:[mjack...@shepard-2:Build]$ cmake ../ -- -- -- variable: myTarget -- Configuring done -- Generating done -- Build files have been written to: /Users/mjackson/Desktop/Test/ Build and the txt file looks like this: variable = Test_Variable = myTarget/Test_Output.cmake Is this a bug or something I am doing wrong or am I just not understanding something basic about macros. (Probably the "dumb" part.. ) Thanks for any help _ Mike Jackson mike.jack...@bluequartz.net BlueQuartz Softwarewww.bluequartz.net Principal Software Engineer Dayton, Ohio ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake