summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cppbuild.cc85
-rw-r--r--libcppbuild.cc96
-rw-r--r--libcppbuild.h4
-rw-r--r--subdir/cppbuild2.cc125
4 files changed, 208 insertions, 102 deletions
diff --git a/cppbuild.cc b/cppbuild.cc
index b1b31ed..e68ac0b 100644
--- a/cppbuild.cc
+++ b/cppbuild.cc
@@ -23,9 +23,6 @@ Nested build configurations for for example unit-tests in a test folder
#include "test/cppbuild.cc"
*/
-std::vector<BuildConfiguration> configs()
-{
- reg(__FILE__);
/*
Glob convenience methods
std::string glob = getFilesInDir(...);
@@ -50,6 +47,10 @@ så kan man kalde f.eks. imageconvert
/*
Compiler selection per-target (for arm cross-compilation)
*/
+namespace
+{
+std::vector<BuildConfiguration> myConfigs()
+{
return
{
{
@@ -94,73 +95,13 @@ Compiler selection per-target (for arm cross-compilation)
"-pthread",
}
},
+ };
+}
- {
- .target = "src.a",
- .sources = {
- "drumgizmo/src/audiocache.cc",
- "drumgizmo/src/audiocacheeventhandler.cc",
- "drumgizmo/src/audiocachefile.cc",
- "drumgizmo/src/audiocacheidmanager.cc",
- "drumgizmo/src/audiofile.cc",
- "drumgizmo/src/audioinputengine.cc",
- "drumgizmo/src/audioinputenginemidi.cc",
- "drumgizmo/src/audiooutputengine.cc",
- "drumgizmo/src/bytesizeparser.cc",
- "drumgizmo/src/channel.cc",
- "drumgizmo/src/channelmixer.cc",
- "drumgizmo/src/configfile.cc",
- "drumgizmo/src/configparser.cc",
- "drumgizmo/src/dgxmlparser.cc",
- "drumgizmo/src/directory.cc",
- "drumgizmo/src/domloader.cc",
- "drumgizmo/src/drumgizmo.cc",
- "drumgizmo/src/drumgizmoconf.cc",
- "drumgizmo/src/drumkit.cc",
- "drumgizmo/src/drumkitloader.cc",
- "drumgizmo/src/events.cc",
- "drumgizmo/src/events_ds.cc",
- "drumgizmo/src/inputprocessor.cc",
- "drumgizmo/src/instrument.cc",
- "drumgizmo/src/latencyfilter.cc",
- "drumgizmo/src/midimapparser.cc",
- "drumgizmo/src/midimapper.cc",
- "drumgizmo/src/path.cc",
- "drumgizmo/src/powerlist.cc",
- "drumgizmo/src/powermap.cc",
- "drumgizmo/src/powermapfilter.cc",
- "drumgizmo/src/random.cc",
- "drumgizmo/src/sample.cc",
- "drumgizmo/src/sample_selection.cc",
- "drumgizmo/src/sem.cc",
- "drumgizmo/src/staminafilter.cc",
- "drumgizmo/src/thread.cc",
- "drumgizmo/src/translation.cc",
- "drumgizmo/src/velocityfilter.cc",
- "drumgizmo/src/versionstr.cc",
- "drumgizmo/src/zrwrapper.cc",
- },
- .depends = {},
- .cxxflags = {
- "-fPIC",
- "-DUI_X11",
- "-O3",
- "-g",
- "-Wall",
- "-Werror",
- "-std=c++11",
- "-Idrumgizmo/getoptpp",
- "-Idrumgizmo/",
- "-Idrumgizmo/hugin",
- "-Idrumgizmo/plugingui/",
- "-Idrumgizmo/src/",
- "-Idrumgizmo/zita-resampler/libs",
- "-Idrumgizmo/pugixml/src",
- },
- .cflags = {},
- .ldflags = {}
- },
-
+std::vector<BuildConfiguration> myConfigs2()
+{
+ return
+ {
{
.target = "libplugingui.so",
.sources = {
@@ -247,6 +188,10 @@ Compiler selection per-target (for arm cross-compilation)
},
.cflags = {},
.ldflags = {}
- },
+ }
};
}
+
+int a = reg(__FILE__, myConfigs);
+int b = reg(__FILE__, myConfigs2);
+}
diff --git a/libcppbuild.cc b/libcppbuild.cc
index b400061..d58705d 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -9,6 +9,7 @@
#include <memory>
#include <algorithm>
#include <list>
+#include <array>
#include <getoptpp/getoptpp.hpp>
@@ -83,35 +84,65 @@ std::shared_ptr<Task> getNextTask(const std::list<std::shared_ptr<Task>>& allTas
return nullptr;
}
-namespace
+struct Config
{
-// Hack to get command-line args for re-launch
-int g_argc;
-char** g_argv;
-}
+ const char* file;
+ std::vector<BuildConfiguration> (*cb)();
+};
+std::array<Config, 100> configFiles;
+int numConfigFiles{0};
// TODO: Use c++20 when ready, somehing like this:
//void reg(const std::source_location location =
// std::source_location::current())
-void reg(const std::string& location)
+int reg(const char* location,
+ std::vector<BuildConfiguration> (*cb)())
+{
+ // NOTE: std::cout cannot be used here
+ configFiles[numConfigFiles].file = location;
+ configFiles[numConfigFiles].cb = cb;
+ ++numConfigFiles;
+ return 0;
+}
+
+void recompileCheck(int argc, char* argv[])
{
- std::filesystem::path configFile(location);
- std::filesystem::path binFile(configFile.stem());
- if(std::filesystem::last_write_time(binFile) <=
- std::filesystem::last_write_time(configFile))
+ bool dirty{false};
+
+ std::vector<std::string> args;
+ args.push_back("-s");
+ args.push_back("-O3");
+ args.push_back("-std=c++17");
+ args.push_back("-pthread");
+
+ std::filesystem::path binFile("cppbuild");
+
+ std::cout << "Recompile check (" << numConfigFiles << "):\n";
+ for(int i = 0; i < numConfigFiles; ++i)
+ {
+ std::string location = configFiles[i].file;
+ std::cout << " - " << location << "\n";
+ std::filesystem::path configFile(location);
+ if(std::filesystem::last_write_time(binFile) <=
+ std::filesystem::last_write_time(configFile))
+ {
+ dirty = true;
+ }
+
+ // Support adding multiple config functions from the same file
+ if(std::find(args.begin(), args.end(), location) == std::end(args))
+ {
+ args.push_back(location);
+ }
+ }
+ args.push_back("libcppbuild.a");
+ args.push_back("-o");
+ args.push_back(binFile.string());
+
+ if(dirty)
{
std::cout << "Rebuilding config\n";
- auto ret = execute("/usr/bin/g++",
- {
- "-s",
- "-O3",
- "-std=c++17",
- "-pthread",
- configFile.string(),
- "libcppbuild.a",
- "-o",
- binFile.string(),
- });
+ auto ret = execute("/usr/bin/g++", args);
if(ret != 0)
{
std::cerr << "Failed.\n";
@@ -121,21 +152,18 @@ void reg(const std::string& location)
{
std::cout << "Re-launch\n";
std::vector<std::string> args;
- for(int i = 1; i < g_argc; ++i)
+ for(int i = 1; i < argc; ++i)
{
- args.push_back(g_argv[i]);
+ args.push_back(argv[i]);
}
- exit(execute(g_argv[0], args));
+ exit(execute(argv[0], args));
}
}
-
-// g++ -s -O3 -std=c++17 -pthread $0 libcppbuild.a -o cppbuild
}
int main(int argc, char* argv[])
{
- g_argc = argc;
- g_argv = argv;
+ recompileCheck(argc, argv);
Settings settings;
// TODO: Set from commandline
@@ -183,7 +211,17 @@ int main(int argc, char* argv[])
std::filesystem::path builddir(settings.builddir);
std::filesystem::create_directories(builddir);
- auto build_configs = configs();
+ std::vector<BuildConfiguration> build_configs;
+ for(int i = 0; i < numConfigFiles; ++i)
+ {
+ //std::string location = configFiles[i].file;
+ auto configs = configFiles[i].cb();
+ for(const auto& config : configs)
+ {
+ build_configs.push_back(config);
+ }
+ }
+
std::list<std::shared_ptr<Task>> tasks;
for(const auto& build_config : build_configs)
{
diff --git a/libcppbuild.h b/libcppbuild.h
index 98f6716..1076bb7 100644
--- a/libcppbuild.h
+++ b/libcppbuild.h
@@ -15,6 +15,4 @@ struct BuildConfiguration
std::vector<std::string> ldflags;
};
-std::vector<BuildConfiguration> configs();
-
-void reg(const std::string& location);
+int reg(const char* location, std::vector<BuildConfiguration> (*cb)());
diff --git a/subdir/cppbuild2.cc b/subdir/cppbuild2.cc
new file mode 100644
index 0000000..374319d
--- /dev/null
+++ b/subdir/cppbuild2.cc
@@ -0,0 +1,125 @@
+#if 0/*
+if [ "cppbuild" -ot "$0" ]
+then
+ echo "Rebuilding cppbuild"
+ g++ -s -O3 -std=c++17 -pthread $0 libcppbuild.a -o cppbuild
+ [ $? != 0 ] && exit 1
+fi
+
+echo "Launching cppbuild"
+./cppbuild $*
+exit $?
+*/
+#endif
+
+#include <vector>
+#include <string>
+#include <utility>
+
+#include "../libcppbuild.h"
+
+/*
+Nested build configurations for for example unit-tests in a test folder
+#include "test/cppbuild.cc"
+*/
+
+/*
+Glob convenience methods
+std::string glob = getFilesInDir(...);
+*/
+
+/*
+Compilation database
+https://clang.llvm.org/docs/JSONCompilationDatabase.html
+*/
+
+/*
+En feature mere kunne være: pre-post build hooks
+De vil kunne udtrykkes som intra-build dependencies
+Og så selvfølgelig med conditions
+*/
+
+/*
+Target som er "shell script" eller sådan noget
+så kan man kalde f.eks. imageconvert
+*/
+
+/*
+Compiler selection per-target (for arm cross-compilation)
+*/
+namespace
+{
+std::vector<BuildConfiguration> myConfigs()
+{
+ return
+ {
+ {
+ .target = "src.a",
+ .sources = {
+ "drumgizmo/src/audiocache.cc",
+ "drumgizmo/src/audiocacheeventhandler.cc",
+ "drumgizmo/src/audiocachefile.cc",
+ "drumgizmo/src/audiocacheidmanager.cc",
+ "drumgizmo/src/audiofile.cc",
+ "drumgizmo/src/audioinputengine.cc",
+ "drumgizmo/src/audioinputenginemidi.cc",
+ "drumgizmo/src/audiooutputengine.cc",
+ "drumgizmo/src/bytesizeparser.cc",
+ "drumgizmo/src/channel.cc",
+ "drumgizmo/src/channelmixer.cc",
+ "drumgizmo/src/configfile.cc",
+ "drumgizmo/src/configparser.cc",
+ "drumgizmo/src/dgxmlparser.cc",
+ "drumgizmo/src/directory.cc",
+ "drumgizmo/src/domloader.cc",
+ "drumgizmo/src/drumgizmo.cc",
+ "drumgizmo/src/drumgizmoconf.cc",
+ "drumgizmo/src/drumkit.cc",
+ "drumgizmo/src/drumkitloader.cc",
+ "drumgizmo/src/events.cc",
+ "drumgizmo/src/events_ds.cc",
+ "drumgizmo/src/inputprocessor.cc",
+ "drumgizmo/src/instrument.cc",
+ "drumgizmo/src/latencyfilter.cc",
+ "drumgizmo/src/midimapparser.cc",
+ "drumgizmo/src/midimapper.cc",
+ "drumgizmo/src/path.cc",
+ "drumgizmo/src/powerlist.cc",
+ "drumgizmo/src/powermap.cc",
+ "drumgizmo/src/powermapfilter.cc",
+ "drumgizmo/src/random.cc",
+ "drumgizmo/src/sample.cc",
+ "drumgizmo/src/sample_selection.cc",
+ "drumgizmo/src/sem.cc",
+ "drumgizmo/src/staminafilter.cc",
+ "drumgizmo/src/thread.cc",
+ "drumgizmo/src/translation.cc",
+ "drumgizmo/src/velocityfilter.cc",
+ "drumgizmo/src/versionstr.cc",
+ "drumgizmo/src/zrwrapper.cc",
+ },
+ .depends = {},
+ .cxxflags = {
+ "-fPIC",
+ "-DUI_X11",
+ "-O3",
+ "-g",
+ "-Wall",
+ "-Werror",
+ "-std=c++11",
+ "-Idrumgizmo/getoptpp",
+ "-Idrumgizmo/",
+ "-Idrumgizmo/hugin",
+ "-Idrumgizmo/plugingui/",
+ "-Idrumgizmo/src/",
+ "-Idrumgizmo/zita-resampler/libs",
+ "-Idrumgizmo/pugixml/src",
+ },
+ .cflags = {},
+ .ldflags = {}
+ }
+ };
+}
+
+int a = reg(__FILE__, myConfigs);
+}