ozgur ozgur - 8 days ago 14
C++ Question

Adding _CRT_SECURE_NO_WARNINGS definition using cmake

Is it possible to add

_CRT_SECURE_NO_WARNINGS
preprocessor definition using cmake?

add_definitions(-CRT_SECURE_NO_WARNINGS)
add_definitions(-_CRT_SECURE_NO_WARNINGS)
add_definitions(_CRT_SECURE_NO_WARNINGS)


These are what I've tried so far. None of these attempts were successful.

Answer

Use this:

add_definitions(-D_CRT_SECURE_NO_WARNINGS)

See here for the official documentation.
The general form is:

add_definitions(-DFOO -DBAR ...)

Note that, if it's intended for a single target, you should rather use target_compile_definitions.

Comments