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/*.cpp
src/*.hpp src/*.hpp
include/*.hpp include/*.hpp
*.o
*.os *.os
*.so *.so
*.obj *.obj

View File

@ -32,27 +32,18 @@ if platform == "osx":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-arch', 'x86_64']) env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup']) env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
if target == "core":
if platform == "linux": if platform == "linux":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14']) env.Append(CCFLAGS = ['-g','-O3', '-std=c++14'])
env.Append(CPPPATH=['.', godot_headers_path, 'include', 'include/core'])
env.Append(CPPPATH=['include/core', godot_headers_path])
if platform == "windows": if platform == "windows":
env.Append(LIBS=[godot_name + '.lib']) env.Append(LIBS=[godot_name])
env.Append(LIBPATH=[godot_lib_path]) env.Append(LIBPATH=[godot_lib_path])
env.Append(CPPFLAGS=['-D_GD_CPP_CORE_API_IMPL'])
sources = [] sources = []
add_sources(sources, "src/core") add_sources(sources, "src/core")
library = env.SharedLibrary(target='bin/godot_cpp_core', source=sources)
Default(library)
elif target == "bindings":
if ARGUMENTS.get("generate_bindings", "no") == "yes": if ARGUMENTS.get("generate_bindings", "no") == "yes":
godot_executable = godot_bin_path + godot_name godot_executable = godot_bin_path + godot_name
@ -76,29 +67,8 @@ elif target == "bindings":
binding_generator.generate_bindings(json_api_file) binding_generator.generate_bindings(json_api_file)
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") add_sources(sources, "src")
library = env.SharedLibrary(target='bin/godot_cpp_bindings', source=sources) library = env.StaticLibrary(target='bin/godot_cpp_bindings', source=sources)
Default(library) 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("#ifndef GODOT_CPP_" + strip_name(c["name"]).upper() + "_HPP")
source.append("#define GODOT_CPP_" + strip_name(c["name"]).upper() + "_HPP") source.append("#define GODOT_CPP_" + strip_name(c["name"]).upper() + "_HPP")
source.append("") 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("")
source.append("#include <godot.h>") source.append("#include <godot.h>")
@ -101,7 +89,7 @@ def generate_class_header(used_classes, c):
# generate the class definition here # 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("public:")
source.append("") source.append("")
@ -253,7 +241,7 @@ def generate_class_implementation(icalls, used_classes, c):
source.append("static inline void ___singleton_init()") source.append("static inline void ___singleton_init()")
source.append("{") source.append("{")
source.append("\tif (" + core_object_name + " == nullptr) {") 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("\t}")
source.append("}") source.append("}")
@ -265,7 +253,7 @@ def generate_class_implementation(icalls, used_classes, c):
if c["instanciable"]: if c["instanciable"]:
source.append("void *" + strip_name(c["name"]) + "::operator new(size_t)") source.append("void *" + strip_name(c["name"]) + "::operator new(size_t)")
source.append("{") 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("}")
source.append("void " + strip_name(c["name"]) + "::operator delete(void *ptr)") source.append("void " + strip_name(c["name"]) + "::operator delete(void *ptr)")

View File

@ -1,16 +1,6 @@
#ifndef ARRAY_H #ifndef ARRAY_H
#define 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 <godot/godot_array.h>
#include "String.hpp" #include "String.hpp"
@ -28,7 +18,7 @@ class PoolColorArray;
class Object; class Object;
class GD_CPP_CORE_API Array { class Array {
godot_array _godot_array; godot_array _godot_array;
public: public:
Array(); Array();

View File

@ -1,16 +1,6 @@
#ifndef BASIS_H #ifndef BASIS_H
#define 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 "Defs.hpp"
#include "Vector3.hpp" #include "Vector3.hpp"
@ -19,10 +9,12 @@ namespace godot {
class Quat; class Quat;
class GD_CPP_CORE_API Basis { class Basis {
public: public:
union {
Vector3 elements[3]; Vector3 elements[3];
Vector3 x, y, z;
};
Basis(const Quat& p_quat); // euler Basis(const Quat& p_quat); // euler
Basis(const Vector3& p_euler); // euler Basis(const Vector3& p_euler); // euler

View File

@ -1,16 +1,6 @@
#ifndef COLOR_H #ifndef COLOR_H
#define 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 <godot/godot_color.h>
#include <cmath> #include <cmath>
@ -20,7 +10,7 @@
namespace godot { namespace godot {
struct GD_CPP_CORE_API Color { struct Color {
private: private:

View File

@ -1,16 +1,6 @@
#ifndef DICTIONARY_H #ifndef DICTIONARY_H
#define 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 "Variant.hpp"
#include "Array.hpp" #include "Array.hpp"
@ -19,7 +9,7 @@
namespace godot { namespace godot {
class GD_CPP_CORE_API Dictionary { class Dictionary {
godot_dictionary _godot_dictionary; godot_dictionary _godot_dictionary;
public: public:
Dictionary(); Dictionary();

View File

@ -1,22 +1,12 @@
#ifndef GODOT_GLOBAL_HPP #ifndef GODOT_GLOBAL_HPP
#define 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" #include "String.hpp"
namespace godot { namespace godot {
class GD_CPP_CORE_API Godot { class Godot {
public: public:
static void print(const String& message); static void print(const String& message);

View File

@ -1,16 +1,6 @@
#ifndef NODEPATH_H #ifndef NODEPATH_H
#define 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 "String.hpp"
#include <godot/godot_node_path.h> #include <godot/godot_node_path.h>
@ -18,7 +8,7 @@
namespace godot { namespace godot {
class GD_CPP_CORE_API NodePath class NodePath
{ {
godot_node_path _node_path; godot_node_path _node_path;
public: public:

View File

@ -1,16 +1,6 @@
#ifndef PLANE_H #ifndef PLANE_H
#define 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 "Vector3.hpp"
#include <cmath> #include <cmath>
@ -25,7 +15,7 @@ enum ClockDirection {
COUNTERCLOCKWISE COUNTERCLOCKWISE
}; };
class GD_CPP_CORE_API Plane { class Plane {
public: public:
Vector3 normal; Vector3 normal;
real_t d; real_t d;

View File

@ -1,16 +1,6 @@
#ifndef POOLARRAYS_H #ifndef POOLARRAYS_H
#define 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 "Defs.hpp"
#include "String.hpp" #include "String.hpp"
@ -24,7 +14,7 @@ namespace godot {
class Array; class Array;
class GD_CPP_CORE_API PoolByteArray { class PoolByteArray {
godot_pool_byte_array _godot_array; godot_pool_byte_array _godot_array;
public: public:
PoolByteArray(); PoolByteArray();
@ -55,7 +45,7 @@ public:
}; };
class GD_CPP_CORE_API PoolIntArray { class PoolIntArray {
godot_pool_int_array _godot_array; godot_pool_int_array _godot_array;
public: public:
PoolIntArray(); PoolIntArray();
@ -86,7 +76,7 @@ public:
}; };
class GD_CPP_CORE_API PoolRealArray { class PoolRealArray {
godot_pool_real_array _godot_array; godot_pool_real_array _godot_array;
public: public:
PoolRealArray(); PoolRealArray();
@ -117,7 +107,7 @@ public:
}; };
class GD_CPP_CORE_API PoolStringArray { class PoolStringArray {
godot_pool_string_array _godot_array; godot_pool_string_array _godot_array;
public: public:
PoolStringArray(); PoolStringArray();
@ -149,7 +139,7 @@ public:
class GD_CPP_CORE_API PoolVector2Array { class PoolVector2Array {
godot_pool_vector2_array _godot_array; godot_pool_vector2_array _godot_array;
public: public:
PoolVector2Array(); PoolVector2Array();
@ -180,7 +170,7 @@ public:
}; };
class GD_CPP_CORE_API PoolVector3Array { class PoolVector3Array {
godot_pool_vector3_array _godot_array; godot_pool_vector3_array _godot_array;
public: public:
PoolVector3Array(); PoolVector3Array();
@ -211,7 +201,7 @@ public:
}; };
class GD_CPP_CORE_API PoolColorArray { class PoolColorArray {
godot_pool_color_array _godot_array; godot_pool_color_array _godot_array;
public: public:
PoolColorArray(); PoolColorArray();

View File

@ -1,16 +1,6 @@
#ifndef QUAT_H #ifndef QUAT_H
#define 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 <cmath>
#include "Vector3.hpp" #include "Vector3.hpp"
@ -19,7 +9,7 @@
namespace godot { namespace godot {
class GD_CPP_CORE_API Quat{ class Quat{
public: public:
real_t x,y,z,w; real_t x,y,z,w;

View File

@ -1,23 +1,13 @@
#ifndef RID_H #ifndef RID_H
#define 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> #include <godot/godot_rid.h>
namespace godot { namespace godot {
class Object; class Object;
class GD_CPP_CORE_API RID { class RID {
godot_rid _godot_rid; godot_rid _godot_rid;
public: public:

View File

@ -1,16 +1,6 @@
#ifndef RECT2_H #ifndef RECT2_H
#define 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 "Vector2.hpp"
#include <cmath> #include <cmath>
@ -26,7 +16,7 @@ typedef Vector2 Point2;
class Transform2D; class Transform2D;
struct GD_CPP_CORE_API Rect2 { struct Rect2 {
Point2 pos; Point2 pos;
Size2 size; Size2 size;

View File

@ -1,16 +1,6 @@
#ifndef RECT3_H #ifndef RECT3_H
#define 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 "Vector3.hpp"
#include "Plane.hpp" #include "Plane.hpp"
@ -19,7 +9,7 @@
namespace godot { namespace godot {
class GD_CPP_CORE_API Rect3 { class Rect3 {
public: public:
Vector3 pos; Vector3 pos;
Vector3 size; Vector3 size;

View File

@ -1,16 +1,6 @@
#ifndef REF_H #ifndef REF_H
#define 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" #include "Variant.hpp"
namespace godot { namespace godot {

View File

@ -1,23 +1,13 @@
#ifndef STRING_H #ifndef STRING_H
#define 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> #include <godot/godot_string.h>
namespace godot { namespace godot {
class NodePath; class NodePath;
class GD_CPP_CORE_API String class String
{ {
godot_string _godot_string; godot_string _godot_string;
public: public:

View File

@ -1,16 +1,6 @@
#ifndef TRANSFORM_H #ifndef TRANSFORM_H
#define 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 "Basis.hpp"
#include "Plane.hpp" #include "Plane.hpp"
@ -18,7 +8,7 @@
namespace godot { namespace godot {
class GD_CPP_CORE_API Transform { class Transform {
public: public:
Basis basis; Basis basis;

View File

@ -1,16 +1,6 @@
#ifndef TRANSFORM2D_H #ifndef TRANSFORM2D_H
#define 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" #include "Vector2.hpp"
@ -20,7 +10,7 @@ typedef Vector2 Size2;
class Rect2; 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": // 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]) // M = (elements[0][0] elements[1][0])
// (elements[0][1] elements[1][1]) // (elements[0][1] elements[1][1])

View File

@ -1,16 +1,6 @@
#ifndef VARIANT_H #ifndef VARIANT_H
#define 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 <godot/godot_variant.h>
#include "Defs.hpp" #include "Defs.hpp"
@ -38,7 +28,7 @@ class Dictionary;
class Array; class Array;
class GD_CPP_CORE_API Variant { class Variant {
godot_variant _godot_variant; godot_variant _godot_variant;
public: public:
enum Type { enum Type {

View File

@ -1,17 +1,6 @@
#ifndef VECTOR2_H #ifndef VECTOR2_H
#define 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 <godot/godot_vector2.h>
#include "Defs.hpp" #include "Defs.hpp"
@ -20,7 +9,7 @@ namespace godot {
class String; class String;
struct GD_CPP_CORE_API Vector2 { struct Vector2 {
union { union {
real_t x; real_t x;

View File

@ -1,16 +1,6 @@
#ifndef VECTOR3_H #ifndef VECTOR3_H
#define 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 "Defs.hpp"
#include "String.hpp" #include "String.hpp"
@ -18,7 +8,7 @@
namespace godot { namespace godot {
struct GD_CPP_CORE_API Vector3 { struct Vector3 {
enum Axis { enum Axis {
AXIS_X, AXIS_X,
@ -40,8 +30,6 @@ struct GD_CPP_CORE_API Vector3 {
Vector3(); Vector3();
Vector3(const Vector3& b);
const real_t& operator[](int p_axis) const; const real_t& operator[](int p_axis) const;
real_t& operator[](int p_axis); real_t& operator[](int p_axis);

View File

@ -26,13 +26,6 @@ Vector3::Vector3()
this->z = 0; 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 const real_t& Vector3::operator[](int p_axis) const
{ {
return coord[p_axis]; return coord[p_axis];