Как сделать SConscript в Scons осведомленным о местоположении заголовка?

Я пытаюсь добавить модуль в игровой проект на основе Godot< /а>. Я хочу добавить модульные тесты с помощью doctest. Для простоты я буду использовать пример, приведенный в ссылке выше. Итак, я создал эту простую файловую структуру:

summator/
    include/
        summator.h
    src/ 
        summator.cpp
    tests/
        doctest.h
        summator_tests.cpp
        SCsub
    config.py
    register_types.h
    register_types.cpp
    SConstruct/SCsub

Последние четыре файла требуются Godot. Вот SConstruct/SCsub (второе имя файла необходимо для Godot, я использовал файл SConstruct для изолированного тестирования):

#!/usr/bin/env python

# import the environment provided by Godot
Import( 'env' )
# when tested in isolation, replace with following line
# env = Environment()

# add include directory to the search path 
env.Append( CPPPATH = [ '#include' ] ) # relative path

# add all cpp files so Scons can build the module
env.add_source_files( env.modules_sources, 'src/*.cpp' )
env.add_source_files( env.modules_sources, '*.cpp' )

# if tests are enabled, build them 
if env[ 'tests' ]:
    SConscript([ 'tests/SCsub' ])

Затем SConscript в summator/tests/ должен построить тесты:

#!/usr/bin/env python

Import( 'env' )

tests_env = env.Clone()

# build tests
tests = test_env.Program( 'runTest', Glob( '*.cpp' )

Когда я пытаюсь запустить это, я получаю сообщение об ошибке, что заголовок "summator.h" не может быть найден:

[ 99%] Compiling ==> modules/summator/tests/sumator_tests.cpp
modules/summator/tests/summator_tests.cpp:3:10: fatal error: 'summator.h' file not found
#include "summator.h"
         ^~~~~~~~~~~~~
1 error generated.
scons: *** [modules/summator/tests/summator_tests.linuxbsd.tools.64.llvm.o] Error 1
scons: building terminated because of errors.

Как я понимаю среды scons, после того, как я добавил к нему путь/файл, все SConscript (которые импортируют среду) могут получить к нему доступ. Что я делаю неправильно? Кажется, что это должно быть тривиально, но по какой-то причине это не сработает.

Вот другие исходные файлы для полноты:

// summator.h
#ifndef SUMMATOR_H
#define SUMMATOR_H

#include "core/reference.h"

class Summator : public Reference 
{
    GDCLASS( Summator, Reference );

    int count;

protected:
    static void _bind_methods();

public:
    void add( int p_value );
    void reset(); 
    int get_total() const;

    Summator();
};

#endif // SUMMATOR_H
// summator.cpp
#include "summator.h"

void Summator::add( int p_value )
{
    count += p_value;
}

void Summator::reset()
{
    count = 0;
}

int Summator::get_total() const 
{
    return count;
}

void Summator::_bind_methods()
{
    ClassDB::bind_method( D_METHOD( "add", "value" ), &Summator::add );
    ClassDB::bind_method( D_METHOD( "reset" ), &Summator::reset );
    ClassDB::bind_method( D_METHOD( "get_total" ), &Summator::get_total );
}

Summator::Summator()
{
    count = 0;
}
// summator_tests.cpp
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
// #include "thirdparty/doctest/doctest.h"
#include "summator.h"
#include "doctest.h"

TEST_CASE( "testing the summator" )
{
    // class under test
    Summator* cut = new Summator();

    cut->add(10);
    CHECK( cut->get_total() == 10 )
    cut->add(10);
    CHECK( cut->get_total() == 20 )
    cut->add(10);
    CHECK( cut->get_total() == 30 )
    cut->reset();
    CHECK( cut->get_total() == 0 )

    // clean up 
    delete cut;
}

person koalag    schedule 13.08.2020    source источник
comment
Работает ли он изолированно, но не в сборке Godot?   -  person bdbaddog    schedule 16.08.2020
comment
Спасибо за ответ, но я нашел решение!   -  person koalag    schedule 18.08.2020


Ответы (1)


После некоторых экспериментов я нашел работающее решение, ознакомьтесь с полным кодом в моем Репозиторий Github.

person koalag    schedule 18.08.2020
comment
Без перехода по ссылке невозможно получить даже представление о способе решения проблемы. Stack Overflow не рекомендует такие ответы, которые называются ответами только по ссылкам. Пожалуйста, добавьте хотя бы немного информации о решении в сам ответ. См. также Как ответить. - person Tsyvarev; 04.09.2020