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

Fix cmake script to compile as submodule #399

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
213 changes: 39 additions & 174 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ PROJECT(phpcpp)
# Use CMake File with following options
# PHPCPP_COMPILE_TS Set flag if PHP was compiled with thread safe
# PHPCPP_MSVCRT_STATIC Set flag if you want to compile the MSVC runtime as a static library
# PHPCPP_SHARED Set flag if you want to compile shared library
# PHPCPP_ARCH Set to "x86_64" if architecture and PHP was compiled under x64 or "x86" for 32 bit
# PHPCPP_PHP_PATH The path to PHP sources

set(CMAKE_CXX_STANDARD 11)
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR})

IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
ADD_DEFINITIONS(-DZEND_DEBUG=1)
ADD_DEFINITIONS(-DZEND_DEBUG=1)
ELSE()
ADD_DEFINITIONS(-DZEND_DEBUG=0)
ADD_DEFINITIONS(-DZEND_DEBUG=0)
ENDIF()

IF (PHPCPP_COMPILE_TS)
Expand All @@ -25,6 +27,10 @@ ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ADD_DEFINITIONS(-DBUILDING_PHPCPP)
ADD_DEFINITIONS(-DZEND_WIN32_KEEP_INLINE)

IF (NOT EXISTS "${PHPCPP_PHP_PATH}/main/php.h")
message(SEND_ERROR "The PHPCPP_PHP_PATH variable does not contain PHP sources path")
ENDIF()

IF (MSVC)
# Should compile MSVC runtime static or dll
IF (PHPCPP_MSVCRT_STATIC)
Expand Down Expand Up @@ -54,13 +60,13 @@ IF (MSVC)
ENDIF ()

INCLUDE_DIRECTORIES(
"${PHPCPP_PHP_PATH}/"
"${PHPCPP_PHP_PATH}/main"
"${PHPCPP_PHP_PATH}/Zend"
"${PHPCPP_PHP_PATH}/TSRM"
"${PHPCPP_PHP_PATH}/ext"
"${PHPCPP_PHP_PATH}/build/main"
"${PHPCPP_PHP_PATH}/build/Zend"
"${PHPCPP_PHP_PATH}/"
"${PHPCPP_PHP_PATH}/main"
"${PHPCPP_PHP_PATH}/Zend"
"${PHPCPP_PHP_PATH}/TSRM"
"${PHPCPP_PHP_PATH}/ext"
"${PHPCPP_PHP_PATH}/build/main"
"${PHPCPP_PHP_PATH}/build/Zend"
)
SET(PHP_LIBS "php")
SET(PHP_LIB_PATH "")
Expand All @@ -87,179 +93,38 @@ ELSE()
ENDIF()
ENDIF()

SET(PHPCPP_COMMON_SOURCES
common/modifiers.cpp
common/streambuf.cpp
)
FILE(GLOB PHPCPP_COMMON_SOURCES common/*.cpp)
FILE(GLOB PHPCPP_COMMON_HEADERS common/*.h)
FILE(GLOB PHPCPP_ZEND_SOURCES zend/*.cpp)
FILE(GLOB PHPCPP_ZEND_HEADERS zend/*.h)
FILE(GLOB PHPCPP_HEADERS_INCLUDE include/phpcpp/*.h)

SET(PHPCPP_COMMON_HEADERS
common/extensionbase.h
common/includes.h
common/streambuf.h
)

ADD_LIBRARY(phpcpp-common STATIC
${PHPCPP_COMMON_HEADERS}
${PHPCPP_COMMON_SOURCES}
)

set_target_properties(phpcpp-common
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)

SET(PHPCPP_ZEND_SOURCES
zend/base.cpp
zend/callable.cpp
zend/classbase.cpp
zend/classimpl.cpp
zend/constant.cpp
zend/constantfuncs.cpp
zend/eval.cpp
zend/exception_handler.cpp
zend/exists.cpp
zend/extension.cpp
zend/extensionimpl.cpp
zend/fatalerror.cpp
zend/file.cpp
zend/function.cpp
zend/functor.cpp
zend/global.cpp
zend/globals.cpp
zend/hashmember.cpp
zend/ini.cpp
zend/inivalue.cpp
zend/iteratorimpl.cpp
zend/members.cpp
zend/module.cpp
zend/namespace.cpp
zend/object.cpp
zend/sapi.cpp
zend/script.cpp
zend/streambuf.cpp
zend/streams.cpp
zend/super.cpp
zend/value.cpp
zend/valueiterator.cpp
zend/zendcallable.cpp
zend/zval.cpp
)

SET(PHPCPP_ZEND_HEADERS
zend/arithmetic.h
zend/boolmember.h
zend/callable.h
zend/classimpl.h
zend/compileroptions.h
zend/constantimpl.h
zend/delayedfree.h
zend/executestate.h
zend/extensionimpl.h
zend/extensionpath.h
zend/floatmember.h
zend/functor.h
zend/hashiterator.h
zend/includes.h
zend/init.h
zend/invaliditerator.h
zend/iteratorimpl.h
zend/lowercase.h
zend/member.h
zend/method.h
zend/module.h
zend/nativefunction.h
zend/notimplemented.h
zend/nullmember.h
zend/numericmember.h
zend/objectimpl.h
zend/opcodes.h
zend/origexception.h
zend/parametersimpl.h
zend/property.h
zend/string.h
zend/stringmember.h
zend/symbol.h
zend/symbol.h
zend/traverseiterator.h
zend/valueiteratorimpl.h
)

SET(PHPCPP_HEADERS_INCLUDE
include/argument.h
include/array.h
include/arrayaccess.h
include/base.h
include/byref.h
include/byval.h
include/call.h
include/class.h
include/classbase.h
include/classtype.h
include/constant.h
include/countable.h
include/deprecated.h
include/errors.h
include/exception.h
include/extension.h
include/fatalerror.h
include/file.h
include/function.h
include/global.h
include/globals.h
include/hashmember.h
include/hashparent.h
include/ini.h
include/inivalue.h
include/interface.h
include/iterator.h
include/modifiers.h
include/namespace.h
include/noexcept.h
include/object.h
include/parameters.h
include/platform.h
include/script.h
include/serializable.h
include/streams.h
include/super.h
include/thread_local.h
include/traversable.h
include/type.h
include/value.h
include/valueiterator.h
include/version.h
include/visibility.h
include/zendcallable.h
include/zval.h
)

LINK_DIRECTORIES(${PHP_LIB_PATH})

IF (PHPCPP_SHARED)
ADD_LIBRARY(phpcpp SHARED
${PHPCPP_HEADERS_INCLUDE}
${PHPCPP_ZEND_HEADERS}
${PHPCPP_ZEND_SOURCES}
phpcpp.h
)

TARGET_LINK_LIBRARIES(phpcpp phpcpp-common ${PHP_LIBS})
${PHPCPP_COMMON_HEADERS}
${PHPCPP_COMMON_SOURCES}
${PHPCPP_HEADERS_INCLUDE}
${PHPCPP_ZEND_HEADERS}
${PHPCPP_ZEND_SOURCES}
phpcpp.h
)
ELSE()
ADD_LIBRARY(phpcpp STATIC
${PHPCPP_HEADERS_INCLUDE}
${PHPCPP_ZEND_HEADERS}
${PHPCPP_ZEND_SOURCES}
phpcpp.h
)

TARGET_LINK_LIBRARIES(phpcpp STATIC phpcpp-common ${PHP_LIBS})
${PHPCPP_COMMON_HEADERS}
${PHPCPP_COMMON_SOURCES}
${PHPCPP_HEADERS_INCLUDE}
${PHPCPP_ZEND_HEADERS}
${PHPCPP_ZEND_SOURCES}
phpcpp.h
)
ENDIF()

SET_TARGET_PROPERTIES(phpcpp
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ install:
${MKDIR} ${INSTALL_HEADERS}/phpcpp
${MKDIR} ${INSTALL_LIB}
${CP} phpcpp.h ${INSTALL_HEADERS}
${CP} include/*.h ${INSTALL_HEADERS}/phpcpp
${CP} include/phpcpp/*.h ${INSTALL_HEADERS}/phpcpp
if [ -e ${PHP_SHARED_LIBRARY} ]; then \
${CP} ${PHP_SHARED_LIBRARY} ${INSTALL_LIB}/; \
${LN} ${INSTALL_LIB}/${PHP_SHARED_LIBRARY} ${INSTALL_LIB}/libphpcpp.so.$(SONAME); \
Expand Down
4 changes: 2 additions & 2 deletions common/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
/**
* Public include files
*/
#include "../include/visibility.h"
#include "../include/modifiers.h"
#include "../include/phpcpp/visibility.h"
#include "../include/phpcpp/modifiers.h"

/**
* Generic implementation header files
Expand Down
41 changes: 41 additions & 0 deletions documentation/install.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,44 @@ <h2 id="osx">Compiling on OSX?</h2>
be added to it.
</p>


<h2 id="cmake">Compiling using cmake</h2>
<p>
You could use PHP-CPP as a part of your project. You can install it into your source tree using command
</p>
<p>
<pre class="language-bash"><code>git submodule add git://github.com/CopernicaMarketingSoftware/PHP-CPP.git
</code></pre>
</p>
<p>
For example, part of your CMakeLists.txt may look like this:
</p>
<p>
<pre class="language-cmake"><code>FIND_PROGRAM(PHP_CONFIG NAMES php-config)

execute_process(
COMMAND ${PHP_CONFIG} --include-dir
OUTPUT_VARIABLE PHPCPP_PHP_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# or: SET(PHPCPP_PHP_PATH "/usr/include/php/20160303" CACHE STRING "")
SET(PHPCPP_ARCH "x86_64" CACHE STRING "")

include_directories(PHP-CPP include)
add_subdirectory(PHP-CPP)
target_link_libraries(YourTarget PRIVATE phpcpp)
</code></pre>
</p>
<p>
For full list of options look through CMakeLists.txt file comments.
</p>
<p>
Or you could compile and install PHP-CPP using Makefile and then reference it in your CMakeLists.txt like this:
</p>

<p>
<pre class="language-cmake"><code>find_library(phpcpp REQUIRED)
target_link_libraries(YourTarget PRIVATE phpcpp)
</code></pre>
</p>

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading