[CMake] Adding definitions to compile one file ?

Eric Noulard eric.noulard at gmail.com
Thu Jan 21 09:50:34 EST 2016


2016-01-21 15:14 GMT+01:00 Vania Joloboff <vania.joloboff at inria.fr>:

> Hi
>
> I want to add two definitions to compile one specific files
> in addition to the global definitions.
> I have the following problem. If I use
>
> set_source_files_properties(source.cpp
> PROPERTIES
> COMPILE_DEFINITIONS VAR1=${MY_VAR1} VAR2=${MY_VAR2} )
>
> then I get error message incorrect number of arguments for
> set_source_files_properties
>
> If I put
> set_source_files_properties(source.cpp
> PROPERTIES COMPILE_DEFINITIONS "VAR1=${MY_VAR1} VAR2=${MY_VAR2}" )
>
> then it generates strangely enough the compile command
>
> /usr/bin/c++ -DVAR1="path1 VAR2=path2" ... source.cpp
>
> with the double quotes as above, which gives a weird value to VAR1 and no
> value to VAR2
>
> If I use twice set_source_files_properties
> the first one is overwritten by the second
> and I only get the definition of VAR2
>
> What am I supposed to do ?
>

Did you try to separate you VAR1 and VAR2 def suing semicolon as indicated
in the doc:
"The COMPILE_DEFINITIONS property may be set to a semicolon-separated
list of preprocessor definitions using the syntax VAR or VAR=value."

see
cmake --help-property COMPILE_DEFINITIONS

so try:
set_source_files_properties(source.cpp
PROPERTIES COMPILE_DEFINITIONS "VAR1=${MY_VAR1};VAR2=${MY_VAR2}" )


-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160121/ee2a5c8e/attachment.html>


More information about the CMake mailing list