finish cmake interop
This commit is contained in:
parent
ca96457590
commit
6b3ca366bf
65
:w
Normal file
65
:w
Normal file
|
@ -0,0 +1,65 @@
|
|||
#pragma once
|
||||
#include "grbc/spec.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum GeneratorTargetType {
|
||||
GeneratorTargetType_Executable,
|
||||
GeneratorTargetType_SharedLibrary,
|
||||
GeneratorTargetType_StaticLibrary
|
||||
};
|
||||
|
||||
struct GeneratorResult {
|
||||
std::string file_name;
|
||||
std::string content;
|
||||
};
|
||||
|
||||
struct GeneratorCompileCommand {
|
||||
LanguageType language_type;
|
||||
|
||||
std::string source_file;
|
||||
std::string object_file;
|
||||
|
||||
std::string compiler_flags;
|
||||
};
|
||||
|
||||
struct GeneratorLinkTargetCommand {
|
||||
std::vector<std::string> object_files;
|
||||
std::vector<std::string> libraries; // Libraries which need to be built before this
|
||||
std::string linker_flags;
|
||||
|
||||
std::string output_name;
|
||||
|
||||
GeneratorTargetType target_type;
|
||||
};
|
||||
|
||||
struct GeneratorExternalTargetCommand {
|
||||
|
||||
};
|
||||
|
||||
struct GeneratorTarget {
|
||||
std::vector<GeneratorCompileCommand> compile_commands;
|
||||
std::vector<GeneratorLinkTargetCommand> link_target_commands;
|
||||
std::vector<GeneratorExternalTargetCommand> external_target_commands;
|
||||
};
|
||||
|
||||
struct GeneratorTask {
|
||||
std::string description, id;
|
||||
|
||||
std::string shell_script;
|
||||
};
|
||||
|
||||
typedef GeneratorResult (*Generator_Run)();
|
||||
|
||||
struct Generator {
|
||||
/// Name of the generator, used in grbc_build(...)
|
||||
std::string name;
|
||||
|
||||
/// Function pointer for this generator
|
||||
Generator_Run func;
|
||||
};
|
||||
|
||||
/**
|
||||
* Ninja generator main function
|
||||
*/
|
||||
GeneratorResult ninja_generator();
|
|
@ -1,5 +1,5 @@
|
|||
### GENERATED BY THE GRBC BUILT-IN NINJA GENERATOR ###
|
||||
### GENERATED ON: 1728828711 ###
|
||||
### GENERATED ON: 1728829359 ###
|
||||
|
||||
## Default variables ##
|
||||
|
||||
|
@ -155,7 +155,7 @@ build $builddir/src/main.o: cxx src/main.cc
|
|||
## Link: grbc ##
|
||||
|
||||
build $builddir/grbc: link_cxx $builddir/src/main.o | $builddir/libgrbc.a $builddir/libgrbc_extensions.a $builddir/libhotwire.a $builddir/libcjson.a
|
||||
p_linker_flags = -llua -lm -ldl build/libgrbc.a build/libgrbc_extensions.a build/libhotwire.a build/libcjson.a -L/tmp/SDL/grbc_configure /tmp/SDL/grbc_configure/libSDL3.so.0.1.5 -O3 -DNDEBUG -Lbuild -Wl,-rpath,build:.
|
||||
p_linker_flags = -llua -lm -ldl build/libgrbc.a build/libgrbc_extensions.a build/libhotwire.a build/libcjson.a build/libSDL3.so.0.1.5 -O3 -DNDEBUG -Lbuild -Wl,-rpath,build:.
|
||||
p_cflags =
|
||||
|
||||
## clean ##
|
||||
|
|
|
@ -27,8 +27,6 @@ struct GState {
|
|||
std::string global_compiler_flags = "";
|
||||
std::string global_linker_flags = " ";
|
||||
|
||||
std::string ninja_output;
|
||||
|
||||
static GState &get() {
|
||||
static GState state{};
|
||||
|
||||
|
|
|
@ -86,15 +86,23 @@ CMakeProject EXT_grbc_import_cmake(const std::string &cmake_path,
|
|||
|
||||
// Collect compilation database
|
||||
FILE *compdb = popen("ninja -t compdb", "r");
|
||||
|
||||
std::string compdb_raw = cmake_util_read_file(compdb);
|
||||
|
||||
pclose(compdb);
|
||||
|
||||
project.compdb = cJSON_Parse(compdb_raw.c_str());
|
||||
|
||||
// Build the cmake subproject, we need this so we can copy artifacts later on in the build step
|
||||
|
||||
grbc_log("building cmake subproject...");
|
||||
int build_exit_code = std::system("ninja");
|
||||
|
||||
if (build_exit_code != EXIT_SUCCESS)
|
||||
grbc_exception("Failed to build cmake project in: " + project.build_dir);
|
||||
|
||||
std::filesystem::current_path(old_path);
|
||||
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
|
@ -139,8 +147,7 @@ Package EXT_grbc_get_cmake_library(const CMakeProject &self,
|
|||
|
||||
Package pkg{};
|
||||
pkg.name = output_name;
|
||||
pkg.linker_flags =
|
||||
"-L" + self.build_dir + " " + full_lib_path.generic_string();
|
||||
pkg.linker_flags = grbc_get_config().build_dir + "/" + full_lib_path.filename().generic_string();
|
||||
|
||||
grbc_log("found cmake library at: " + full_lib_path.generic_string());
|
||||
|
||||
|
@ -167,12 +174,16 @@ std::string EXT_grbc_get_cmake_library_string(const CMakeProject &self) {
|
|||
if (!cJSON_HasObjectItem(compdb_item, "file"))
|
||||
grbc_exception("Compilation database item is missing 'file'");
|
||||
|
||||
std::string cmd = cJSON_GetStringValue(cJSON_GetObjectItem(compdb_item, "command"));
|
||||
std::string cmd =
|
||||
cJSON_GetStringValue(cJSON_GetObjectItem(compdb_item, "command"));
|
||||
|
||||
if (!cmd.empty()) continue;
|
||||
if (!cmd.empty())
|
||||
continue;
|
||||
|
||||
std::string file = cJSON_GetStringValue(cJSON_GetObjectItem(compdb_item, "file"));
|
||||
std::string output = cJSON_GetStringValue(cJSON_GetObjectItem(compdb_item, "output"));
|
||||
std::string file =
|
||||
cJSON_GetStringValue(cJSON_GetObjectItem(compdb_item, "file"));
|
||||
std::string output =
|
||||
cJSON_GetStringValue(cJSON_GetObjectItem(compdb_item, "output"));
|
||||
|
||||
library_string += "Target: " + output + "\n";
|
||||
library_string += "\tOutputting to file: " + output + "\n\n";
|
||||
|
|
Loading…
Reference in a new issue