How to create a C #define for a certain target using CMake?

后端 未结 3 1726
面向向阳花
面向向阳花 2020-12-30 01:45

I feel a little stupid right now. After recently converting a few smaller projects to use CMake, I decided to also get rid of a few \"Platform_Config.h\" files. These files

3条回答
  •  有刺的猬
    2020-12-30 02:37

    option command might provide what you are looking for.
    use it with the COMPILE DEFINITIONS property on the target and i think you are done. To set the property on the target, use the command set target properties

    option(DEBUGPRINTS "Prints a lot of debug prints")
    target(myProgram ...)
    if(DEBUGPRINTS)
    set_target_properties(myProgram PROPERTIES COMPILE_DEFINITIONS "DEBUGPRINTS=1")
    endif()
    

    edit:

    The option i wrote in the example shows up as a checkbox in the CMake GUI.

提交回复
热议问题