From 6f428356f98aae08121d99370c606125be4dd1d6 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Wed, 20 Mar 2013 20:01:54 +0100 Subject: Trying for a PHP module --- contrib/cmake/FindPHP5.cmake | 78 ++++++++++++++++-------------------- src/bindings/swig/php/CMakeLists.txt | 21 +++++----- src/bindings/swig/php/uscxml.i | 4 +- 3 files changed, 47 insertions(+), 56 deletions(-) diff --git a/contrib/cmake/FindPHP5.cmake b/contrib/cmake/FindPHP5.cmake index 212e8c1..620c1c7 100644 --- a/contrib/cmake/FindPHP5.cmake +++ b/contrib/cmake/FindPHP5.cmake @@ -1,47 +1,37 @@ -# - Find PHP5 -# This module finds if PHP5 is installed and determines where the include files -# and libraries are. It also determines what the name of the library is. This -# code sets the following variables: -# -# PHP5_INCLUDE_PATH = path to where php.h can be found -# PHP5_EXECUTABLE = full path to the php5 binary -# -# Copyright (c) 2006-2011 Mathieu Malaterre -# -# Redistribution and use is allowed according to the terms of the New -# BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# +if (UNIX) + find_program(PHP_CONFIG + NAMES php-config + PATHS + /usr/bin + /usr/local/bin + /opt/local/bin + ) + if (PHP_CONFIG) + execute_process(COMMAND ${PHP_CONFIG} --includes + OUTPUT_VARIABLE PHP_INCLUDE_DIRS + ERROR_VARIABLE PHP_INCLUDE_errors + RESULT_VARIABLE PHP_INCLUDE_result) + string(REGEX REPLACE "-I" "" PHP_INCLUDE_DIRS ${PHP_INCLUDE_DIRS}) + string(REGEX REPLACE "[ \n\r]+" ";" PHP_INCLUDE_DIRS ${PHP_INCLUDE_DIRS}) -set(PHP5_POSSIBLE_INCLUDE_PATHS - /usr/include/php5 - /usr/local/include/php5 - /usr/include/php - /usr/local/include/php - /usr/local/apache/php - ) - -set(PHP5_POSSIBLE_LIB_PATHS - /usr/lib -) - -find_path(PHP5_FOUND_INCLUDE_PATH main/php.h - ${PHP5_POSSIBLE_INCLUDE_PATHS}) - -if(PHP5_FOUND_INCLUDE_PATH) - set(php5_paths "${PHP5_POSSIBLE_INCLUDE_PATHS}") - foreach(php5_path Zend main TSRM) - set(php5_paths ${php5_paths} "${PHP5_FOUND_INCLUDE_PATH}/${php5_path}") - endforeach() - set(PHP5_INCLUDE_PATH "${php5_paths}" INTERNAL "PHP5 include paths") + execute_process(COMMAND ${PHP_CONFIG} --libs + OUTPUT_VARIABLE PHP_LIBRARIES + ERROR_VARIABLE PHP_LIBRARIES_errors + RESULT_VARIABLE PHP_LIBRARIES_result) + string(REGEX REPLACE "-l" "" PHP_LIBRARIES ${PHP_LIBRARIES}) + string(REGEX REPLACE "[ \n\r]+" ";" PHP_LIBRARIES ${PHP_LIBRARIES}) + list(REMOVE_DUPLICATES PHP_LIBRARIES) + + execute_process(COMMAND ${PHP_CONFIG} --ldflags + OUTPUT_VARIABLE PHP_LDFLAGS + ERROR_VARIABLE PHP_LDFLAGS_errors + RESULT_VARIABLE PHP_LDFLAGS_result) + + endif() +else() + message(STATUS "Finding PHP5 on Windows is not supported") endif() -find_program(PHP5_EXECUTABLE NAMES php5 php ) - -mark_as_advanced( - PHP5_EXECUTABLE - PHP5_FOUND_INCLUDE_PATH - ) - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(PHP5 DEFAULT_MSG PHP5_EXECUTABLE PHP5_INCLUDE_PATH) \ No newline at end of file +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PHP5 DEFAULT_MSG PHP_CONFIG PHP_INCLUDE_DIRS PHP_LIBRARIES PHP_LDFLAGS) +MARK_AS_ADVANCED(PHP_LIBRARIES PHP_INCLUDE_DIRS PHP_LDFLAGS) diff --git a/src/bindings/swig/php/CMakeLists.txt b/src/bindings/swig/php/CMakeLists.txt index 74456e3..95c98e5 100644 --- a/src/bindings/swig/php/CMakeLists.txt +++ b/src/bindings/swig/php/CMakeLists.txt @@ -8,21 +8,22 @@ else() return() 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 SWIG_FLAGS "-package;${SCXMLPL_JAVA_PACKAGE}") SET_SOURCE_FILES_PROPERTIES(uscxml.i PROPERTIES CPLUSPLUS ON) -SET(CMAKE_SWIG_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/${SCXMLPL_JAVA_DIR}") - -SWIG_ADD_MODULE(uscxmlNativePHP php uscxml.i) -# foreach(JNI_LIBRARY ${JNI_LIBRARIES}) -# if (NOT ${JNI_LIBRARY} MATCHES ".*jawt.*") -# SWIG_LINK_LIBRARIES(uscxmlNativePHP ${JNI_LIBRARY}) -# endif() -# endforeach() + +SWIG_ADD_MODULE(uscxmlNativePHP php5 uscxml.i) +foreach(PHP_LIBRARY ${PHP_LIBRARIES}) + SWIG_LINK_LIBRARIES(uscxmlNativePHP ${PHP_LIBRARY}) +endforeach() + +#set_target_properties(uscxmlNativePHP PROPERTIES LINK_FLAGS ${PHP_LDFLAGS}) set_target_properties(uscxmlNativePHP PROPERTIES FOLDER "Bindings") -swig_link_libraries(uscxmlNativePHP uscxml) +SWIG_LINK_LIBRARIES(uscxmlNativePHP uscxml) diff --git a/src/bindings/swig/php/uscxml.i b/src/bindings/swig/php/uscxml.i index e2e1a86..a545a7a 100644 --- a/src/bindings/swig/php/uscxml.i +++ b/src/bindings/swig/php/uscxml.i @@ -3,13 +3,13 @@ // import swig typemaps //%include //%include -%include +//%include // disable warning related to unknown base class #pragma SWIG nowarn=401 //%ignore boost::enable_shared_from_this; -%javaconst(1); +//%javaconst(1); # %shared_ptr(uscxml::dom::Element); # %shared_ptr(uscxml::dom::Executable); -- cgit v0.12