@@ -42,14 +42,22 @@ else:
4242 OPTFLAGS = "-O3 "
4343
4444# Enviroment use by all the builds
45- env = Environment (CXXFLAGS = "-std=c++2a " + FFLAGS + OPTFLAGS + WFLAGS )
45+ env = Environment (
46+ # The PATH should contain version-specific tools, such as 'protoc',
47+ # otherwise e.g. '/bin/protoc' would be called and the latter would produce
48+ # *.pb.* of a version different from the one of $PROTOBUF_INCLUDE dir.
49+ ENV = {'PATH' : os .environ ['PATH' ]},
50+ CXXFLAGS = "-std=c++2a " + FFLAGS + OPTFLAGS + WFLAGS
51+ )
4652# env.MergeFlags(GetOption('cflags'))
4753
4854comm_env = env .Clone ()
4955comm_env .Replace (
5056 CPPPATH = ['include' , 'src' ,
5157 os .getenv ('NLOHMANN_JSON_INCLUDE' , default = '/usr/include' ),
52- os .getenv ('GLOG_INCLUDE' , default = '' )],
58+ os .getenv ('GLOG_INCLUDE' , default = '' ),
59+ os .getenv ('PROTOBUF_INCLUDE' , default = '' )
60+ ],
5361 LIBS = [],
5462 LIBPATH = []
5563 )
@@ -58,11 +66,15 @@ comm_env.Replace(
5866# The rest of the code is supposed to compiled using higher standards.
5967lenient_env = comm_env .Clone ()
6068lenient_env .Replace (CXXFLAGS = lenient_env ['CXXFLAGS' ].replace ("-Weffc++" , "" ))
61- lenient_env .Replace (CXXFLAGS = re .sub ("-Warray-bounds[^\s]+" , "-Warray-bounds=1" , lenient_env ['CXXFLAGS' ]))
69+ lenient_env .Replace (CXXFLAGS = re .sub ("-Warray-bounds[^\s]+" , "-Warray-bounds=1" , lenient_env ['CXXFLAGS' ]))
6270lenient_env .Replace (CXXFLAGS = re .sub ("-Wsuggest-attribute=const" , "-Wno-suggest-attribute=const" , lenient_env ['CXXFLAGS' ]))
6371lenient_env .Replace (CXXFLAGS = re .sub ("-Wsuggest-final-types" , "-Wno-suggest-final-types" , lenient_env ['CXXFLAGS' ]))
6472lenient_env .Replace (CXXFLAGS = re .sub ("-Wuseless-cast" , "-Wno-useless-cast" , lenient_env ['CXXFLAGS' ]))
6573lenient_env .Replace (CXXFLAGS = re .sub ("-Wsuggest-override" , "-Wno-suggest-override" , lenient_env ['CXXFLAGS' ]))
74+ lenient_env .Replace (CXXFLAGS = re .sub ("-Wshadow" , "-Wno-shadow" , lenient_env ['CXXFLAGS' ]))
75+ lenient_env .Replace (CXXFLAGS = re .sub ("-Wredundant-decls" , "-Wno-redundant-decls" , lenient_env ['CXXFLAGS' ]))
76+ lenient_env .Replace (CXXFLAGS = re .sub ("-Wdeprecated-declarations" , "-Wno-deprecated-declarations" , lenient_env ['CXXFLAGS' ]))
77+ lenient_env .Replace (CXXFLAGS = re .sub ("-Wundef" , "-Wno-undef" , lenient_env ['CXXFLAGS' ]))
6678
6779comm_cc = [
6880 'src/comm/ConnClient.cc' ,
@@ -83,10 +95,27 @@ ulib = comm_env.SharedLibrary('lib/comm', comm_cc)
8395client_env = comm_env .Clone ()
8496client_env .Replace (
8597 CPPPATH = ['include' , 'src' ,
86- os .getenv ('NLOHMANN_JSON_INCLUDE' , default = '/usr/include' )],
98+ os .getenv ('NLOHMANN_JSON_INCLUDE' , default = '/usr/include' ),
99+ os .getenv ('PROTOBUF_INCLUDE' , default = '' )
100+ ],
101+ # This might not be required:
87102 LIBS = ['comm' ],
88- LIBPATH = ['lib/' ]
89- )
103+
104+ # Pointing to $XYZ_LIB in LIBPATH and RPATH is a way for the executables
105+ # that will be linked with this lib to ibe able to find the correct
106+ # version of XYZ lib, even if serveral version of XYZ lib exists on the
107+ # system. (And to avoid potential coredumps when a wrong .so is used at
108+ # run-time.) If curious, do
109+ #
110+ # % ldd lib/libaperturedb-client.so | grep protobuf
111+ #
112+ # once the lib is build.
113+ LIBPATH = ['lib/' ,
114+ os .getenv ('PROTOBUF_LIB' , default = '' )
115+ ],
116+ )
117+
118+ client_env .Append (RPATH = client_env ['LIBPATH' ])
90119
91120compileProtoFiles (client_env )
92121
@@ -108,29 +137,46 @@ CXXFLAGS = env['CXXFLAGS']
108137
109138# Comm Testing
110139comm_test_env = Environment (
140+ ENV = {'PATH' : os .environ ['PATH' ]},
111141 CPPPATH = ['include' , 'src' ,
112142 os .getenv ('NLOHMANN_JSON_INCLUDE' , default = '/usr/include' ),
113143 os .getenv ('PROMETHEUS_CPP_CORE_INCLUDE' , default = '' ),
114144 os .getenv ('GLOG_INCLUDE' , default = '' ),
145+ os .getenv ('PROTOBUF_INCLUDE' , default = '' )
115146 ],
116147 LIBPATH = ['lib' ,
117148 os .getenv ('PROMETHEUS_CPP_LIB' , default = '' ),
118149 os .getenv ('GLOG_LIB' , default = '' ),
150+ os .getenv ('PROTOBUF_LIB' , default = '' )
119151 ],
120152 CXXFLAGS = CXXFLAGS ,
121- LIBS = [
122- 'aperturedb-client ' ,
153+ LIBS = ['aperturedb-client' ,
154+ 'prometheus-cpp-core ' ,
123155 'comm' ,
124- 'pthread' ,
125156 'gtest' ,
126157 'glog' ,
127- 'prometheus-cpp-core' ,
158+ 'protobuf' ,
159+ 'pthread' ,
128160 ],
129- RPATH = ['../lib' ]
130161 )
131162
163+ # Using RPATH causes the linker to record locations of shared libs inside the
164+ # executable, so that we do not need to either (a) copy the libs to standard
165+ # locations or (b) point to them in LD_LIBRARY_PATH. To check if this worked
166+ # correctly, do
167+ #
168+ # % ldd test/comm_test | grep 'not found'
169+ #
170+ # To check for which libs relative paths are used, do
171+ #
172+ # % ldd test/comm_test | grep '=>' | grep -v '=> /'
173+ #
174+ # For an info on RPATH, see the man page for 'ld'.
175+
176+ comm_test_env .Append (RPATH = comm_test_env ['LIBPATH' ])
177+
132178
133- comm_test_env .ParseConfig ('pkg-config --cflags --libs protobuf' )
179+ ## comm_test_env.ParseConfig('pkg-config --cflags --libs protobuf')
134180
135181comm_test_source_files = [
136182 'test/AuthEnabledVDMSServer.cc' ,
0 commit comments