summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-01-03 16:01:05 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-01-03 16:01:05 (GMT)
commit87f7923531ab927606d860250e5554c72cb64505 (patch)
treeaa06a32812c66551ac0f790ad13d1061784248d5
parent0fdb8fa489bba1a5f1112f4bd7d792412dd38896 (diff)
downloadlibkolabxml-php.tar.gz
Patch by C. Giboudeauxphp
- Replace the FindPHP4.cmake usage since we need PHP >= 5.3. - Fix the kolabformat installation. By default it now installs in the extensions directory defined when building php. This can be overwritten by manually setting PHP_INSTALL_DIR when running CMake.
-rw-r--r--src/php/CMakeLists.txt86
1 files changed, 53 insertions, 33 deletions
diff --git a/src/php/CMakeLists.txt b/src/php/CMakeLists.txt
index 20647a5..eb24edd 100644
--- a/src/php/CMakeLists.txt
+++ b/src/php/CMakeLists.txt
@@ -10,8 +10,8 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KOLAB_SWIG_PHP_SOURCE_FI
VERBATIM
)
-SET_SOURCE_FILES_PROPERTIES(${KOLAB_SWIG_PHP_SOURCE_FILE} PROPERTIES GENERATED 1)
-ADD_CUSTOM_TARGET(generate_php_bindings ALL DEPENDS ${KOLAB_SWIG_PHP_SOURCE_FILE})
+set_source_files_properties(${KOLAB_SWIG_PHP_SOURCE_FILE} PROPERTIES GENERATED 1)
+add_custom_target(generate_php_bindings ALL DEPENDS ${KOLAB_SWIG_PHP_SOURCE_FILE})
#Compile PHP Bindings
@@ -20,34 +20,54 @@ if (APPLE)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flat_namespace -undefined suppress" )
endif()
-# Debian (Wheezy) won't be able to find PHP using find_package. In packaging libkolabxml
-# for it, we define the include path and executable during the build.
-if (NOT PHP4_INCLUDE_PATH OR NOT PHP4_EXECUTABLE)
- find_package(PHP4 5.3 REQUIRED)
-endif (NOT PHP4_INCLUDE_PATH OR NOT PHP4_EXECUTABLE)
-
-if (PHP4_FOUND OR (PHP4_INCLUDE_PATH AND PHP4_EXECUTABLE))
- include_directories(${PHP4_INCLUDE_PATH})
-
- # In an additional twist on Debian (Wheezy) - the PHP headers are fubar. php.h is in main/,
- # TSRM/TSRM.h includes <tsrm_config.h> instead of "tsrm_config.h", and we require
- # Zend/zend.h (included, of course, as "zend.h" without -I/usr/include/php5/Zend)
- include_directories("${PHP4_INCLUDE_PATH}/Zend" "${PHP4_INCLUDE_PATH}/TSRM" "${PHP4_INCLUDE_PATH}/main")
- add_library(phpbindings SHARED ${KOLAB_SWIG_PHP_SOURCE_FILE})
- target_link_libraries(phpbindings kolabxml)
- SET_TARGET_PROPERTIES(phpbindings PROPERTIES OUTPUT_NAME "kolabformat")
- SET_TARGET_PROPERTIES(phpbindings PROPERTIES PREFIX "")
-
- configure_file(test.php ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
-
- set(PHP_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/phpbindings" CACHE STRING "Install directory for php bindings.")
-
- install(TARGETS phpbindings LIBRARY DESTINATION ${PHP_INSTALL_DIR})
-
- install( FILES
- ${CMAKE_CURRENT_BINARY_DIR}/kolabformat.php
- DESTINATION ${PHP_INSTALL_DIR}
- )
-else(PHP4_FOUND OR (PHP4_INCLUDE_PATH AND PHP4_EXECUTABLE))
- message(WARNING "not building php bindings because php was not found")
-endif (PHP4_FOUND OR (PHP4_INCLUDE_PATH AND PHP4_EXECUTABLE))
+# Try to find PHP5
+find_path(PHP_INCLUDE_DIR NAMES main/php.h PATH_SUFFIXES php php5)
+find_program(PHP_EXECUTABLE NAMES php)
+
+# Libkolabxml needs PHP >= 5.3
+set(PHP_MIN_VERSION 50300)
+
+# Find where to install the extension files if it's not defined
+if(NOT DEFINED PHP_INSTALL_DIR)
+ find_program(PHP_CONFIG_EXECUTABLE NAMES php-config)
+ if(PHP_CONFIG_EXECUTABLE)
+ execute_process(COMMAND ${PHP_CONFIG_EXECUTABLE} --extension-dir
+ OUTPUT_VARIABLE _php_extensions_dir
+ )
+ string(REGEX REPLACE "\n" "" _php_extensions_dir "${_php_extensions_dir}")
+ set(PHP_INSTALL_DIR ${_php_extensions_dir} CACHE STRING "Install directory for PHP bindings.")
+ else()
+ set(PHP_INSTALL_DIR ${LIB_INSTALL_DIR}/extensions)
+ endif()
+endif()
+
+if(PHP_INCLUDE_DIR AND PHP_EXECUTABLE)
+ file(READ ${PHP_INCLUDE_DIR}/main/php_version.h PHP_VERSION_CONTENT)
+ string(REGEX MATCH "#define PHP_VERSION_ID[ ]*[0-9]*\n" _PHP_VERSION_ID_MATCH ${PHP_VERSION_CONTENT})
+ if(_PHP_VERSION_ID_MATCH)
+ string(REGEX REPLACE "#define PHP_VERSION_ID[ ]*([0-9]*)\n" "\\1" PHP_VERSION_ID ${_PHP_VERSION_ID_MATCH})
+ endif()
+
+ # Include the needed PHP5 subdirs
+ set(PHP_INCLUDE_DIRS ${PHP_INCLUDE_DIR} ${PHP_INCLUDE_DIR}/main ${PHP_INCLUDE_DIR}/TSRM ${PHP_INCLUDE_DIR}/Zend )
+endif()
+
+if(NOT PHP_VERSION_ID VERSION_LESS ${PHP_MIN_VERSION})
+ include_directories(${PHP_INCLUDE_DIRS})
+ add_library(phpbindings SHARED ${KOLAB_SWIG_PHP_SOURCE_FILE})
+ target_link_libraries(phpbindings kolabxml)
+ set_target_properties(phpbindings PROPERTIES OUTPUT_NAME "kolabformat")
+ set_target_properties(phpbindings PROPERTIES PREFIX "")
+
+ configure_file(test.php ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
+
+ install(TARGETS phpbindings LIBRARY DESTINATION ${PHP_INSTALL_DIR})
+
+ install( FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/kolabformat.php
+ DESTINATION ${PHP_INSTALL_DIR}
+ )
+
+else()
+ message(WARNING "not building php bindings because php was not found")
+endif()