Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MacOS #33

Merged
merged 7 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ __You will need some sort of geodata to use this plugin.__ A good starting point

# Building

For building this project we need to install [Scons](https://scons.org) by following one of the [User Guide](https://scons.org/documentation.html) *Installing Scons* which is both used for Godot GDNative and this project and we need the GDAL library which has different installation instruction listed below.

- [Linux](#building-on-linux)
- [Windows](#building-on-windows)
- [MacOS](#building-on-macos)
## Building on Linux

### Preparation
Expand Down Expand Up @@ -93,6 +98,31 @@ When using GDAL on Windows, problems with DLLs not being found are pretty freque

If you still get `Error 126: The specified module could not be found.` when starting the demo project, we recommend checking the Geodot DLL and the GDAL DLL with [Dependencies](https://github.com/lucasg/Dependencies).

## Building on MacOS

The current implementation only has support for x86 and not for the new M1 processor.

### Preparation

1. Install using `brew install gdal` or manually https://github.com/OSGeo/gdal.
1. Check installation with ie `gdalinfo --formats`
1. Use `brew info gdal | grep '/usr/local' | cut -d ' ' -f 1` or `which gdalinfo` to find the GDAL install location.
1. Make a note of this path like `/usr/local/Cellar/gdal/3.2.1` and use that below for `osgeo_path=...`
1. Initialize all git submodules: `git submodule update --init --recursive`
1. Generate the GDNative C++ bindings:
```
cd godot-cpp
scons generate_bindings=yes target=release --jobs=$(sysctl -n hw.logicalcpu)
cd ..
```

### Compiling

1. Compile the project itself using the GDAL location like `scons target=release osgeo_path=/usr/local/Cellar/gdal/3.2.1`
1. This generates the file `libgeodot.dylib` and 2 more located in `demo/addons/geodot/osx`
1. Move the files `libRasterTileExtractor.dylib` and `libVectorExtractor.dylib` from `demo/addons/geodot/osx` into `demo/build` directory. See #52
1. `mkdir build ; mv demo/addons/geodot/osx/libRasterTileExtractor.dylib demo/addons/geodot/osx/libVectorExtractor.dylib demo/build`

# Developing

We recommend VSCodium for developing. For on-the-fly code completion, error reporting, etc., install the `clangd` extension in VSCodium and run `scons compiledb=yes` in order to generate the required compilation database.
Expand Down
6 changes: 6 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ if env['platform'] == "osx":
lib_file_ending = ".dylib"
env['target_path'] += 'osx/'
cpp_library += '.osx'

env.Append(CXXFLAGS=['-std=c++17'])

if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS=['-g', '-O2', '-arch', 'x86_64'])
env.Append(LINKFLAGS=['-arch', 'x86_64'])
Expand Down Expand Up @@ -140,6 +143,9 @@ env.Append(LIBS=[cpp_library, rte_library, vector_library])
if env['platform'] == "windows":
env.Append(LIBS=['gdal_i.lib'])
env.Append(LIBPATH=[env['osgeo_path'] + '\\lib\\'])
elif env['platform'] == 'osx':
env.Append(LIBS=['libgdal.dylib'])
env.Append(LIBPATH=[os.path.join(env['osgeo_path'], "lib")])

# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=['src/'])
Expand Down
2 changes: 2 additions & 0 deletions src/global/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#define EXPORT __declspec(dllexport)
#elif __unix__
#define EXPORT
#elif __APPLE__
#define EXPORT
#endif

#endif // __DEFINES_H__
3 changes: 3 additions & 0 deletions src/raster-tile-extractor/GeoRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#ifdef _WIN32
#include <cpl_error.h>
#include <gdal_priv.h>
#elif __APPLE__
#include <cpl_error.h>
#include <gdal_priv.h>
#elif __unix__
#include <gdal/cpl_error.h>
#include <gdal/gdal_priv.h>
Expand Down
3 changes: 3 additions & 0 deletions src/raster-tile-extractor/RasterTileExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#ifdef _WIN32
#include <gdal_priv.h>
#include <gdalwarper.h>
#elif __APPLE__
#include <gdal_priv.h>
#include <gdalwarper.h>
#elif __unix__
#include <gdal/gdal_priv.h>
#include <gdal/gdalwarper.h>
Expand Down
17 changes: 15 additions & 2 deletions src/raster-tile-extractor/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(PathVariable('osgeo_path', "(Windows only) path to OSGeo installation", "", PathVariable.PathAccept))
opts.Add(PathVariable('osgeo_path', "(Windows and Mac) path to OSGeo installation", "", PathVariable.PathAccept))

# only support 64 at this time..
bits = 64
Expand All @@ -25,7 +25,7 @@ if env['p'] != '':

if env['platform'] == '':
print("No valid target platform selected.")
quit();
quit()

env['target_path'] = 'build/'
env['target_name'] = 'libRasterTileExtractor'
Expand All @@ -50,6 +50,19 @@ elif env['platform'] == "windows":
print("OSGeo paths are invalid!")
quit()

elif env['platform'] == 'osx':
#env.Append(LINKFLAGS=['/WHOLEARCHIVE'])
env.Append(CXXFLAGS=['-std=c++17'])

# Include GDAL
gdal_include_path = os.path.join(env['osgeo_path'], "include")
gdal_lib_path = os.path.join(env['osgeo_path'], "lib")
gdal_lib_name = "libgdal.dylib"

if not os.path.exists(gdal_include_path) or not os.path.exists(gdal_lib_path):
print("OSGeo paths are invalid!")
quit()

env.Append(CPPPATH=[gdal_include_path])
env.Append(LIBPATH=[gdal_lib_path])
env.Append(LIBS=[gdal_lib_name])
Expand Down
2 changes: 2 additions & 0 deletions src/vector-extractor/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#ifdef _WIN32
#include <ogr_feature.h>
#elif __APPLE__
#include <ogr_feature.h>
#elif __unix__
#include <gdal/ogr_feature.h>
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/vector-extractor/LineFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#ifdef _WIN32
#include <gdal_priv.h>
#include <ogr_geometry.h>
#elif __APPLE__
#include <gdal_priv.h>
#include <ogr_geometry.h>
#elif __unix__
#include <gdal/gdal_priv.h>
#include <gdal/ogr_geometry.h>
Expand Down
2 changes: 2 additions & 0 deletions src/vector-extractor/PointFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#ifdef _WIN32
#include <gdal_priv.h>
#elif __APPLE__
#include <gdal_priv.h>
#elif __unix__
#include <gdal/gdal_priv.h>
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/vector-extractor/PolygonFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#ifdef _WIN32
#include <gdal_priv.h>
#elif __APPLE__
#include <gdal_priv.h>
#elif __unix__
#include <gdal/gdal_priv.h>
#endif
Expand Down
17 changes: 15 additions & 2 deletions src/vector-extractor/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(PathVariable('osgeo_path', "(Windows only) path to OSGeo installation", "", PathVariable.PathAccept))
opts.Add(PathVariable('osgeo_path', "(Windows and Mac) path to OSGeo installation", "", PathVariable.PathAccept))

# only support 64 at this time..
bits = 64
Expand All @@ -25,7 +25,7 @@ if env['p'] != '':

if env['platform'] == '':
print("No valid target platform selected.")
quit();
quit()

env['target_path'] = 'build/'
env['target_name'] = 'libVectorExtractor'
Expand All @@ -50,6 +50,19 @@ elif env['platform'] == "windows":
print("OSGeo paths are invalid!")
quit()

elif env['platform'] == 'osx':
#env.Append(LINKFLAGS=['/WHOLEARCHIVE'])
env.Append(CXXFLAGS=['-std=c++17'])

# Include GDAL
gdal_include_path = os.path.join(env['osgeo_path'], "include")
gdal_lib_path = os.path.join(env['osgeo_path'], "lib")
gdal_lib_name = "libgdal.dylib"

if not os.path.exists(gdal_include_path) or not os.path.exists(gdal_lib_path):
print("OSGeo paths are invalid!")
quit()

env.Append(CPPPATH=[gdal_include_path])
env.Append(LIBPATH=[gdal_lib_path])
env.Append(LIBS=[gdal_lib_name])
Expand Down
3 changes: 3 additions & 0 deletions src/vector-extractor/VectorExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#ifdef _WIN32
#include <gdal.h>
#include <ogrsf_frmts.h>
#elif __APPLE__
#include <gdal.h>
#include <ogrsf_frmts.h>
#elif __unix__
#include <gdal/gdal.h>
#include <gdal/ogrsf_frmts.h>
Expand Down