[CMake] how to set 2 additional compile flags on target (VS2005)
Bram de Greve
bram.degreve at bramz.org
Tue Nov 11 06:39:14 EST 2008
Hi,
I'm trying to use precompiled headers with VS2005. Therefore, I need to
set on the target two additional compile flags: /Yu with the header to
be precompiled, and /Fp with the path of the resulting PCH.
But whatever I try, cmake will only set one of them.
The following will only set the second compile flag. in this case /Fp.
If I reverse the lines, it will set /Yu.
set_target_properties(
${target}
PROPERTIES
COMPILE_FLAGS /Yu"${hdrfile}"
COMPILE_FLAGS /Fp"${pchpath}"
)
If I put both compile flags on one line as following, it is not accepted
by CMake as there's an incorrect number of arguments:
set_target_properties(
${target}
PROPERTIES
COMPILE_FLAGS /Yu"${hdrfile}" /Fp"${pchpath}"
)
Splitting it into two statements as following, has the same effect (only
setting the second one)
set_target_properties(
${target}
PROPERTIES
COMPILE_FLAGS /Yu"${hdrfile}"
)
set_target_properties(
${target}
PROPERTIES
COMPILE_FLAGS /Fp"${pchpath}"
)
Using set_property with APPEND, has the effect that it concatenates both
flags with a semicolon, something like /Yufoobar.h;/Fpfoobar.pch, so
that VS thinks the header to be precompiled is called
"foobar.h;/Fpfoobar.pch". Err, wrong =)
set_property(
TARGET ${target}
APPEND PROPERTY
COMPILE_FLAGS /Yu"${hdrfile}" /Fp"${pchpath}")
It even has this same concatenation effect when I split it into two
statements:
set_property(
TARGET ${target}
APPEND PROPERTY
COMPILE_FLAGS /Fp"${pchpath}")
set_property(
TARGET ${target}
APPEND PROPERTY
COMPILE_FLAGS /Yu"${hdrfile}")
And when I leave out the APPEND, we're back to square one where it only
sets the second compiler flag:
set_property(
TARGET ${target}
PROPERTY
COMPILE_FLAGS /Fp"${pchpath}")
set_property(
TARGET ${target}
PROPERTY
COMPILE_FLAGS /Yu"${hdrfile}")
So, my question obviously is: what's the proper way to set TWO (or more)
additional compiler flags on na target.
Thanks in advance,
Bram
PS: Technically, it's not really necessary to set /Fp, as the default is
fine, but it still strikes me as cumbersome.
More information about the CMake
mailing list