Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 256
ozgur Avatar asked Nov 24 '16 06:11

ozgur


1 Answers

Use this:

if(MSVC)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()

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.

like image 100
skypjack Avatar answered Nov 15 '22 12:11

skypjack