How to define a C++ preprocessor macro through the command line with CMake?

后端 未结 4 636
野性不改
野性不改 2020-12-01 05:25

I try to set a preprocessor macro in the command line of CMake. I\'ve tried:

set generator=\"Visual Studio 8 2005\"
set params=-D MY_MACRO=1
cmake.exe -G %ge         


        
4条回答
  •  半阙折子戏
    2020-12-01 05:56

    Unless you have a good reason not to, you should use ADD_DEFINITIONS(=[, ...]).

    Just add the following line to your CMakeLists.txt:

    ADD_DEFINITIONS("MY_MACRO=1")
    

    CMake will take care of the syntax of the switches (be it -D=, or /D=).

提交回复
热议问题