[CMake] How to add "-DDEBUG" just in command line?

Kermit Mei kermit.mei at gmail.com
Sat Feb 28 07:15:09 EST 2009


Enrico Franchi wrote:
>
> On Feb 28, 2009, at 10:48 AM, Kermit Mei wrote:
>
>> Hello, is there any elegant way to add "-DDEBUG" to the complier flag
>> just in command line?
>
> IF(${CMAKE_BUILD_TYPE} STREQUAL Debug)
>         MESSAGE("Adding Debug flag...")
>         ADD_DEFINITIONS(-DDEBUG)
> ENDIF(${CMAKE_BUILD_TYPE} STREQUAL Debug)

I had google it, and everything goes well:


OPTION(DEFINE_DEBUG
  "Build the project using debugging code"
  OFF)
IF(DEFINE_DEBUG)
  MESSAGE("Adding Debug flag...")
  ADD_DEFINITIONS(-DDEBUG)
  SET(CMAKE_BUILD_TYPE Debug)
  MESSAGE("Build type is " ${CMAKE_BUILD_TYPE})
ENDIF(DEFINE_DEBUG)

And ues the following command to add debug build:
$ cmake -DDEFINE_DEBUG=ON -DCMAKE_INSTALL_PREFIX=/usr ..

Thank you, all the same;p



More information about the CMake mailing list