[CMake] Pass value from CMake to source file?

Eric Noulard eric.noulard at gmail.com
Sun Oct 4 08:06:38 EDT 2009


2009/10/4 Wojciech Migda <wojtek.golf at interia.pl>:
>>
>> You should use CONFIGURE_FILE for that.
>>
>> Look for example this section of the Wiki:
>> http://www.cmake.org/Wiki/CMake_HowToDoPlatformChecks
> My personal favourite would be preprocessor macro:
>
> FIND_PATH(IMAGE_DIR REQUIRED)
>
> ADD_DEFINITIONS( -DIMAGE_DIR=${IMAGE_DIR} )

Pretty right for a single/simple definition this is very good
thank you Wojciech.

The difference here is that IMAGE_DIR will be defined for all
compiled files.
If you want to use the same technique but applied to a single source file
you may use

set_source_files_properties(<your_particular_sourcefile>
PROPERTIES COMPILE_FLAGS "-DIMAGE_DIR=${IMAGE_DIR}")




-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list