Search code examples
csvcmakec-preprocessorconditional-compilation

define value with comma through cmake


I used to have a define like this:

#define MY_CLSID {0xc9955517, 0x6ca4, 0x439f, {0x86, 0xb7, 0xdd, 0xc5, 0xb6, 0x45, 0xe7, 0x6c}}

now I want to do this through cmake, but I have failed so far. Anyone knows how to do that?

P.S.: That was my try:

add_definitions(/D MY_CLSID={0x87f8774f,0xb485,0x47e2,{0xa7,0x55,0xa4,0xa,0x8a,0x5e,0x88,0x6c}})

Solution

  • Of course, arrowdodger's answer is correct and if you have only a few of those defines, I would recommend it as well. In case of lots of (more complex) defines, the use of configure_file can be a good alternative:

    // In Your_CLSID.h.in
    #cmakedefine {0xc9955517, 0x6ca4, 0x439f, {0x86, 0xb7, 0xdd, 0xc5, 0xb6, 0x45, 0xe7, 0x6c}}
    // end of Your_CLSID.h.in
    

    and generate a "Your_CLSID.h" with

    configure_file( ${CMAKE_SOURCE_DIR}/Your_CLSID_Config.h.in ${CMAKE_BINARY_DIR}/common/Your_CLSID.h )
    

    Of course, you will have to add your binary dir to the include-directories:

    include_directories( ${CMAKE_BINARY_DIR}/common )
    

    See also my similar answers to the following questions: