1Import('env')
2
3import os
4
5base_env = env.Clone()
6base_env.Replace(NANOPBFLAGS = '--cpp-descriptor')
7base_env.NanopbProtoCpp('message')
8
9# not enabled for "c++03", which fails with "warning: offset of on non-POD type 'TestMessage'"
10# 'offsetof' in C++98 requires POD type, C++11 standard relaxes that to standard-layout class.
11# see: http://www.cplusplus.com/reference/cstddef/offsetof/
12for std in ["c++11", "c++14", "c++17", "c++20"]:
13    e = base_env.Clone()
14    e.Append(CXXFLAGS = '-std={}'.format(std))
15
16    # Make sure compiler supports this version of C++ before we actually run the
17    # test.
18    conf = Configure(e)
19    compiler_valid = conf.CheckCXX() and conf.CheckCXXHeader('vector')
20    e = conf.Finish()
21    if not compiler_valid:
22        print("Skipping {} test - compiler doesn't support it".format(std))
23        continue
24
25    sources = [ 'cxx_callback_datatype.cpp', 'message.pb.cpp', '$NANOPB/pb_decode.c', '$NANOPB/pb_encode.c', '$NANOPB/pb_common.c' ]
26    objects = [ e.Object('{}_{}'.format(os.path.basename(s), std), s) for s in sources ]
27    p = e.Program(target = 'cxx_callback_datatype_{}'.format(std), source = objects)
28    e.RunTest(p)
29