Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_library(
"src/translateconfig.cpp"
"src/msvcenvironment.cpp"
"src/exampleproject.cpp"
"src/env.cpp"
)

add_subdirectory(lib/json.h)
Expand Down
8 changes: 5 additions & 3 deletions build-win-clang.bat
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

setlocal

mkdir "build"
mkdir "build\clang"

call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64

clang++.exe -Iinclude -Ilib/json.h/include -Isrc matmake.cpp -std=c++17 -o build/clang/matmake.exe
clang++.exe -Iinclude -Ilib/json.h/include -Isrc matmake.cpp -std=c++17 -o build/matmake2.exe -g

echo matmake created in build/clang
echo matmake created in build
7 changes: 4 additions & 3 deletions build-win-gcc.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

setlocal

mkdir "build"
mkdir "build\gcc"

g++ -Iinclude -Ilib/json.h/include -Isrc matmake.cpp -std=c++17 -o build/gcc/matmake.exe
g++ -Iinclude -Ilib/json.h/include -Isrc matmake.cpp -std=c++17 -o build/matmake2.exe

echo matmake created in build/g++
echo matmake created in build
13 changes: 8 additions & 5 deletions build-win-msvc.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

setlocal

mkdir build
mkdir "build\msvc"

cd build/msvc
cd build

call "%PROGRAMFILES(X86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64

cl.exe /I..\..\include /I..\..\lib/json.h/include /I..\..\src ..\..\matmake.cpp ^
/std:c++17 /EHa /D NOMINMAX /link /out:matmake.exe
cl.exe /I..\include /I..\lib/json.h/include /I..\src ..\matmake.cpp ^
/std:c++17 /EHa /D NOMINMAX /link /out:matmake2.exe /DEBUG:FULL

echo matmake created in build/

echo matmake created in build/msvc
cd ../
4 changes: 4 additions & 0 deletions demos/project1/Matmakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

main
src = src/*.cpp
out = main
config =
debug
c++17
command = [exe]
includes =
src
include

all
in = @main
1 change: 1 addition & 0 deletions matmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! Seems to speed up build around 4x

#include "src/defaultfile.cpp"
#include "src/env.cpp"
#include "src/exampleproject.cpp"
#include "src/matmakefile.cpp"
#include "src/msvcenvironment.cpp"
Expand Down
16 changes: 8 additions & 8 deletions src/createtasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,27 +207,27 @@ inline std::pair<TaskList, Task *> createTree(
style = task.flagStyle();
}
if (auto p = root.property("dir")) {
task.dir(BuildLocation::Real, p->value());
task.dir(BuildLocation::Real, p->path());
}
if (auto p = root.property("objdir")) {
task.dir(BuildLocation::Intermediate, p->value());
task.dir(BuildLocation::Intermediate, p->path());
}
if (auto p = root.property("cxx")) {
task.cxx(p->value());
task.cxx(p->path());
}
if (auto p = root.property("cc")) {
task.cc(p->value());
task.cc(p->path());
}
if (auto p = root.property("ar")) {
task.ar(p->value());
task.ar(p->path());
}
if (auto p = root.property("command")) {
task.command(p->value());
}
if (auto p = root.property("src")) {
// Requires command to be red before becauso of flag style
for (auto &src : p->values) {
auto paths = expandPaths(src);
auto paths = expandPaths(normalizePath(src));

for (auto &path : paths) {
if (auto f = duplicateMap.find(path); f != duplicateMap.end()) {
Expand Down Expand Up @@ -277,7 +277,7 @@ inline std::pair<TaskList, Task *> createTree(
}
}
if (auto p = root.property("out")) {
task.out(p->value());
task.out(p->path());
}
if (auto p = root.property("flags")) {
task.flags(p->concat());
Expand All @@ -294,7 +294,7 @@ inline std::pair<TaskList, Task *> createTree(
}
}
if (auto p = root.property(("depprefix"))) {
task.depfile(p->value());
task.depfile(p->path());
}
if (auto p = root.property("config")) {
task.config(p->values);
Expand Down
60 changes: 35 additions & 25 deletions src/defaultfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,46 @@ bool hasCommand(std::string command) {
std::to_string(__LINE__) +
" is not implemented "};
}
} // namespace
}

std::string getHighestClang() {
if (getOs() == Os::Windows) {
return "clang++.exe";
}

for (size_t i = 20; i > 2; --i) {
auto command = "clang++-" + std::to_string(i);
if (hasCommand(command)) {
return command;
}
}

return "clang++";
if (getOs() == Os::Windows) {
return "clang++.exe";
}

for (size_t i = 20; i > 2; --i) {
auto command = "clang++-" + std::to_string(i);
if (hasCommand(command)) {
return command;
}
}

return "clang++";
}

std::string getHighestGcc() {
if (getOs() == Os::Windows) {
return "g++.exe";
}

for (size_t i = 20; i > 2; --i) {
auto command = "g++-" + std::to_string(i);
if (hasCommand(command)) {
return command;
}
}

return "g++";
if (getOs() == Os::Windows) {
return "g++.exe";
}

for (size_t i = 20; i > 2; --i) {
auto command = "g++-" + std::to_string(i);
if (hasCommand(command)) {
return command;
}
}

return "g++";
}

void normalize(Json &json) {
#ifdef MATMAKE_USING_WINDOWS
for (auto &c : json.value) {
if (c == '/') {
c = '\\';
}
}
#endif
}

} // namespace
Expand Down
56 changes: 56 additions & 0 deletions src/env.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! This file handles all different ways to add to environment
//! Variables

#include "os.h"
#include <array>
#include <cstdlib>
#include <string>

#ifdef MATMAKE_USING_WINDOWS

#if defined(__MINGW32__) || defined(__CYGWIN__)

extern "C" int putenv(const char *);

void setenv(const char *name, const char *value, int overwrite) {
auto arg = std::string{name} + value;
putenv(arg.data());
}

std::string getEnvVar(std::string name) {
return getenv(name.c_str());
}

#else

#include <Windows.h>

int setenv(const char *name, const char *value, int overwrite) {
return -!SetEnvironmentVariableA(name, value);
}

std::string getEnvVar(std::string name) {
auto arr = std::array<char, 9000>{};

size_t size = GetEnvironmentVariableA(name.c_str(), arr.data(), arr.size());

return std::string(arr.data(), size);
}

#endif

#else

std::string getEnvVar(std::string name) {
return getenv(name.c_str());
}

#endif

void appendEnv(std::string name, std::string value) {
auto oldVar = getEnvVar(name);

value = oldVar + value;

setenv(name.c_str(), value.c_str(), 1);
}
5 changes: 5 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#include <string>

void appendEnv(std::string name, std::string value);
std::string getEnvVar(std::string name);
32 changes: 31 additions & 1 deletion src/filesystem.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "os.h"

#ifdef USE_EXPERIMENTAL_FILESYSTEM

// Se below
Expand Down Expand Up @@ -27,7 +29,8 @@ namespace filesystem = std::experimental::filesystem;

//! Compatabilityt function, that only removes the first part of a path,
//! It is enough for the usecases of this project though
inline filesystem::path compat_relative(filesystem::path path, filesystem::path base) {
inline filesystem::path compat_relative(filesystem::path path,
filesystem::path base) {
return path.string().substr(base.string().size());
}

Expand All @@ -39,3 +42,30 @@ inline filesystem::path compat_relative(filesystem::path path,
}

#endif

#ifdef MATMAKE_USING_WINDOWS

inline filesystem::path normalizePath(std::string path) {
for (auto &c : path) {
if (c == '/') {
c = '\\';
}
}
return filesystem::path{path};
}

inline filesystem::path normalizePath(filesystem::path path) {
return normalizePath(path.string());
}

#else

inline filesystem::path normalizePath(std::string path) {
return filesystem::path{path};
}

inline filesystem::path normalizePath(filesystem::path path) {
return path;
}

#endif
7 changes: 7 additions & 0 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ int main(int argc, char **argv) {
std::cerr << "error: " << e.what() << "\n";
return 1;
}
catch (std::exception &e) {
std::cerr << "error: " << e.what() << "\n";
}

catch (...) {
std::cerr << "unknown error\n";
}

return 0;
}
Loading