Как добавить исполняемый файл google test в файл SConstruct - PullRequest
0 голосов
/ 01 ноября 2019

Edit: после попытки заставить его работать в течение дня, я просто переписал его в cmake. Scons на самом деле не требуется для работы с родным языком.

У меня есть проект godot с некоторыми нативными (c ++) скриптами. Я хотел бы добавить юнит-тесты google-test для классов c ++.

scons совершенно новый для меня, и мне трудно докучать по документации. С существующим файлом SConstruct, как я могу добавить новый тестовый объект Google, который использует исходные файлы в моих native/test каталогах (несколько слоев подкаталогов) и ссылки на мою существующую библиотеку?

Я хотел быиспользуйте VariantDir, чтобы сохранить объектные файлы в исходных каталогах тестов.

Целевые строки теста расположены почти снизу, я включил весь файл для контекста.

#!python
import os, subprocess

opts = Variables([], ARGUMENTS)

projectName = 'mygame'
projectPrettyName = 'MyGame'

# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()

# compilation database support
env.Tool("compilation_db")
env.Alias("compiledb", env.CompilationDatabase('compile_commands.json'))

# Define our options
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
opts.Add(EnumVariable('platform', "Compilation platform", 'linux', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", 'linux', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'yes'))
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', projectName + '.godot/bin/'))
opts.Add(PathVariable('target_name', 'The library name.', 'lib' + projectName, PathVariable.PathAccept))

# Local dependency paths, adapt them to your setup
godot_headers_path = "godot-cpp/godot_headers/"
cpp_bindings_path = "godot-cpp/"
cpp_library = "libgodot-cpp"

# only support 64 at this time..
bits = 64

# Updates the environment with the option variables.
opts.Update(env)

# Process some arguments
if env['use_llvm']:
    env['CC'] = 'clang'
    env['CXX'] = 'clang++'

if env['p'] != '':
    env['platform'] = env['p']

if env['platform'] == '':
    print("No valid target platform selected.")
    quit();

# Check our platform specifics
if env['platform'] == "osx":
    env['target_path'] += 'osx/'
    cpp_library += '.osx'
    if env['target'] in ('debug', 'd'):
        env.Append(CCFLAGS=['-g', '-O2', '-arch', 'x86_64'])
        env.Append(LINKFLAGS=['-arch', 'x86_64'])
    else:
        env.Append(CCFLAGS=['-g', '-O3', '-arch', 'x86_64'])
        env.Append(LINKFLAGS=['-arch', 'x86_64'])

elif env['platform'] in ('x11', 'linux'):
    env['target_path'] += 'x11/'
    cpp_library += '.linux'
    if env['target'] in ('debug', 'd'):
        env.Append(CCFLAGS=['-fPIC', '-g3', '-Og'])
        env.Append(CXXFLAGS=['-std=c++17'])
    else:
        env.Append(CCFLAGS=['-fPIC', '-g', '-O3'])
        env.Append(CXXFLAGS=['-std=c++17'])

elif env['platform'] == "windows":
    env['target_path'] += 'win64/'
    cpp_library += '.windows'
    # This makes sure to keep the session environment variables on windows,
    # that way you can run scons in a vs 2017 prompt and it will find all the required tools
    env.Append(ENV=os.environ)

    env.Append(CPPDEFINES=['WIN32', '_WIN32', '_WINDOWS', '_CRT_SECURE_NO_WARNINGS'])
    env.Append(CCFLAGS=['-W3', '-GR'])
    if env['target'] in ('debug', 'd'):
        env.Append(CPPDEFINES=['_DEBUG'])
        env.Append(CCFLAGS=['-EHsc', '-MDd', '-ZI'])
        env.Append(LINKFLAGS=['-DEBUG'])
    else:
        env.Append(CPPDEFINES=['NDEBUG'])
        env.Append(CCFLAGS=['-O2', '-EHsc', '-MD'])

if env['target'] in ('release', 'r'):
    cpp_library += '.release'
else:
    cpp_library += '.debug'

cpp_library += '.' + str(bits)

# make sure our binding library is properly includes
env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
env.Append(LIBS=[cpp_library])

env.Append(CPPPATH=['native/include/'])
env.VariantDir('#build/', 'native/src', duplicate=0)
sources = Glob('#build/**.cpp')

libPath = target=env['target_path'] + env['target_name']
library = env.SharedLibrary(libPath, source=sources)

# Test target description: Help needed here
env.VariantDir('#tbuild/', 'native/test', duplicate=0) # ???
testsources = Glob('#tbuild/*cpp') # ???
tests = env.Program(???)

Default(library, 'compiledb')
...