Using CMake generator expressions with GYP

234 Views Asked by At

I'm working on Node.js native module which contains C and C++ sources. node-gyp is used to build the module.

As I want only one warning rises error in C code I use the following lines in binding.gyp:

"cflags!": [ "-Werror"],
"cflags": [ "-Werror=implicit-function-declaration" ],

This works fine while compiling C code but produces the following warning on each C++ source file:

cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-function-declaration’ is not valid for C++

I found this answer - Apply C-specific gcc options to C/C++ mixed library - which solves the same problem when using 'pure' CMake. Unfortunately I didn't found if it is possible and how to add this condition correctly to GYP configuration file - maybe using variables and conditions? Please, let me know if it's solvable. Thanks.

1

There are 1 best solutions below

0
On

I found solution to the problem in my question and I'm posting an answer just in case somebody will have the same kind of a problem.

Original improper configuration in binding.gyp was as follows:

"cflags!": [ "-Werror"],
"cflags": [ "-Werror=implicit-function-declaration" ],

Correct configuration for my requirements is:

"cflags!": [ "-Werror"],
"cflags_c": [ "-Werror=implicit-function-declaration" ],

To avoid the warning in C++ we just need to add required flag to C-special flags cflag_c.

Solution was obtained while studying my_module.target.mk file in my project which contains the following comments (thanks to developers!):

# Flags passed to all source files.
CFLAGS_Release := \
# Flags passed to only C files.
CFLAGS_C_Release := \
# Flags passed to only C++ files.
CFLAGS_CC_Release := \

Thus it's seemed obvious, but I still didn't find clear reference in CMake and GYP documentation on these flags. I'm asking please to provide me with corresponding links if you know them or you will find them - I should know where is my mistake in searching docs to avoid them in the future.