[CMake] Problem with set_source_files_properties

Michael Hertling mhertling at online.de
Thu Jan 5 19:30:25 EST 2012


On 01/05/2012 02:42 PM, Mateusz Loskot wrote:
> On 5 January 2012 12:31, vivek goel <goelvivek2011 at gmail.com> wrote:
>> I am using code
>> where f contains the file name
>>
>>
>> set(MY_PATH "-D__RELATIVE_PATH__=\\\"ab\\\"")
>> set_source_files_properties(${f} PROPERTIES
>>   COMPILE_FLAGS ${MY_PATH})
>>
>> I am not able to see -D__RELATIVE_PATH__ inside compilation flags.
> 
> You have read the 2nd paragraph of COMPILE_FLAGS section in manual, haven't you.
> 
> Best regards,

Although COMPILE_FLAGS is not meant to specify definitions,
it usually works; look at the following exemplary project:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(P C)
SET(CMAKE_VERBOSE_MAKEFILE ON)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){return 0;}\n")
ADD_EXECUTABLE(main main.c)
SET_SOURCE_FILES_PROPERTIES(main.c
    PROPERTIES COMPILE_FLAGS "-D__RELATIVE_PATH__=\\\"ab\\\"")

Make's output reveals:

.../gcc -D__RELATIVE_PATH__=\"ab\" -o .../main.c.o -c .../main.c

Vivek, perhaps a mistake with regard to the variable f? BTW, note
that the COMPILE_DEFINITIONS properties take account for proper
escaping and then some; the COMPILE_FLAGS ones don't, AFAIK.

Regards,

Michael


More information about the CMake mailing list