Răsfoiți Sursa

add test method to build test, link gtest and gmock lib

tanghai 15 ani în urmă
părinte
comite
10fdaa3b85
3 a modificat fișierele cu 29 adăugiri și 17 ștergeri
  1. 28 15
      SConstruct
  2. 0 1
      src/SConscript
  3. 1 1
      src/thread/SConscript

+ 28 - 15
SConstruct

@@ -1,38 +1,51 @@
 env = DefaultEnvironment()
 env = DefaultEnvironment()
 
 
 def ParseOptions():
 def ParseOptions():
-	AddOption('--opt',
-		dest='opt',
-		action='store_true',
-		default='false',
+	AddOption('--mode',
+		dest='mode',
+		action='store',
+		type='string',
+		default='dbg',
 		help='build in opt mode, default dbg mode')
 		help='build in opt mode, default dbg mode')
+	AddOption("--ntest",
+    action="store_true",
+    dest="ntest",
+    default=False,
+    help="dont build test")
 
 
 ParseOptions()
 ParseOptions()
 
 
-env.Append(LIBPATH=[
-	'/usr/local/lib'
-])
-
 env.Append(LIBS=[
 env.Append(LIBS=[
 	'gflags',
 	'gflags',
 	'glog',
 	'glog',
-	'gtest',
-	'gmock',
 ])
 ])
 
 
-if GetOption('opt') == True:
-	env['root'] = 'opt'
+env['MODE'] = GetOption('mode')
+env['NTEST'] = GetOption('ntest')
+
+if env['MODE'] == 'opt':
 	env.Append(CCFLAGS='-O2 -g')
 	env.Append(CCFLAGS='-O2 -g')
 	env.Append(LIBS='tcmalloc')
 	env.Append(LIBS='tcmalloc')
 else:
 else:
-	env['root'] = 'dbg'
 	env.Append(CCFLAGS='-g')
 	env.Append(CCFLAGS='-g')
 	env.Append(LIBS='tcmalloc_debug')
 	env.Append(LIBS='tcmalloc_debug')
 
 
-env.Append(CPPPATH=Dir(env['root']).abspath)
+env.Append(CPPPATH=Dir(env['MODE']).abspath)
+
+def Test(env, target, source):
+	if env['NTEST']:
+		return
+	test_env = env.Clone()
+	test_env.Append(LIBS=[
+		'gtest',
+		'gmock',
+	])
+	test_target = test_env.Program(target, source)
+	return test_target
 
 
+env.AddMethod(Test, 'Test')
 
 
 Export('env')
 Export('env')
 
 
-SConscript('src/SConscript', variant_dir=env['root'])
+SConscript('src/SConscript', variant_dir=env['MODE'])
 
 

+ 0 - 1
src/SConscript

@@ -3,7 +3,6 @@ Import('env')
 subdirs = [
 subdirs = [
 	'experimental',
 	'experimental',
 	'thread',
 	'thread',
-	'net',
 ]
 ]
 
 
 for subdir in subdirs:
 for subdir in subdirs:

+ 1 - 1
src/thread/SConscript

@@ -14,4 +14,4 @@ thread_lib = thread_env.StaticLibrary('thread', thread_src)
 
 
 thread_env.Append(LIBS=thread_lib)
 thread_env.Append(LIBS=thread_lib)
 
 
-thread_env.Program('thread_pool_test.cc')
+thread_env.Test('thread_pool_test', 'thread_pool_test.cc')