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

Feature/windows build #2

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions CREDITS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
geos
Sandro Santilli <[email protected]> - GEOS
J Smith <[email protected]> <[email protected]> - PHP packaging
Sandro Santilli [email protected] - GEOS
J Smith [email protected] [email protected] - PHP packaging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this format change ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of < > The RC resource compiler crashes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like an upstream bug. The current one does not crash, right ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the current version compiles without errors

86 changes: 68 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,102 @@
PHP module for GEOS
===================
# PHP module for GEOS

[![build status]
(https://drone.osgeo.org/api/badges/geos/php-geos/status.svg?branch=master)]
(https://drone.osgeo.org/geos/php-geos?branch=master)
[![build status](https://dronie.osgeo.org/api/badges/geos/php-geos/status.svg?branch=master)](https://github.com/libgeos/php-geos/tree/master)

The code in this directory provides a PHP module to make use
of functionalities of the [GEOS library] (http://geos.osgeo.org).
of functionalities of the [GEOS library](http://geos.osgeo.org).

The bindings are linked to the C-API, for betters stability.

# Building
## Building (UNIX)

## Requirements
### Requirements

You need:

- PHP development files
( often found in packages named something like 'php5-dev' )
- PHP development files
( often found in packages named something like 'php5-dev' )

- GEOS development files
( often found in packages named something like 'libgeos-dev' )
- GEOS development files
( often found in packages named something like 'libgeos-dev' )

## Procedure
### Procedure

git clone https://git.osgeo.org/gitea/geos/php-geos.git
git clone https://github.com/libgeos/php-geos.git
eisberg marked this conversation as resolved.
Show resolved Hide resolved
cd php-geos
./autogen.sh
./configure
make # generates modules/geos.so

# Testing
## Building (Windows)

### Requirements

- PHP source files: download [zip](http://windows.php.net/download/) or clone from [github](https://github.com/php/php-src)
- PHP SDK ( https://github.com/Microsoft/php-sdk-binary-tools )
- Visual C++:
* Visual C++ 14.0 (Visual Studio 2015) for PHP 7.0 or PHP 7.1.
* Visual C++ 15.0 (Visual Studio 2017) for PHP 7.2, PHP 7.3 or PHP 7.4.
* Visual C++ 16.0 (Visual Studio 2019) for master.
- GEOS Windows binaries (binary dll, includes and lib):
* As part of [OSGeo4W](http://osgeo4w.osgeo.org/) as part of the geos package.
* As part of [MS4W](https://ms4w.com/)

### Configure

Official instructions for compiling PHP extensions: https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2

1. Install OSGeo4w in `C:\OSGeo4W64` and PHP-SDK in `C:/php-sdk.`
2. Invoke the starter script, for example for Visual Studio 2015 64-bit build, invoke phpsdk-vc15-x64.bat
3. Run the phpsdk_buildtree batch script which will create the desired directory structure:

phpsdk_buildtree phpdev

The phpsdk_buildtree script will create the path according to the currently VC++ version used and switch into the newly created directory
4. Extract the PHP source code to `C:\php-sdk\phpdev\vX##\x##`, where:

vX## is the compiler version you are using (eq vc15 or vs16)
x## is your architecture (x86 or x64)
For example: `C:\php-sdk\phpdev\vc15\x64\php-7.4.11-src`
In the same directory where you extracted the PHP source there is a deps directory.
For example: `C:\php-sdk\phpdev\vc15\x64\deps`

5. Copy GEOS binaries from `C:\OSGeo4W64` (`bin`, `include` and `lib` subdir) to `C:\php-sdk\phpdev\vc15\x64\deps\`
6. Copy (clone) code from this repository to `C:\php-sdk\phpdev\vc15\x64\php-7.4.11-src\ext\geos`


### Compile

Run next commands to compile ([see official php instruction](https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2)):

c:\php-sdk\phpsdk-vc15-x64.bat
cd C:\php-sdk\phpdev\vc15\x64\php-7.4.11-src
buildconf
configure --disable-all --enable-cli --with-geos
nmake



## Testing

Automated testing is executed on 'make check'.

You'll need phpunit installed for this to work. To install:

pear install --force --alldeps phpunit/phpunit

# Installing
## Installing

### Unix

As root (or owner with write access to the directory
returned by php-config --extension-dir), run:

make install

# Using
### Window
Copy php_geos.dll to extension directory and enable it in php.ini

## Using

... TODO ...
(reference some automatically built doc?)

20 changes: 20 additions & 0 deletions config.w32
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// vim:ft=javascript

ARG_WITH("geos", "geos support", "yes");

if (PHP_GEOS != "no") {
if (CHECK_LIB("geos_c.lib", "geos", PHP_GEOS) &&
CHECK_HEADER_ADD_INCLUDE("geos_c.h", "CFLAGS_GEOS", PHP_GEOS)) {

EXTENSION("geos", "geos.c", 1);
geos_c = "geos_c.lib";

CHECK_LIB(geos_c, "initGEOS_r", PHP_GEOS) && !PHP_GEOS && WARNING("Unable to build the GEOS: a newer libgeos is required");


} else {
WARNING("geos support can't be enabled, libraries or headers are missing")
PHP_GEOS = "no";
}

}
14 changes: 11 additions & 3 deletions geos.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,19 @@ getRelay(zval* val, zend_class_entry* ce) {

if ( proxy->std.ce != ce ) {
php_error_docref(NULL TSRMLS_CC, E_ERROR,
#if PHP_VERSION_ID >= 70000
eisberg marked this conversation as resolved.
Show resolved Hide resolved
"Relay object is not an %s", ZSTR_VAL(ce->name));
#else
"Relay object is not an %s", ce->name);
#endif
}
if ( ! proxy->relay ) {
php_error_docref(NULL TSRMLS_CC, E_ERROR,
php_error_docref(NULL TSRMLS_CC, E_ERROR,
#if PHP_VERSION_ID >= 70000
"Relay object for object of type %s is not set", ZSTR_VAL(ce->name));
#else
"Relay object for object of type %s is not set", ce->name);
#endif
}
return proxy->relay;
}
Expand Down Expand Up @@ -863,7 +871,7 @@ PHP_METHOD(Geometry, buffer)
GEOS_PHP_ZVAL data;
HashTable *style;
zend_string *key;
ulong index;
zend_ulong index;

this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);

Expand Down Expand Up @@ -956,7 +964,7 @@ PHP_METHOD(Geometry, offsetCurve)
GEOS_PHP_ZVAL data;
HashTable *style;
zend_string *key;
ulong index;
zend_ulong index;

this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);

Expand Down
4 changes: 2 additions & 2 deletions tests/004_WKBWriter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class WKBWriterTest extends GEOSTest
$writer->write(1);
$this->assertTrue(false);
} catch (ErrorException $e) {
$this->assertContains('expects parameter 1 to be object, integer given', $e->getMessage());
$this->assertContains('expects parameter 1 to be object, int', $e->getMessage());
}
}

Expand All @@ -151,7 +151,7 @@ class WKBWriterTest extends GEOSTest
$writer->writeHEX(1);
$this->assertTrue(false);
} catch (ErrorException $e) {
$this->assertContains('expects parameter 1 to be object, integer given', $e->getMessage());
$this->assertContains('expects parameter 1 to be object, int', $e->getMessage());
}
}
}
Expand Down