[CMake] Modules with additional files

Johannes Wienke jwienke at techfak.uni-bielefeld.de
Wed Dec 29 15:51:51 EST 2010


Am 29.12.2010 21:47 schrieb David Cole:
> 
> Variables inside functions inherit their values from the calling
> scope. If you need the value of the CMAKE_CURRENT_LIST_DIR in a
> function that points to the directory containing the file that the
> function is defined in, then you should do something like this:
> 
> # MyModule.cmake
> set(MyModule_DIR "${CMAKE_CURRENT_LIST_DIR}")
>   # important that this set call is at file scope outside of function
> declarations...
> 
> function(that_needs_list_dir ...)
>   set(dir "MyModule_DIR")
>   # use ${dir} here if necessary
> endfunction()

Thanks, I already did something like that.

> Of course, you're subject to global variable name clashes at this
> point.... so the global variable name should somehow incorporate the
> name of the file it lives in, and perhaps be named more cleverly than
> my example here so that you can avoid colliding with some other
> module's variable name.

Ok. Good to know.

> More context (sample code from your modules) would help us answer your
> questions more effectively....
> 
> By the way, CMAKE_CURRENT_LIST_DIR is new. It's only in CMake 2.8.3 and later.

Thanks for the reminder.

Johannes

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://www.cmake.org/pipermail/cmake/attachments/20101229/1d2e1ba6/attachment.pgp>


More information about the CMake mailing list