Skip to content

Commit

Permalink
support static link
Browse files Browse the repository at this point in the history
  • Loading branch information
zzusoftboy committed Nov 9, 2017
1 parent 6ab9e3c commit e3eb3c7
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 34 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ endif()
set(ZAPI_VERSION
"${ZAPI_VERSION_MAJOR}.${ZAPI_VERSION_MINOR}.${ZAPI_VERSION_PATCH}-${ZAPI_VERSION_STAGE}")

if(NOT ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
set(ZAPI_BUILD_EMBED_MOED ON)
endif()

set(ZAPI_WORKSPACE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(ZAPI_UTILS_DIR "${ZAPI_WORKSPACE_DIR}/utils")
set(ZAPI_SOURCE_DIR "${ZAPI_WORKSPACE_DIR}/src")
Expand All @@ -69,8 +73,7 @@ option(ZAPI_OPT_ENABLE_RUNTIME_TESTS

option(ZAPI_OPT_ENABLE_VERBOSE_DEBUG
"Enable verbose debugging" OFF)

option(ZAPI_OPT_PHPCFG_PATH "Specify the php-config path of host platform" "")
set(ZAPI_OPT_PHPCFG_PATH "" CACHE STRING "Specify the php-config path of host platform.")
set(ZAPI_OPT_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
string(TOUPPER "${CMAKE_BUILD_TYPE}" ZAPI_BUILD_TYPE)

Expand All @@ -90,6 +93,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}")
endif()

string(REPLACE " " ";" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_EXE_LINKER_FLAGS "-Xlinker --allow-shlib-undefined ${CMAKE_EXE_LINKER_FLAGS}")
endif()
Expand Down Expand Up @@ -127,6 +134,10 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") # OR CMAKE_BUILD_TYPE STREQUAL "RelWithD
endif()
endif()

# if we are in embed mode, setup force setup some variables and options
if()
endif()

include(AddLibZendApi)
include(DetectPhpInfo)
include(FindGTest)
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/AddLibZendApi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# DEPENDS targets...
# Same semantics as add_dependencies().
# LINK_COMPONENTS components...
# Same as the variable LLVM_LINK_COMPONENTS.
# Same as the variable ZAPI_LINK_COMPONENTS.
# LINK_LIBS lib_targets...
# Same semantics as target_link_libraries().
# ADDITIONAL_HEADERS
Expand Down Expand Up @@ -168,7 +168,7 @@ function(zapi_add_unittest test_suite test_name)
# libpthreads overrides some standard library symbols, so main
# executable must be linked with it in order to provide consistent
# API for all shared libaries loaded by this executable.
target_link_libraries(${test_name} ${ZAPI_TEMP_GTEST_LIBS} ${PTHREAD_LIB} ${CMAKE_PROJECT_NAME}
target_link_libraries(${test_name} ${ZAPI_TEMP_GTEST_LIBS} ${PTHREAD_LIB} ${ZAPI_PROJECT_NAME}
zapi_libphp)
add_dependencies(${test_suite} ${test_name})
get_target_property(test_suite_folder ${test_suite} FOLDER)
Expand Down
2 changes: 1 addition & 1 deletion include/zapi/lang/Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class ZAPI_DECL_EXPORT Class final : public AbstractClass

template <typename TargetClassType, typename CallalbleType,
CallalbleType callable, bool IsCallable, bool IsMemberCallable>
friend class internal::ClassMethodRegisterImpl;
friend struct internal::ClassMethodRegisterImpl;
};

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions include/zapi/lang/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ZAPI_DECL_EXPORT Parameters final
{}

Parameters(const Parameters &other)
: m_data(other.m_data), m_object(other.m_object)
: m_object(other.m_object), m_data(other.m_data)
{}

Parameters(const ParamCollectionType::iterator begin,
Expand All @@ -61,7 +61,7 @@ class ZAPI_DECL_EXPORT Parameters final
{}

Parameters(Parameters &&params) ZAPI_DECL_NOEXCEPT
: m_data(std::move(params.m_data)), m_object(params.m_object)
: m_object(params.m_object), m_data(std::move(params.m_data))
{}

Parameters(StdClass *object) : m_object(object)
Expand Down
4 changes: 2 additions & 2 deletions include/zapi/lang/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ ZAPI_DECL_EXPORT Modifier operator|(Modifier left, Modifier right);
ZAPI_DECL_EXPORT Modifier operator&(Modifier left, Modifier right);
ZAPI_DECL_EXPORT Modifier &operator|=(Modifier &left, Modifier right);
ZAPI_DECL_EXPORT Modifier &operator&=(Modifier &left, Modifier right);
ZAPI_DECL_EXPORT bool operator==(const Modifier left, int value);
ZAPI_DECL_EXPORT bool operator==(int value, const Modifier &right);
ZAPI_DECL_EXPORT bool operator==(const Modifier left, unsigned long value);
ZAPI_DECL_EXPORT bool operator==(unsigned long value, const Modifier &right);
ZAPI_DECL_EXPORT bool operator==(Modifier left, Modifier right);

using HashTableDataDeleter = dtor_func_t;
Expand Down
2 changes: 2 additions & 0 deletions include/zapi/protocol/Countable.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class ZAPI_DECL_EXPORT Countable
{
public:
virtual zapi_long count() = 0;
virtual ~Countable()
{}
};

} // protocol
Expand Down
2 changes: 2 additions & 0 deletions include/zapi/protocol/Serializable.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class ZAPI_DECL_EXPORT Serializable
public:
virtual std::string serialize() = 0;
virtual void unserialize(const char *input, size_t size) = 0;
virtual ~Serializable()
{}
};

} // protocol
Expand Down
2 changes: 2 additions & 0 deletions include/zapi/protocol/Traversable.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class ZAPI_DECL_EXPORT Traversable
{
public:
virtual AbstractIterator *getIterator() = 0;
virtual ~Traversable()
{}
};

} // protocol
Expand Down
7 changes: 6 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ set(ZAPI_SRC
utils/InternalFuncs.cpp
)

zapi_add_library(${ZAPI_PROJECT_NAME} SHARED ${ZAPI_SRC} ${ZAPI_PUBLIC_HEADERS})
if(BUILD_SHARED_LIBS)
set(ZAPI_BUILD_TYPE SHARED)
else()
set(ZAPI_BUILD_TYPE STATIC)
endif()
zapi_add_library(${ZAPI_PROJECT_NAME} ${ZAPI_BUILD_TYPE} ${ZAPI_SRC} ${ZAPI_PUBLIC_HEADERS})

# setup zapi property
target_compile_options(${ZAPI_PROJECT_NAME}
Expand Down
2 changes: 0 additions & 2 deletions src/ds/ArrayVariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ ArrayIterator ArrayVariant::append(const Variant &value)
zval temp;
ZVAL_COPY(&temp, zvalPtr);
zend_array *selfArrPtr = getZendArrayPtr();
zapi_long cindex = selfArrPtr->nNextFreeElement;
zval *valPtr = zend_hash_next_index_insert(selfArrPtr, &temp);
if (valPtr) {
HashPosition pos = calculateIdxFromZval(valPtr);
Expand All @@ -401,7 +400,6 @@ ArrayIterator ArrayVariant::append(Variant &&value)
ZVAL_COPY_VALUE(&temp, zvalPtr);
std::memset(&value.m_implPtr->m_buffer, 0, sizeof(value.m_implPtr->m_buffer));
zend_array *selfArrPtr = getZendArrayPtr();
zapi_long cindex = selfArrPtr->nNextFreeElement;
zval *valPtr = zend_hash_next_index_insert(selfArrPtr, &temp);
if (valPtr) {
HashPosition pos = calculateIdxFromZval(valPtr);
Expand Down
2 changes: 0 additions & 2 deletions src/ds/StringVariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ bool StringVariant::toBool() const ZAPI_DECL_NOEXCEPT

std::string StringVariant::toString() const ZAPI_DECL_NOEXCEPT
{
zval *self = const_cast<zval *>(getZvalPtr());
zend_string *str = getZendStringPtr();
if (!str) {
return std::string();
Expand Down Expand Up @@ -1415,7 +1414,6 @@ bool operator <(const std::string &lhs, const StringVariant &rhs)

bool operator <=(const char *lhs, const StringVariant &rhs)
{
size_t len = std::max(std::strlen(lhs), rhs.getLength());
return std::memcmp(lhs, rhs.getCStr(), rhs.getLength()) < 0 ||
0 == std::memcmp(lhs, rhs.getCStr(), rhs.getLength());
}
Expand Down
4 changes: 2 additions & 2 deletions src/ds/Variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ bool Variant::isBool() const ZAPI_DECL_NOEXCEPT
if (getType() == Type::False || getType() == Type::True) {
return true;
}
Type type = static_cast<Type>(Z_TYPE_P(const_cast<zval *>(getZvalPtr())));
return getType() == Type::False || getType() == Type::True;
Type type = getType();
return type == Type::False || type == Type::True;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/kernel/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@
//
// Created by softboy on 25/07/2017.

namespace zapi
{
namespace kernel
{

}
} // zapi
12 changes: 6 additions & 6 deletions src/lang/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ Modifier &operator&=(Modifier &left, Modifier right)
return left;
}

bool operator==(int value, Modifier right)
bool operator==(unsigned long value, Modifier right)
{
return static_cast<unsigned int>(right) == value;
return static_cast<unsigned long>(right) == value;
}

bool operator==(Modifier left, int value)
bool operator==(Modifier left, unsigned long value)
{
return static_cast<unsigned int>(left) == value;
return static_cast<unsigned long>(left) == value;
}

bool operator==(Modifier left, Modifier right)
{
return static_cast<unsigned int>(left) == static_cast<unsigned int>(right);
return static_cast<unsigned long>(left) == static_cast<unsigned long>(right);
}

} // lang
} // zapi
} // zapi
4 changes: 2 additions & 2 deletions src/utils/InternalFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace internal

bool parse_namespaces(const std::string &ns, std::list<std::string> &parts)
{
int markPos = 0;
std::string::size_type markPos = 0;
int cycleSepCount = 0;
std::string::value_type curChar;
std::string::size_type len = ns.size();
Expand All @@ -32,7 +32,7 @@ bool parse_namespaces(const std::string &ns, std::list<std::string> &parts)
if (ns[len - 1] == ':') {
return false;
}
int i = 0;
std::string::size_type i = 0;
for (; i < ns.size(); i++) {
curChar = ns[i];
if (':' == curChar) {
Expand Down
6 changes: 2 additions & 4 deletions src/vm/AbstractClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,8 @@ class ScopedFree
{
public:
ScopedFree(ContextMapType &map, const std::string &key)
: m_map(map),
m_key(key)
: m_key(key),
m_map(map)
{}
~ScopedFree()
{
Expand Down Expand Up @@ -844,7 +844,6 @@ void AbstractClassPrivate::magicInvokeForwarder(INTERNAL_FUNCTION_PARAMETERS)
{
CallContext *callContext = reinterpret_cast<CallContext *>(execute_data->func);
assert(callContext);
zend_internal_function *func = &callContext->m_func;
AbstractClass *meta = callContext->m_selfPtr->m_apiPtr;
zend_class_entry *defClassEntry = callContext->m_selfPtr->m_classEntry;
assert(defClassEntry);
Expand Down Expand Up @@ -1131,7 +1130,6 @@ void AbstractClass::registerProperty(const char *name, const zapi::GetterMethodC

void AbstractClass::registerConstant(const Constant &constant)
{
ZAPI_D(AbstractClass);
const zend_constant &zendConst = constant.getZendConstant();
const std::string &name = constant.getName();
switch (Z_TYPE(zendConst.value)) {
Expand Down
3 changes: 2 additions & 1 deletion src/vm/Callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ Callable &Callable::setReturnType(const std::string &clsName) ZAPI_DECL_NOEXCEPT

Callable &Callable::setReturnType(const char *clsName) ZAPI_DECL_NOEXCEPT
{
return setReturnType(clsName);
m_implPtr->m_retClsName = clsName;
return *this;
}

void Callable::setupCallableArgInfo(zend_internal_arg_info *info, const lang::Argument &arg) const
Expand Down
2 changes: 1 addition & 1 deletion tests/dummyext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set(DUMMYEXT_SRCS
add_library(dummyext MODULE
${DUMMYEXT_SRCS})

target_link_libraries(dummyext ${PTHREAD_LIB} ${CMAKE_PROJECT_NAME})
target_link_libraries(dummyext ${PTHREAD_LIB} ${ZAPI_PROJECT_NAME})
set(BUILD_ETC_DIR ${ZAPI_BINARY_DIR}/etc)
set_target_properties(dummyext PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${ZAPI_BINARY_DIR}/extensions
Expand Down
8 changes: 4 additions & 4 deletions tests/dummyext/NativeClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ Variant MagicMethodClass::__call(const std::string &method, Parameters &params)
zapi::out << "MagicMethodClass::__call is called" << std::endl;
if (method == "calculateSum") {
NumericVariant sum;
for (int i = 0; i < params.size(); i++) {
for (Parameters::SizeType i = 0; i < params.size(); i++) {
sum += NumericVariant(params.at(i));
}
return sum;
Expand All @@ -467,7 +467,7 @@ Variant MagicMethodClass::__invoke(Parameters &params) const
{
zapi::out << "MagicMethodClass::__invoke is called" << std::endl;
NumericVariant sum;
for (int i = 0; i < params.size(); i++) {
for (Parameters::SizeType i = 0; i < params.size(); i++) {
sum += NumericVariant(params.at(i));
}
return sum;
Expand Down Expand Up @@ -578,7 +578,7 @@ Variant MagicMethodClass::__callStatic(const std::string &method, Parameters &pa
zapi::out << "MagicMethodClass::__callStatic is called" << std::endl;
if (method == "staticCalculateSum") {
NumericVariant sum;
for (int i = 0; i < params.size(); i++) {
for (Parameters::SizeType i = 0; i < params.size(); i++) {
sum += NumericVariant(params.at(i));
}
return sum;
Expand Down Expand Up @@ -634,7 +634,7 @@ Variant ObjectVariantClass::__invoke(Parameters &params) const
zapi::out << "ObjectVariantClass::__invoke invoked" << std::endl;
StringVariant str(params.at(0).getUnDerefZvalPtr(), true);
NumericVariant result;
for (int i = 1; i < params.size(); i++) {
for (Parameters::SizeType i = 1; i < params.size(); i++) {
result += NumericVariant(params.at(i));
}
str = "zapi";
Expand Down

0 comments on commit e3eb3c7

Please sign in to comment.