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