[CMake] Escaping semicolons in COMPILE_FLAGS on msvc

Michael Hertling mhertling at online.de
Mon Oct 18 23:03:08 EDT 2010


On 10/18/2010 06:50 PM, David Genest wrote:
> Hi, 
> 
> I have tried and tried, but haven't succeeded to include a semicolon as a COMPILE_FLAGS property for a file. I turn to you for wisdom:
> 
> I need to get this as a result in the pre-processor definitions: 
> 
> MYPATH=\"d:\\;.\\Lib\"
> 
> But when I use the following escape sequence in set_source_files_properties:
> 
> set_source_files_properties(source.c PROPERTIES COMPILE_FLAGS "-DMYPATH=\\\"d:\\\;.\\\\Lib\\\"")
> 
> the generated result is: MYPATH=\"d:\\";".\\Lib\"
> 
> note the quoted semicolon. Is there a quoting workaround to allow unquoted semicolons?

FYI: On *nix, the following CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(GENEST C)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){return 0;}\n")
SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/main.c
    PROPERTIES COMPILE_FLAGS "-DMYPATH=\\\"d:\\\;.\\\\Lib\\\"")
GET_SOURCE_FILE_PROPERTY(f ${CMAKE_BINARY_DIR}/main.c COMPILE_FLAGS)
MESSAGE("COMPILE_FLAGS: ${f}")
ADD_EXECUTABLE(main main.c)

results in

COMPILE_FLAGS: -DMYPATH=\"d:\\;.\\Lib\"

as you desire, and the compile command shows up as

...gcc -DMYPATH=\"d:\\;.\\Lib\" -o .../main.c.o -c .../main.c

also as desired, but fails since the shell interprets this line as an
invocation of gcc followed by an invocation of a .\Lib" command. Thus,
your issue seems to be related to your platform or the generator you
use, resp. BTW, which string do you want to see in your preprocessed
source file, i.e. what is MYPATH expected to be expanded to exactly,
and have you considered to use the COMPILE_DEFINITIONS properties
instead of COMPILE_FLAGS?

Regards,

Michael


More information about the CMake mailing list