summaryrefslogtreecommitdiffstats
path: root/src/bindings/swig/php/CMakeLists.txt
blob: 802f3a27785bf53f9b024003e6af85e2cd2cea62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# generate PHP module

find_package(PHP5)
if(PHP5_FOUND)
	include_directories(${PHP5_INCLUDE_PATH})
else()
	message(STATUS "No PHP5 libraries found - not building php module")
	return()
endif()

# copied from cmake's FindPHP4.cmake and adapted
if(APPLE)
	# this is a hack for now
  set(PHP_MODULE_CXX_FLAGS "${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS} -Wl")
  foreach(symbol
		__efree
		__emalloc
		__estrdup
		__estrndup
		__object_init
		__object_init_ex
		__zend_get_parameters_array_ex
		__zend_list_find
		__zval_copy_ctor
		__zval_copy_ctor_func
		_add_property_zval_ex
		_alloc_globals
		_compiler_globals
		_convert_to_double
		_convert_to_long
		_convert_to_boolean
		__convert_to_string
		_gc_remove_zval_from_buffer
		_call_user_function
		_php_sprintf
		_executor_globals
		_zend_get_constant
		_zend_lookup_class
		_zend_register_long_constant
		_zval_is_true
		_zend_error
		_zend_hash_find
		__zend_hash_add_or_update
		_zend_register_internal_class_ex
		_zend_register_list_destructors_ex
		_zend_register_resource
		_zend_rsrc_list_get_rsrc_type
		_zend_wrong_param_count
		_zend_throw_exception
		_zval_used_for_init
		)
    set(PHP_MODULE_CXX_FLAGS
      "${PHP_MODULE_CXX_FLAGS},-U,${symbol}")
  endforeach()
endif()

#message(FATAL_ERROR "PHP_LDFLAGS: ${PHP_LDFLAGS}")

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${PHP_INCLUDE_DIRS})

SET(CMAKE_SWIG_FLAGS "")

# we need ; to produce a space with the package .. weird
SET_SOURCE_FILES_PROPERTIES(uscxml.i PROPERTIES CPLUSPLUS ON)

SWIG_ADD_MODULE(uscxmlNativePHP php5 uscxml.i)
foreach(PHP_LIBRARY ${PHP_LIBRARIES})
#	SWIG_LINK_LIBRARIES(uscxmlNativePHP ${PHP_LIBRARY})
endforeach()
SWIG_LINK_LIBRARIES(uscxmlNativePHP uscxml)

if (APPLE)
	set_target_properties(uscxmlNativePHP PROPERTIES LINK_FLAGS ${PHP_MODULE_CXX_FLAGS})
endif()

set(PHP_COMPILE_FLAGS "-DSWIG")

if (PHP_ZTS_ENABLED)
	# we are only building php bindings for unices anyhow
	set(PHP_COMPILE_FLAGS "${PHP_COMPILE_FLAGS} -DZTS")
	set(PHP_COMPILE_FLAGS "${PHP_COMPILE_FLAGS} -DPTHREADS")
endif()
if (PHP_DEBUG_ENABLED)
	set(PHP_COMPILE_FLAGS "${PHP_COMPILE_FLAGS} -DZEND_DEBUG")	
endif()

ADD_CUSTOM_COMMAND(
	TARGET uscxmlNativePHP
	POST_BUILD
	COMMAND ${CMAKE_COMMAND} -E copy
		${CMAKE_CURRENT_BINARY_DIR}/uscxmlNativePHP.php
		${PROJECT_SOURCE_DIR}/src/bindings/swig/php/uscxmlNativePHP.php
)

set_target_properties(uscxmlNativePHP PROPERTIES COMPILE_FLAGS ${PHP_COMPILE_FLAGS})
set_target_properties(uscxmlNativePHP PROPERTIES FOLDER "Bindings")

set(USCXML_LANGUAGE_BINDINGS "php ${USCXML_LANGUAGE_BINDINGS}")
set(USCXML_LANGUAGE_BINDINGS ${USCXML_LANGUAGE_BINDINGS} PARENT_SCOPE)