Skip to content

Commit

Permalink
Merge pull request jcalifornia#20 from GodotNativeTools/static-linking
Browse files Browse the repository at this point in the history
Use static linking instead of dynamic linking
  • Loading branch information
karroffel authored Jul 24, 2017
2 parents fd852ea + 4769f49 commit 2195f2e
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 297 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
src/*.cpp
src/*.hpp
include/*.hpp
*.o
*.os
*.so
*.obj
Expand Down
82 changes: 26 additions & 56 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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'])


env.Append(CPPPATH=['include/core', godot_headers_path])

if platform == "windows":
env.Append(LIBS=[godot_name + '.lib'])
env.Append(LIBPATH=[godot_lib_path])

env.Append(CPPFLAGS=['-D_GD_CPP_CORE_API_IMPL'])

sources = []
add_sources(sources, "src/core")

library = env.SharedLibrary(target='bin/godot_cpp_core', source=sources)
Default(library)
if platform == "linux":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14'])

env.Append(CPPPATH=['.', godot_headers_path, 'include', 'include/core'])

elif target == "bindings":
if platform == "windows":
env.Append(LIBS=[godot_name])
env.Append(LIBPATH=[godot_lib_path])

if ARGUMENTS.get("generate_bindings", "no") == "yes":
godot_executable = godot_bin_path + godot_name
sources = []
add_sources(sources, "src/core")

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'
if ARGUMENTS.get("generate_bindings", "no") == "yes":
godot_executable = godot_bin_path + godot_name

subprocess.call([godot_executable, '--gdnative-generate-json-api', json_api_file])
if env["CXX"] == "clang++":
godot_executable += ".llvm"

# actually create the bindings here

import binding_generator


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\''])
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'

env.Append(CPPPATH=['.', godot_headers_path, 'include', 'include/core'])
subprocess.call([godot_executable, '--gdnative-generate-json-api', json_api_file])

if platform == "windows":
env.Append(LIBS=[godot_name])
env.Append(LIBPATH=[godot_lib_path])
# actually create the bindings here

import binding_generator

env.Append(LIBS=['godot_cpp_core'])
env.Append(LIBPATH=['bin'])

binding_generator.generate_bindings(json_api_file)

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)
Default(library)
library = env.StaticLibrary(target='bin/godot_cpp_bindings', source=sources)
Default(library)

18 changes: 3 additions & 15 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>")
Expand Down Expand Up @@ -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("")
Expand Down Expand Up @@ -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("}")

Expand All @@ -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)")
Expand Down
12 changes: 1 addition & 11 deletions include/core/Array.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -28,7 +18,7 @@ class PoolColorArray;

class Object;

class GD_CPP_CORE_API Array {
class Array {
godot_array _godot_array;
public:
Array();
Expand Down
18 changes: 5 additions & 13 deletions include/core/Basis.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
12 changes: 1 addition & 11 deletions include/core/Color.hpp
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -20,7 +10,7 @@
namespace godot {


struct GD_CPP_CORE_API Color {
struct Color {


private:
Expand Down
12 changes: 1 addition & 11 deletions include/core/Dictionary.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -19,7 +9,7 @@

namespace godot {

class GD_CPP_CORE_API Dictionary {
class Dictionary {
godot_dictionary _godot_dictionary;
public:
Dictionary();
Expand Down
12 changes: 1 addition & 11 deletions include/core/GodotGlobal.hpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
12 changes: 1 addition & 11 deletions include/core/NodePath.hpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
#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>

namespace godot {


class GD_CPP_CORE_API NodePath
class NodePath
{
godot_node_path _node_path;
public:
Expand Down
12 changes: 1 addition & 11 deletions include/core/Plane.hpp
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -25,7 +15,7 @@ enum ClockDirection {
COUNTERCLOCKWISE
};

class GD_CPP_CORE_API Plane {
class Plane {
public:
Vector3 normal;
real_t d;
Expand Down
Loading

0 comments on commit 2195f2e

Please sign in to comment.