Skip to content

Commit 93bc4f8

Browse files
author
Maxim Leontyev
committed
Dependencies are compiled as submodules
1 parent 89d25ce commit 93bc4f8

File tree

8 files changed

+90
-53
lines changed

8 files changed

+90
-53
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "modules/json"]
2+
path = modules/json
3+
url = git://github.com/nlohmann/json.git
4+
[submodule "modules/td"]
5+
path = modules/td
6+
url = git://github.com/tdlib/td.git

CMakeLists.txt

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,92 @@ set(EXT_NAME tdlib)
44
set(EXT_VERSION 0.0.7)
55
project(${EXT_NAME} VERSION ${EXT_VERSION} LANGUAGES CXX)
66

7-
set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
7+
set(CMAKE_CXX_STANDARD 14)
8+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
89

9-
find_package(Td 1.3.0 REQUIRED)
10-
if(NOT Td_FOUND)
11-
message(SEND_ERROR "Failed to find Td")
12-
return()
13-
endif()
14-
15-
#find_library(PHPCPP phpcpp)
16-
#if(NOT PHPCPP)
17-
# message(SEND_ERROR "Failed to find PHP-CPP")
18-
# return()
19-
#endif()
2010

21-
find_file(NLOHMANN_JSON_INCLUDE_FILE nlohmann/json.hpp)
22-
if(NOT NLOHMANN_JSON_INCLUDE_FILE)
23-
message(SEND_ERROR "Failed to find nlohmann_json")
24-
endif()
2511

2612
FIND_PROGRAM(PHP_CONFIG NAMES php-config)
2713
if(NOT PHP_CONFIG)
2814
message(SEND_ERROR "Failed to find php-config")
2915
return()
3016
endif()
17+
18+
execute_process(
19+
COMMAND ${PHP_CONFIG} --include-dir
20+
OUTPUT_VARIABLE PHPCPP_PHP_PATH
21+
OUTPUT_STRIP_TRAILING_WHITESPACE
22+
)
3123
execute_process(
32-
COMMAND ${PHP_CONFIG} --configure-options
33-
COMMAND sed -ne "s/^.*--with-config-file-scan-dir=\\([^ ]*\\).*/\\1/p"
34-
OUTPUT_VARIABLE PHP_CONFIG_DIR
35-
OUTPUT_STRIP_TRAILING_WHITESPACE
24+
COMMAND ${PHP_CONFIG} --configure-options
25+
COMMAND sed -ne "s/^.*--with-config-file-scan-dir=\\([^ ]*\\).*/\\1/p"
26+
OUTPUT_VARIABLE PHP_CONFIG_DIR
27+
OUTPUT_STRIP_TRAILING_WHITESPACE
3628
)
3729
execute_process(
38-
COMMAND ${PHP_CONFIG} --extension-dir
39-
OUTPUT_VARIABLE PHP_EXTENSIONS_DIR
40-
OUTPUT_STRIP_TRAILING_WHITESPACE
30+
COMMAND ${PHP_CONFIG} --extension-dir
31+
OUTPUT_VARIABLE PHP_EXTENSIONS_DIR
32+
OUTPUT_STRIP_TRAILING_WHITESPACE
4133
)
4234
execute_process(
43-
COMMAND ${PHP_CONFIG} --vernum
44-
OUTPUT_VARIABLE PHP_VERSION_NUMBER
45-
OUTPUT_STRIP_TRAILING_WHITESPACE
35+
COMMAND ${PHP_CONFIG} --vernum
36+
OUTPUT_VARIABLE PHP_VERSION_NUMBER
37+
OUTPUT_STRIP_TRAILING_WHITESPACE
4638
)
4739

4840
if(PHP_VERSION_NUMBER LESS 70000)
4941
message(SEND_ERROR "PHP-CPP works only with PHP ^7.0. For older PHP versions, use the PHP-CPP-LEGACY instead.")
5042
return()
5143
endif()
5244

53-
set(SOURCE_FILES tdlib.cpp include/TDLib/BaseJsonClient.cpp include/TDLib/JsonClient.cpp include/TDApi/TDLibParameters.cpp include/TDApi/TDLibLogConfiguration.cpp)
45+
46+
47+
48+
49+
add_subdirectory(modules/td)
50+
51+
52+
# PHP-CPP now has incorrect CMakeLists.txt
53+
# Waiting for fixes in PR 399 to be applied
54+
# todo: uncomment when the PHP-CPP problems will be fixed
55+
#SET(PHPCPP_ARCH "x86_64" CACHE STRING "")
56+
#include_directories(modules/PHP-CPP modules/PHP-CPP/include)
57+
#add_subdirectory(modules/PHP-CPP)
58+
find_library(PHPCPP phpcpp)
59+
if(NOT PHPCPP)
60+
message(SEND_ERROR "Failed to find PHP-CPP")
61+
return()
62+
endif()
63+
64+
65+
set(JSON_BuildTests OFF CACHE INTERNAL "")
66+
add_subdirectory(modules/json)
67+
68+
69+
70+
set(SOURCE_FILES
71+
tdlib.cpp
72+
include/TDLib/BaseJsonClient.cpp
73+
include/TDLib/JsonClient.cpp
74+
include/TDApi/TDLibParameters.cpp
75+
include/TDApi/TDLibLogConfiguration.cpp
76+
include/td_json_client_func.cpp
77+
)
5478
set(EXT_INI_FILE ${EXT_NAME}.ini)
5579

56-
set(CMAKE_SHARED_LIBRARY_PREFIX "")
5780

81+
set(CMAKE_SHARED_LIBRARY_PREFIX "")
5882
add_library(${EXT_NAME} SHARED ${SOURCE_FILES})
59-
target_link_libraries(${EXT_NAME} phpcpp Td::TdJson Td::TdStatic)
83+
84+
85+
target_link_libraries(${EXT_NAME}
86+
PRIVATE
87+
Td::TdJson
88+
Td::TdStatic
89+
nlohmann_json::nlohmann_json
90+
PUBLIC
91+
phpcpp
92+
)
6093

6194
add_custom_command(TARGET ${EXT_NAME}
6295
POST_BUILD

README.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,16 @@ $client->destroy();
6161
```
6262

6363
## Required
64-
- [TDLib v1.3.0][1]
65-
```bash
66-
git clone https://github.com/tdlib/td.git
67-
cd td && mkdir build && cd build
68-
cmake -DCMAKE_BUILD_TYPE=Release ..
69-
cmake --build .
70-
sudo cmake --build . --target install
71-
```
7264
- [PHP-CPP v2.0.0][2]
65+
66+
All dependencies are installed via git submodules. But PHP-CPP
67+
currently has buggy CMake configuration and should be globally installed as a library.
68+
7369
```bash
7470
git clone https://github.com/CopernicaMarketingSoftware/PHP-CPP.git
7571
cd PHP-CPP
7672
make
7773
sudo make install
78-
```
79-
- [nlohmann/json v3.2.0 (JSON for Modern C++)][3]
80-
```bash
81-
git clone https://github.com/nlohmann/json.git
82-
cd json && mkdir build && cd build
83-
cmake ..
84-
make install
8574
```
8675

8776
## install extension

include/td_json_client_func.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
#include <td/telegram/td_json_client.h>
12
#include "TDLib/BaseJsonClient.hpp"
23
#include "td_json_client_func.hpp"
34

45
Php::Value td_json_client_func_create()
56
{
67
void *client_ptr = td_json_client_create();
7-
BaseJsonClient *client = new BaseJsonClient(client_ptr);
8+
auto *client = new BaseJsonClient(client_ptr);
89
return Php::Object("TDLib\\BaseJsonClient", client);
910
}
1011

1112
void td_json_client_func_destroy(Php::Parameters &params)
1213
{
1314
Php::Value object = params[0];
1415
if(!object.instanceOf("TDLib\\BaseJsonClient")) throw Php::Exception("First parameter must be instance of TDLib\\BaseJsonClient.");
15-
BaseJsonClient *client = (BaseJsonClient *)object.implementation();
16+
auto *client = (BaseJsonClient *)object.implementation();
1617

1718
client->destroy();
1819
}
@@ -22,7 +23,7 @@ Php::Value td_json_client_func_execute(Php::Parameters &params)
2223
Php::Value object = params[0];
2324
if(!object.instanceOf("TDLib\\BaseJsonClient")) throw Php::Exception("First parameter must be instance of TDLib\\BaseJsonClient.");
2425
const char *query = params[1];
25-
BaseJsonClient *client = (BaseJsonClient *)object.implementation();
26+
auto *client = (BaseJsonClient *)object.implementation();
2627

2728
std::string result = client->execute(query);
2829
return result;
@@ -33,7 +34,7 @@ void td_json_client_func_send(Php::Parameters &params)
3334
Php::Value object = params[0];
3435
if(!object.instanceOf("TDLib\\BaseJsonClient")) throw Php::Exception("First parameter must be instance of TDLib\\BaseJsonClient.");
3536
const char *query = params[1];
36-
BaseJsonClient *client = (BaseJsonClient *)object.implementation();
37+
auto *client = (BaseJsonClient *)object.implementation();
3738

3839
client->send(query);
3940
}
@@ -43,7 +44,7 @@ Php::Value td_json_client_func_receive(Php::Parameters &params)
4344
Php::Value object = params[0];
4445
if(!object.instanceOf("TDLib\\BaseJsonClient")) throw Php::Exception("First parameter must be instance of TDLib\\BaseJsonClient.");
4546
double timeout = params[1];
46-
BaseJsonClient *client = (BaseJsonClient *)object.implementation();
47+
auto *client = (BaseJsonClient *)object.implementation();
4748

4849
std::string result = client->receive(timeout);
4950
return result;

include/td_json_client_func.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
#ifndef TDLIB_TD_JSON_CLIENT_FUNC_H
2-
#define TDLIB_TD_JSON_CLIENT_FUNC_H
1+
#ifndef TD_JSON_CLIENT_FUNC_H
2+
#define TD_JSON_CLIENT_FUNC_H
3+
4+
#include <phpcpp.h>
35

46
Php::Value td_json_client_func_create();
7+
58
void td_json_client_func_destroy(Php::Parameters &params);
9+
610
Php::Value td_json_client_func_execute(Php::Parameters &params);
11+
712
void td_json_client_func_send(Php::Parameters &params);
13+
814
Php::Value td_json_client_func_receive(Php::Parameters &params);
915

10-
#endif // TDLIB_TD_JSON_CLIENT_FUNC_H
16+
#endif

modules/json

Submodule json added at 8584994

modules/td

Submodule td added at 101aa73

tdlib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "tdlib.hpp"
99

10-
#include "include/td_json_client_func.cpp"
10+
#include "include/td_json_client_func.hpp"
1111
#include "include/TDLib/JsonClient.hpp"
1212
#include "include/TDApi/TDLibParameters.hpp"
1313
#include "include/TDApi/TDLibLogConfiguration.hpp"

0 commit comments

Comments
 (0)