Merge pull request #20 from GodotNativeTools/static-linking

Use static linking instead of dynamic linking
pull/21/head
Thomas Herzog 2017-07-24 04:52:18 +02:00 committed by GitHub
commit 2195f2e9a8
23 changed files with 64 additions and 303 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
src/*.cpp
src/*.hpp
include/*.hpp
*.o
*.os
*.so
*.obj

View File

@ -32,73 +32,43 @@ if platform == "osx":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
if target == "core":
if platform == "linux":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14'])
if platform == "linux":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14'])
env.Append(CPPPATH=['.', godot_headers_path, 'include', 'include/core'])
if platform == "windows":
env.Append(LIBS=[godot_name])
env.Append(LIBPATH=[godot_lib_path])
sources = []
add_sources(sources, "src/core")
env.Append(CPPPATH=['include/core', godot_headers_path])
if ARGUMENTS.get("generate_bindings", "no") == "yes":
godot_executable = godot_bin_path + godot_name
if env["CXX"] == "clang++":
godot_executable += ".llvm"
if platform == "windows":
env.Append(LIBS=[godot_name + '.lib'])
env.Append(LIBPATH=[godot_lib_path])
godot_executable += ".exe"
env.Append(CPPFLAGS=['-D_GD_CPP_CORE_API_IMPL'])
# TODO Generating the API should be done only if the Godot build is more recent than the JSON file
json_api_file = 'godot_api.json'
sources = []
add_sources(sources, "src/core")
subprocess.call([godot_executable, '--gdnative-generate-json-api', json_api_file])
library = env.SharedLibrary(target='bin/godot_cpp_core', source=sources)
Default(library)
# actually create the bindings here
import binding_generator
elif target == "bindings":
if ARGUMENTS.get("generate_bindings", "no") == "yes":
godot_executable = godot_bin_path + godot_name
if env["CXX"] == "clang++":
godot_executable += ".llvm"
if platform == "windows":
godot_executable += ".exe"
# TODO Generating the API should be done only if the Godot build is more recent than the JSON file
json_api_file = 'godot_api.json'
subprocess.call([godot_executable, '--gdnative-generate-json-api', json_api_file])
# actually create the bindings here
import binding_generator
binding_generator.generate_bindings(json_api_file)
binding_generator.generate_bindings(json_api_file)
add_sources(sources, "src")
if platform == "linux":
if env["CXX"] == "clang++":
env.Append(CCFLAGS = ['-Wno-writable-strings'])
else:
env.Append(CCFLAGS = ['-Wno-write-strings', '-Wno-return-local-addr'])
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14'])
env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\''])
env.Append(CPPPATH=['.', godot_headers_path, 'include', 'include/core'])
if platform == "windows":
env.Append(LIBS=[godot_name])
env.Append(LIBPATH=[godot_lib_path])
env.Append(LIBS=['godot_cpp_core'])
env.Append(LIBPATH=['bin'])
env.Append(CPPFLAGS=['-D_GD_CPP_BINDING_IMPL'])
sources = []
add_sources(sources, "src")
library = env.SharedLibrary(target='bin/godot_cpp_bindings', source=sources)
Default(library)
library = env.StaticLibrary(target='bin/godot_cpp_bindings', source=sources)
Default(library)

View File

@ -62,18 +62,6 @@ def generate_class_header(used_classes, c):
source.append("#ifndef GODOT_CPP_" + strip_name(c["name"]).upper() + "_HPP")
source.append("#define GODOT_CPP_" + strip_name(c["name"]).upper() + "_HPP")
source.append("")
source.append("#if defined(_WIN32) && defined(_GD_CPP_BINDING_IMPL)")
source.append("# define GD_CPP_BINDING_API __declspec(dllexport)")
source.append("#elif defined(_WIN32)")
source.append("# define GD_CPP_BINDING_API __declspec(dllimport)")
source.append("#else")
source.append("# define GD_CPP_BINDING_API")
source.append("#endif");
source.append("")
source.append("")
source.append("")
source.append("")
source.append("#include <godot.h>")
@ -101,7 +89,7 @@ def generate_class_header(used_classes, c):
# generate the class definition here
source.append("class GD_CPP_BINDING_API " + strip_name(c["name"]) + ("" if c["base_class"] == "" else (" : public " + strip_name(c["base_class"])) ) + " {")
source.append("class " + strip_name(c["name"]) + ("" if c["base_class"] == "" else (" : public " + strip_name(c["base_class"])) ) + " {")
source.append("public:")
source.append("")
@ -253,7 +241,7 @@ def generate_class_implementation(icalls, used_classes, c):
source.append("static inline void ___singleton_init()")
source.append("{")
source.append("\tif (" + core_object_name + " == nullptr) {")
source.append("\t\t" + core_object_name + " = godot_global_get_singleton(\"" + strip_name(c["name"]) + "\");")
source.append("\t\t" + core_object_name + " = godot_global_get_singleton((char *) \"" + strip_name(c["name"]) + "\");")
source.append("\t}")
source.append("}")
@ -265,7 +253,7 @@ def generate_class_implementation(icalls, used_classes, c):
if c["instanciable"]:
source.append("void *" + strip_name(c["name"]) + "::operator new(size_t)")
source.append("{")
source.append("\treturn godot_get_class_constructor(\"" + c["name"] + "\")();")
source.append("\treturn godot_get_class_constructor((char *)\"" + c["name"] + "\")();")
source.append("}")
source.append("void " + strip_name(c["name"]) + "::operator delete(void *ptr)")

View File

@ -1,16 +1,6 @@
#ifndef ARRAY_H
#define ARRAY_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_array.h>
#include "String.hpp"
@ -28,7 +18,7 @@ class PoolColorArray;
class Object;
class GD_CPP_CORE_API Array {
class Array {
godot_array _godot_array;
public:
Array();

View File

@ -1,16 +1,6 @@
#ifndef BASIS_H
#define BASIS_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Defs.hpp"
#include "Vector3.hpp"
@ -19,10 +9,12 @@ namespace godot {
class Quat;
class GD_CPP_CORE_API Basis {
class Basis {
public:
Vector3 elements[3];
union {
Vector3 elements[3];
Vector3 x, y, z;
};
Basis(const Quat& p_quat); // euler
Basis(const Vector3& p_euler); // euler

View File

@ -1,16 +1,6 @@
#ifndef COLOR_H
#define COLOR_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_color.h>
#include <cmath>
@ -20,7 +10,7 @@
namespace godot {
struct GD_CPP_CORE_API Color {
struct Color {
private:

View File

@ -1,16 +1,6 @@
#ifndef DICTIONARY_H
#define DICTIONARY_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Variant.hpp"
#include "Array.hpp"
@ -19,7 +9,7 @@
namespace godot {
class GD_CPP_CORE_API Dictionary {
class Dictionary {
godot_dictionary _godot_dictionary;
public:
Dictionary();

View File

@ -1,22 +1,12 @@
#ifndef GODOT_GLOBAL_HPP
#define GODOT_GLOBAL_HPP
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "String.hpp"
namespace godot {
class GD_CPP_CORE_API Godot {
class Godot {
public:
static void print(const String& message);

View File

@ -1,16 +1,6 @@
#ifndef NODEPATH_H
#define NODEPATH_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "String.hpp"
#include <godot/godot_node_path.h>
@ -18,7 +8,7 @@
namespace godot {
class GD_CPP_CORE_API NodePath
class NodePath
{
godot_node_path _node_path;
public:

View File

@ -1,16 +1,6 @@
#ifndef PLANE_H
#define PLANE_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Vector3.hpp"
#include <cmath>
@ -25,7 +15,7 @@ enum ClockDirection {
COUNTERCLOCKWISE
};
class GD_CPP_CORE_API Plane {
class Plane {
public:
Vector3 normal;
real_t d;

View File

@ -1,16 +1,6 @@
#ifndef POOLARRAYS_H
#define POOLARRAYS_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Defs.hpp"
#include "String.hpp"
@ -24,7 +14,7 @@ namespace godot {
class Array;
class GD_CPP_CORE_API PoolByteArray {
class PoolByteArray {
godot_pool_byte_array _godot_array;
public:
PoolByteArray();
@ -55,7 +45,7 @@ public:
};
class GD_CPP_CORE_API PoolIntArray {
class PoolIntArray {
godot_pool_int_array _godot_array;
public:
PoolIntArray();
@ -86,7 +76,7 @@ public:
};
class GD_CPP_CORE_API PoolRealArray {
class PoolRealArray {
godot_pool_real_array _godot_array;
public:
PoolRealArray();
@ -117,7 +107,7 @@ public:
};
class GD_CPP_CORE_API PoolStringArray {
class PoolStringArray {
godot_pool_string_array _godot_array;
public:
PoolStringArray();
@ -149,7 +139,7 @@ public:
class GD_CPP_CORE_API PoolVector2Array {
class PoolVector2Array {
godot_pool_vector2_array _godot_array;
public:
PoolVector2Array();
@ -180,7 +170,7 @@ public:
};
class GD_CPP_CORE_API PoolVector3Array {
class PoolVector3Array {
godot_pool_vector3_array _godot_array;
public:
PoolVector3Array();
@ -211,7 +201,7 @@ public:
};
class GD_CPP_CORE_API PoolColorArray {
class PoolColorArray {
godot_pool_color_array _godot_array;
public:
PoolColorArray();

View File

@ -1,16 +1,6 @@
#ifndef QUAT_H
#define QUAT_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <cmath>
#include "Vector3.hpp"
@ -19,7 +9,7 @@
namespace godot {
class GD_CPP_CORE_API Quat{
class Quat{
public:
real_t x,y,z,w;

View File

@ -1,23 +1,13 @@
#ifndef RID_H
#define RID_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_rid.h>
namespace godot {
class Object;
class GD_CPP_CORE_API RID {
class RID {
godot_rid _godot_rid;
public:

View File

@ -1,16 +1,6 @@
#ifndef RECT2_H
#define RECT2_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Vector2.hpp"
#include <cmath>
@ -26,7 +16,7 @@ typedef Vector2 Point2;
class Transform2D;
struct GD_CPP_CORE_API Rect2 {
struct Rect2 {
Point2 pos;
Size2 size;

View File

@ -1,16 +1,6 @@
#ifndef RECT3_H
#define RECT3_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Vector3.hpp"
#include "Plane.hpp"
@ -19,7 +9,7 @@
namespace godot {
class GD_CPP_CORE_API Rect3 {
class Rect3 {
public:
Vector3 pos;
Vector3 size;

View File

@ -1,16 +1,6 @@
#ifndef REF_H
#define REF_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Variant.hpp"
namespace godot {

View File

@ -1,23 +1,13 @@
#ifndef STRING_H
#define STRING_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_string.h>
namespace godot {
class NodePath;
class GD_CPP_CORE_API String
class String
{
godot_string _godot_string;
public:

View File

@ -1,16 +1,6 @@
#ifndef TRANSFORM_H
#define TRANSFORM_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Basis.hpp"
#include "Plane.hpp"
@ -18,7 +8,7 @@
namespace godot {
class GD_CPP_CORE_API Transform {
class Transform {
public:
Basis basis;

View File

@ -1,16 +1,6 @@
#ifndef TRANSFORM2D_H
#define TRANSFORM2D_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Vector2.hpp"
@ -20,7 +10,7 @@ typedef Vector2 Size2;
class Rect2;
struct GD_CPP_CORE_API Transform2D {
struct Transform2D {
// Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper":
// M = (elements[0][0] elements[1][0])
// (elements[0][1] elements[1][1])

View File

@ -1,16 +1,6 @@
#ifndef VARIANT_H
#define VARIANT_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_variant.h>
#include "Defs.hpp"
@ -38,7 +28,7 @@ class Dictionary;
class Array;
class GD_CPP_CORE_API Variant {
class Variant {
godot_variant _godot_variant;
public:
enum Type {

View File

@ -1,17 +1,6 @@
#ifndef VECTOR2_H
#define VECTOR2_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_vector2.h>
#include "Defs.hpp"
@ -20,7 +9,7 @@ namespace godot {
class String;
struct GD_CPP_CORE_API Vector2 {
struct Vector2 {
union {
real_t x;

View File

@ -1,16 +1,6 @@
#ifndef VECTOR3_H
#define VECTOR3_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Defs.hpp"
#include "String.hpp"
@ -18,7 +8,7 @@
namespace godot {
struct GD_CPP_CORE_API Vector3 {
struct Vector3 {
enum Axis {
AXIS_X,
@ -40,8 +30,6 @@ struct GD_CPP_CORE_API Vector3 {
Vector3();
Vector3(const Vector3& b);
const real_t& operator[](int p_axis) const;
real_t& operator[](int p_axis);

View File

@ -26,13 +26,6 @@ Vector3::Vector3()
this->z = 0;
}
Vector3::Vector3(const Vector3& b)
{
this->x = b.x;
this->y = b.y;
this->z = b.z;
}
const real_t& Vector3::operator[](int p_axis) const
{
return coord[p_axis];