unity build! but not like that kind
This commit is contained in:
80
nob.c
80
nob.c
@@ -5,12 +5,11 @@
|
||||
#include "nob.h"
|
||||
|
||||
#define BUILD_DIR "build"
|
||||
#define IMGUI_LIB BUILD_DIR "/imgui.lib"
|
||||
#define IMGUI_LIB_DEBUG BUILD_DIR "/imgui_d.lib"
|
||||
#define IMGUI_LIB_RELEASE BUILD_DIR "/imgui.lib"
|
||||
|
||||
static const char *src_files[] = {
|
||||
"src/main.cpp",
|
||||
"src/platform/platform_win32.cpp",
|
||||
"src/renderer/renderer_dx12.cpp",
|
||||
};
|
||||
|
||||
static const char *imgui_files[] = {
|
||||
@@ -34,27 +33,35 @@ static const char *link_libs[] = {
|
||||
"dwmapi.lib",
|
||||
};
|
||||
|
||||
static bool build_imgui_lib(void) {
|
||||
int need = nob_needs_rebuild(IMGUI_LIB, imgui_files, NOB_ARRAY_LEN(imgui_files));
|
||||
static const char *obj_name(const char *src_path) {
|
||||
const char *slash = strrchr(src_path, '/');
|
||||
const char *name = slash ? slash + 1 : src_path;
|
||||
size_t len = strlen(name);
|
||||
return nob_temp_sprintf("%s/%.*s.obj", BUILD_DIR, (int)(len - 4), name);
|
||||
}
|
||||
|
||||
static bool build_imgui_lib(bool debug) {
|
||||
const char *lib_path = debug ? IMGUI_LIB_DEBUG : IMGUI_LIB_RELEASE;
|
||||
|
||||
int need = nob_needs_rebuild(lib_path, imgui_files, NOB_ARRAY_LEN(imgui_files));
|
||||
if (need < 0) return false;
|
||||
if (!need) {
|
||||
nob_log(NOB_INFO, "%s is up to date", IMGUI_LIB);
|
||||
nob_log(NOB_INFO, "%s is up to date", lib_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
nob_log(NOB_INFO, "Building %s...", IMGUI_LIB);
|
||||
nob_log(NOB_INFO, "Building %s...", lib_path);
|
||||
|
||||
// Compile each imgui source to .obj
|
||||
Nob_Cmd cmd = {0};
|
||||
nob_cmd_append(&cmd, "cl.exe");
|
||||
nob_cmd_append(&cmd, "/nologo", "/std:c++17", "/EHsc", "/W3", "/c");
|
||||
nob_cmd_append(&cmd, "/Ivendor/imgui", "/Ivendor/imgui/backends");
|
||||
|
||||
#ifdef _DEBUG
|
||||
nob_cmd_append(&cmd, "/Zi", "/Od", "/D_DEBUG");
|
||||
#else
|
||||
nob_cmd_append(&cmd, "/O2", "/DNDEBUG");
|
||||
#endif
|
||||
if (debug) {
|
||||
nob_cmd_append(&cmd, "/Zi", "/Od", "/D_DEBUG");
|
||||
} else {
|
||||
nob_cmd_append(&cmd, "/O2", "/DNDEBUG");
|
||||
}
|
||||
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/Fo:%s/", BUILD_DIR));
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/Fd:%s/", BUILD_DIR));
|
||||
@@ -67,26 +74,16 @@ static bool build_imgui_lib(void) {
|
||||
// Archive .obj files into a .lib
|
||||
cmd.count = 0;
|
||||
nob_cmd_append(&cmd, "lib.exe", "/nologo");
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/OUT:%s", IMGUI_LIB));
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/OUT:%s", lib_path));
|
||||
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++) {
|
||||
const char *base = nob_temp_sprintf("%s", imgui_files[i]);
|
||||
const char *slash = strrchr(base, '/');
|
||||
const char *name = slash ? slash + 1 : base;
|
||||
size_t len = strlen(name);
|
||||
char *obj = nob_temp_sprintf("%s/%.*s.obj", BUILD_DIR, (int)(len - 4), name);
|
||||
nob_cmd_append(&cmd, obj);
|
||||
}
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++)
|
||||
nob_cmd_append(&cmd, obj_name(imgui_files[i]));
|
||||
|
||||
if (!nob_cmd_run(&cmd)) return false;
|
||||
|
||||
// Clean up imgui .obj files
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++) {
|
||||
const char *slash = strrchr(imgui_files[i], '/');
|
||||
const char *name = slash ? slash + 1 : imgui_files[i];
|
||||
size_t len = strlen(name);
|
||||
nob_delete_file(nob_temp_sprintf("%s/%.*s.obj", BUILD_DIR, (int)(len - 4), name));
|
||||
}
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(imgui_files); i++)
|
||||
nob_delete_file(obj_name(imgui_files[i]));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -94,10 +91,15 @@ static bool build_imgui_lib(void) {
|
||||
int main(int argc, char **argv) {
|
||||
NOB_GO_REBUILD_URSELF(argc, argv);
|
||||
|
||||
bool debug = false;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "debug") == 0) debug = true;
|
||||
}
|
||||
|
||||
if (!nob_mkdir_if_not_exists(BUILD_DIR)) return 1;
|
||||
|
||||
// Build vendor libs (unless already built)
|
||||
if (!build_imgui_lib()) return 1;
|
||||
if (!build_imgui_lib(debug)) return 1;
|
||||
|
||||
// Compile and link
|
||||
Nob_Cmd cmd = {0};
|
||||
@@ -106,11 +108,11 @@ int main(int argc, char **argv) {
|
||||
nob_cmd_append(&cmd, "/nologo", "/std:c++17", "/EHsc", "/W3");
|
||||
nob_cmd_append(&cmd, "/Isrc", "/Ivendor/imgui", "/Ivendor/imgui/backends");
|
||||
|
||||
#ifdef _DEBUG
|
||||
nob_cmd_append(&cmd, "/Zi", "/Od", "/D_DEBUG");
|
||||
#else
|
||||
nob_cmd_append(&cmd, "/Zi", "/O2", "/DNDEBUG");
|
||||
#endif
|
||||
if (debug) {
|
||||
nob_cmd_append(&cmd, "/Zi", "/Od", "/D_DEBUG");
|
||||
} else {
|
||||
nob_cmd_append(&cmd, "/Zi", "/O2", "/DNDEBUG");
|
||||
}
|
||||
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/Fe:%s/autosample.exe", BUILD_DIR));
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/Fo:%s/", BUILD_DIR));
|
||||
@@ -123,19 +125,15 @@ int main(int argc, char **argv) {
|
||||
nob_cmd_append(&cmd, "/SUBSYSTEM:CONSOLE");
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf("/PDB:%s/autosample.pdb", BUILD_DIR));
|
||||
nob_cmd_append(&cmd, "/DEBUG");
|
||||
nob_cmd_append(&cmd, IMGUI_LIB);
|
||||
nob_cmd_append(&cmd, debug ? IMGUI_LIB_DEBUG : IMGUI_LIB_RELEASE);
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(link_libs); i++)
|
||||
nob_cmd_append(&cmd, link_libs[i]);
|
||||
|
||||
if (!nob_cmd_run(&cmd)) return 1;
|
||||
|
||||
// Clean up .obj files
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(src_files); i++) {
|
||||
const char *slash = strrchr(src_files[i], '/');
|
||||
const char *name = slash ? slash + 1 : src_files[i];
|
||||
size_t len = strlen(name);
|
||||
nob_delete_file(nob_temp_sprintf("%s/%.*s.obj", BUILD_DIR, (int)(len - 4), name));
|
||||
}
|
||||
for (size_t i = 0; i < NOB_ARRAY_LEN(src_files); i++)
|
||||
nob_delete_file(obj_name(src_files[i]));
|
||||
|
||||
nob_log(NOB_INFO, "Build complete: %s/autosample.exe", BUILD_DIR);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user