Repository: mesonbuild/meson

Issue:
Question: Where are c_std and cpp_std flags logged?
I run `ninja -v -C builddir` command and didn't see any `-std=c89` or `std=c++14` flags in output of two separate projects.

Aren't those commands supposed to be logged as well?

By the way, this is what is inside `compile_commands.json` file of my C project; I'm beautifying it for reading purposes:
```json
[
  {
    "directory": "/home/stefanos/tmp/c_projects/dokimi/builddir",
    "command": "ccache cc -Idemo@exe -I. -I.. -I../include 
    -fdiagnostics-color=always -pipe 
    -D_FILE_OFFSET_BITS=64 
    -Wall -Winvalid-pch -Wextra -Wpedantic 
    -O0 -g  -MD -MQ 'demo@exe/src_main.c.o' 
    -MF 'demo@exe/src_main.c.o.d' -o 'demo@exe/src_main.c.o' -c ../src/main.c",
    "file": "../src/main.c"
  }
]
```
Is this the expected behavior?


Discussion:
Did you change the default options? And in that case did you wipe the build directory after changing it?
@NickeZ Here's what I have in my meson.build:

```python
project(
    'demo',
    'c',
    version: '0.1',
    default_options: [
        'c_std=c89',
        'warning_level=3'
    ]
)

sources = ['src/main.c']
inc = include_directories('include')

executable(
    'demo', 
    sources,
    include_directories : inc,
    install: true
)
```
> Did you change the default options? And in that case did you wipe the build directory after changing it?

Well, I first typed the `meson.build` file and then generated my `builddir`.
If you first generated with

```
project(
    'demo',
    'c',
    version: '0.1',
)
```

and then modified the file to:

```
project(
    'demo',
    'c',
    version: '0.1',
    default_options: [
        'c_std=c89',
        'warning_level=3'
    ]
)
```

You have to wipe the build directory. This is a "feature" not a bug according to @jpakkane .
This is a very strange behavior. As I said, I typed the aforementioned `meson.build` first and then generated the `builddir`.

Now that I have removed it and regenerated it, it works as expected.

Is this normal or just happens from time to time?
> Is this normal or just happens from time to time?

That should not happen. If you can find a way to reproduce it you should file a bug.

However, the fact that `default_options` never are applied to existing build directories is a feature.
See #2193
Ah I see. So it's a common issue, not just my case.

Resolving patch:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1855,6 +1855,7 @@ def __init__(self, build, backend=None, subproject='', subdir='', subproject_dir
             self.default_project_options = default_project_options.copy()
         else:
             self.default_project_options = {}
+        self.project_default_options = {}
         self.build_func_dict()
         # build_def_files needs to be defined before parse_project is called
         self.build_def_files = [os.path.join(self.subdir, environment.build_filename)]
@@ -1874,6 +1875,18 @@ def __init__(self, build, backend=None, subproject='', subdir='', subproject_dir
             else:
                 self.builtin['target_machine'] = self.builtin['host_machine']
 
+    def get_non_matching_default_options(self):
+        env = self.environment
+        for def_opt_name, def_opt_value in self.project_default_options.items():
+            for option_type in [
+                    env.coredata.builtins, env.coredata.compiler_options,
+                    env.coredata.backend_options, env.coredata.base_options,
+                    env.coredata.user_options]:
+                for cur_opt_name, cur_opt_value in option_type.items():
+                    if (def_opt_name == cur_opt_name and
+                            def_opt_value != cur_opt_value.value):
+                        yield (def_opt_name, def_opt_value, cur_opt_value.value)
+
     def build_func_dict(self):
         self.funcs.update({'add_global_arguments': self.func_add_global_arguments,
                            'add_project_arguments': self.func_add_project_arguments,
@@ -2377,9 +2390,10 @@ def func_project(self, node, args, kwargs):
         # values previously set from command line. That means that changing
         # default_options in a project will trigger a reconfigure but won't
         # have any effect.
+        self.project_default_options = mesonlib.stringlistify(kwargs.get('default_options', []))
+        self.project_default_options = coredata.create_options_dict(self.project_default_options)
         if self.environment.first_invocation:
-            default_options = mesonlib.stringlistify(kwargs.get('default_options', []))
-            default_options = coredata.create_options_dict(default_options)
+            default_options = self.project_default_options
             default_options.update(self.default_project_options)
         else:
             default_options = {}
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -142,6 +142,11 @@ def _generate(self, env):
             profile.runctx('intr.run()', globals(), locals(), filename=fname)
         else:
             intr.run()
+        # Print all default option values that don't match the current value
+        for def_opt_name, def_opt_value, cur_opt_value in intr.get_non_matching_default_options():
+            mlog.log('Option', mlog.bold(def_opt_name), 'is:',
+                     mlog.bold(str(cur_opt_value)),
+                     '[default: {}]'.format(str(def_opt_value)))
         try:
             dumpfile = os.path.join(env.get_scratch_dir(), 'build.dat')
             # We would like to write coredata as late as possible since we use the existence of


Test patch: