Start working on build system.
This commit is contained in:
parent
4b308f6c32
commit
521486be62
88 changed files with 1065 additions and 349 deletions
25
src/base/compiler/BuildLibrary.cpp
Normal file
25
src/base/compiler/BuildLibrary.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "BuildLibrary.h"
|
||||
|
||||
#include "Logger.h"
|
||||
#include "Directory.h"
|
||||
|
||||
BuildLibrary::BuildLibrary(const FileSystemPath& build_config)
|
||||
: m_build_config(build_config)
|
||||
{
|
||||
}
|
||||
|
||||
Status BuildLibrary::scan()
|
||||
{
|
||||
LOG_INFO("Scanning build file at: " << m_build_config);
|
||||
const auto search_dir = m_build_config.parent_path();
|
||||
const auto status = Directory::getFilesWithExtension(search_dir,
|
||||
".cpp",
|
||||
m_sources,
|
||||
true);
|
||||
return status;
|
||||
}
|
||||
|
||||
const Vector<FileSystemPath>& BuildLibrary::get_sources() const
|
||||
{
|
||||
return m_sources;
|
||||
}
|
22
src/base/compiler/BuildLibrary.h
Normal file
22
src/base/compiler/BuildLibrary.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "FileSystemPath.h"
|
||||
#include "String.h"
|
||||
|
||||
class BuildLibrary
|
||||
{
|
||||
public:
|
||||
BuildLibrary() = default;
|
||||
|
||||
BuildLibrary(const FileSystemPath& build_config);
|
||||
|
||||
Status scan();
|
||||
|
||||
const Vector<FileSystemPath>& get_sources() const;
|
||||
|
||||
private:
|
||||
FileSystemPath m_build_config;
|
||||
Vector<FileSystemPath> m_sources;
|
||||
Vector<FileSystemPath> m_includes;
|
||||
String m_name;
|
||||
};
|
73
src/base/compiler/BuildSession.cpp
Normal file
73
src/base/compiler/BuildSession.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "BuildSession.h"
|
||||
|
||||
#include "Logger.h"
|
||||
#include "Process.h"
|
||||
#include "Directory.h"
|
||||
|
||||
BuildSession::BuildSession(const String& source_dir,
|
||||
const String& build_dir)
|
||||
: m_source_dir(source_dir)
|
||||
{
|
||||
if (build_dir.empty())
|
||||
{
|
||||
m_build_dir = FileSystemPath::current_dir().value();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_build_dir = build_dir;
|
||||
}
|
||||
}
|
||||
|
||||
Status BuildSession::scan()
|
||||
{
|
||||
LOG_INFO("Scanning sources at:" << m_source_dir);
|
||||
Vector<FileSystemPath> toml_files;
|
||||
STATUS_CHECK(Directory::getFilesWithExtension(
|
||||
m_source_dir,
|
||||
".toml",
|
||||
toml_files,
|
||||
true), "Error looking for build files");
|
||||
|
||||
for(const auto& toml_file : toml_files)
|
||||
{
|
||||
if (toml_file.file_name() == "build")
|
||||
{
|
||||
STATUS_CHECK(add_library(toml_file),
|
||||
"Error adding library");
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
||||
}
|
||||
|
||||
Status BuildSession::add_library(const FileSystemPath& config_path)
|
||||
{
|
||||
LOG_INFO("Adding library at: " << config_path);
|
||||
BuildLibrary lib(config_path);
|
||||
STATUS_CHECK(lib.scan(), "Error scanning library");
|
||||
m_libraries.push_back(lib);
|
||||
return {};
|
||||
}
|
||||
|
||||
Status BuildSession::build()
|
||||
{
|
||||
for(const auto& library : m_libraries)
|
||||
{
|
||||
for(const auto& source : library.get_sources())
|
||||
{
|
||||
String compiler_command = m_compiler_command + " -c ";
|
||||
compiler_command += source.str() + " ";
|
||||
LOG_INFO("Running command: " << compiler_command);
|
||||
|
||||
const auto self_name = Process::get_self_name();
|
||||
if (!self_name.ok())
|
||||
{
|
||||
return Status(self_name.error());
|
||||
}
|
||||
LOG_INFO("Self name is: " << self_name.value());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
24
src/base/compiler/BuildSession.h
Normal file
24
src/base/compiler/BuildSession.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "BuildLibrary.h"
|
||||
#include "Error.h"
|
||||
|
||||
class BuildSession
|
||||
{
|
||||
public:
|
||||
BuildSession(const String& source_dir,
|
||||
const String& build_dir = {});
|
||||
|
||||
Status scan();
|
||||
|
||||
Status build();
|
||||
|
||||
Status add_library(const FileSystemPath& config_path);
|
||||
|
||||
private:
|
||||
String m_compiler_command{"g++"};
|
||||
String m_compiler_flags{"-g -fno-exceptions -fno-rtti"};
|
||||
FileSystemPath m_source_dir;
|
||||
FileSystemPath m_build_dir;
|
||||
Vector<BuildLibrary> m_libraries;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue