[CMake] 'recursive' or multiple level @@ replacement in configure_file
J.S. van Bethlehem
j.s.van.bethlehem at astro.rug.nl
Fri May 6 04:25:21 EDT 2011
David Cole wrote:
> On Thu, May 5, 2011 at 7:08 AM, J.S. van Bethlehem
> <j.s.van.bethlehem at astro.rug.nl
> <mailto:j.s.van.bethlehem at astro.rug.nl>> wrote:
>
> Hello,
>
> Today I was trying something along the following lines:
> in CMakeLists.txt
> set(BASENAME some_text)
> set(${BASENAME}_DIR /some/path)
> set(${BASENAME}_SHARE /some/other/path)
> set(${BASENAME}_INCLUDES file1.h;file2.h;file3.h)
> configure_file(config.h.in <http://config.h.in> config.h @ONLY)
>
> and in config.h.in <http://config.h.in> do:
> set(INSTALL_PATH @@BASENAME at _DIR@)
> foreach(incl ${INSTALL_PATH})
> # do something
> endforeach(incl ${INSTALL_PATH})
>
> My expectation was that first @BASENAME@ would evaluate to
> 'some_text' after which @some_text_DIR@ would evaluate to the
> respective value. This fails, so the obvious question is: am I
> trying something that is simply not possible, or should I use
> different syntax to accomplish this?
>
>
>
> Why are you putting CMake script code into the file config.h.in
> <http://config.h.in>?
>
> Seems like you want to generate the .h.in <http://h.in> file based on
> a CMake loop, and *then* use it in a configure_file call...
>
> What do you want the final .h file to look like?
>
Aah, right, very silly of me using the 'config.h' name. It suggests
somehow that I want to create C(++)(0x) header, but this is not the
case. My apologies - I tried to quickly create a 'minimal example' but
thereby created something that is not even close to what I want to
achieve. Let me be a bit more specific then.
I tend to be quite modular when I write code (even though it's just for
personal use) and I noticed that when creating CMake-files for each of
these pieces I was continuously writing the same CMake script lines for
these pieces. So I decided to create a special CMakeModules-package that
stores .cmake-script files that define these macros. So in the above
example BASENAME would be the name of my module (which I like to store
in a variable to prevent typos when this name is rather long or in case
I want to change it) Then in the example above the *_INCLUDES would be a
list of *.cmake files that define a set of macros, not header-files.
Then what I called config.h.in would be an in-file for a
modulename-config.cmake file. Then when I do find_package(BASENAME) in
my other sources, CMake would find the resulting configuration file,
which would then take care of including the macro-files that are part of
my CMakeModules-package.
Now that I'm reading back, I see I made another mistake: the variable to
the foreach-command should be ${BASENAME}_INCLUDES; this is the piece of
the configuration-file that will read my macro *.cmake files.
Again my apologies for the unclear message. Hopefully the comments I
added now make things a bit clearer.
Yours sincerely,
Jakob van Bethlehem
More information about the CMake
mailing list