Skip to content
Snippets Groups Projects
Commit b732fe8f authored by Alexandr Mruchok's avatar Alexandr Mruchok
Browse files

[*] refactoring in CmakeLists

[*] changed main() to cellframe_node_Main, cellframe_node__cli_Main, cellframe_node_tool_Main for android
[+] Added cellframe_node.h
parent 32d49b8d
No related branches found
No related tags found
No related merge requests found
project(cellframe-node C)
cmake_minimum_required(VERSION 3.1)
set(NODE_TARGET "${PROJECT_NAME}" )
set(NODE_CLI_TARGET "${PROJECT_NAME}-cli" )
set(NODE_TOOL_TARGET "${PROJECT_NAME}-tool")
include(scripts/OS_Detection.cmake)
if(DAP_DEBUG_BUILD)
......@@ -170,7 +174,9 @@ add_subdirectory(libdap-stream-ch-chain)
add_subdirectory(libdap-stream-ch-chain-net)
add_subdirectory(libdap-stream-ch-chain-net-srv)
add_subdirectory(libdap-chain-global-db)
#if (NOT ANDROID)
add_subdirectory(libdap-chain-global-db)
#endif()
#add_subdirectory(libdap-stream-ch-chat)
if(BUILD_CELLFRAME_NODE_TESTS)
......@@ -178,18 +184,40 @@ if(BUILD_CELLFRAME_NODE_TESTS)
add_subdirectory(test)
endif()
set( NODE_SOURCES
sources/main.c
sources/sig_unix_handler.c
)
set( NODE_CLI_SOURCES
sources/main_node_cli.c
sources/main_node_cli_shell.c
sources/main_node_cli_net.c
)
set( NODE_TOOL_SOURCES
sources/main_node_tool.c
)
if(UNIX)
add_executable(${PROJECT_NAME} "sources/main.c" "sources/sig_unix_handler.c")
add_executable(${PROJECT_NAME}-cli "sources/main_node_cli.c" "sources/main_node_cli_shell.c" "sources/main_node_cli_net.c" )
add_executable(${PROJECT_NAME}-tool "sources/main_node_tool.c" )
if(ANDROID)
add_library(${PROJECT_NAME} SHARED
${NODE_SOURCES}
${NODE_CLI_SOURCES}
${NODE_TOOL_SOURCES}
sources/cellframe_node.h
)
else()
add_executable(${PROJECT_NAME} ${NODE_SOURCES})
add_executable(${NODE_CLI_TARGET} ${NODE_CLI_SOURCES})
add_executable(${NODE_TOOL_TARGET} ${NODE_TOOL_SOURCES})
endif()
endif()
if(WIN32)
add_executable(${PROJECT_NAME} "sources/main.c" "sources/exh_win32.c" "sources/sig_win32_handler.c")
add_executable(${PROJECT_NAME}-cli "sources/main_node_cli.c" "sources/main_node_cli_shell.c" "sources/main_node_cli_net.c" )
add_executable(${PROJECT_NAME}-tool "sources/main_node_tool.c" )
add_executable(${NODE_CLI_TARGET} "sources/main_node_cli.c" "sources/main_node_cli_shell.c" "sources/main_node_cli_net.c" )
add_executable(${NODE_TOOL_TARGET} "sources/main_node_tool.c" )
target_link_libraries(${PROJECT_NAME}-cli dap_chain_net
target_link_libraries(${NODE_CLI_TARGET} dap_chain_net
${CMAKE_CURRENT_SOURCE_DIR}/lib/[x86_64CLANG]/libjson-c[x86_64CLANG].a
${CMAKE_CURRENT_SOURCE_DIR}/lib/[x86_64CLANG]/wepoll[x86_64CLANG].a
${CMAKE_CURRENT_SOURCE_DIR}/lib/[x86_64CLANG]/libsqlite3[x86_64CLANG].a
......@@ -222,8 +250,8 @@ if(WIN32)
Secur32
userenv
)
set_property(TARGET ${PROJECT_NAME}-cli APPEND_STRING PROPERTY LINK_FLAGS "-mconsole")
target_link_libraries(${PROJECT_NAME}-tool dap_core dap_crypto dap_server_core dap_enc_server dap_udp_server dap_session
set_property(TARGET ${NODE_CLI_TARGET} APPEND_STRING PROPERTY LINK_FLAGS "-mconsole")
target_link_libraries(${NODE_TOOL_TARGET} dap_core dap_crypto dap_server_core dap_enc_server dap_udp_server dap_session
dap_enc_server dap_stream dap_stream_ch_vpn dap_stream_ch_chain dap_stream_ch_chain_net
dap_stream_ch_chain_net_srv dap_chain dap_chain_crypto dap_client
dap_chain_cs_dag dap_chain_cs_dag_poa dap_chain_cs_dag_pos
......@@ -263,7 +291,7 @@ if(WIN32)
Secur32
userenv
)
set_property(TARGET ${PROJECT_NAME}-tool APPEND_STRING PROPERTY LINK_FLAGS "-mconsole")
set_property(TARGET ${NODE_TOOL_TARGET} APPEND_STRING PROPERTY LINK_FLAGS "-mconsole")
target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_server_core dap_enc_server dap_udp_server dap_session
......@@ -315,22 +343,23 @@ endif()
#add_executable(${PROJECT_NAME}-tool "sources/main_node_tool.c" )
if(UNIX)
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "-D_GNU_SOURCE")
target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_crypto dap_server_core dap_enc_server dap_udp_server dap_session
set(NODE_LIBRARIES
dap_core dap_crypto dap_crypto dap_server_core dap_enc_server dap_udp_server dap_session
dap_enc_server dap_stream dap_stream_ch_vpn dap_stream_ch_chain dap_stream_ch_chain_net
dap_stream_ch_chain_net_srv dap_chain dap_chain_crypto dap_client
dap_chain_cs_dag dap_chain_cs_dag_poa dap_chain_cs_dag_pos
dap_chain_net dap_chain_net_srv dap_chain_net_srv_app dap_chain_net_srv_app_db
dap_chain_net_srv_datum dap_chain_net_srv_datum_pool dap_chain_net_srv_vpn
dap_chain_wallet dap_chain_global_db dap_chain_mempool dap_chain_gdb m magic
dap_cuttdb
#dap_server_http_db
)
dap_cuttdb)
target_link_libraries(${PROJECT_NAME}-cli m dap_chain_net curl dap_cuttdb )
set(NODE_CLI_LIBRARIES
m dap_chain_net curl dap_cuttdb)
target_link_libraries(${PROJECT_NAME}-tool dap_core dap_crypto dap_server_core dap_enc_server dap_udp_server dap_session
set(NODE_TOOL_LIBRARIES
dap_core dap_crypto dap_server_core dap_enc_server dap_udp_server dap_session
dap_enc_server dap_stream dap_stream_ch_vpn dap_stream_ch_chain dap_stream_ch_chain_net
dap_stream_ch_chain_net_srv dap_chain dap_chain_crypto dap_client
dap_chain_cs_dag dap_chain_cs_dag_poa dap_chain_cs_dag_pos
......@@ -340,32 +369,33 @@ if(UNIX)
dap_core
)
if(NOT ANDROID)
target_link_libraries(${PROJECT_NAME}
pthread
dap_server_http_db_auth
dap_cuttdb
)
target_link_libraries(${PROJECT_NAME}-cli pthread)
target_link_libraries(${PROJECT_NAME}-tool pthread)
if(ANDROID )
set(ALL_LIBRARIES ${NODE_LIBRARIES} ${NODE_CLI_LIBRARIES} ${NODE_TOOL_LIBRARIES} log)
endif()
list(REMOVE_DUPLICATES ALL_LIBRARIES)
target_link_libraries(${NODE_TARGET} ${ALL_LIBRARIES})
else()
target_link_libraries(${NODE_TARGET} ${NODE_LIBRARIES} pthread dap_server_http_db_auth dap_cuttdb )
target_link_libraries(${NODE_CLI_TARGET} ${NODE_CLI_LIBRARIES} pthread )
target_link_libraries(${NODE_TOOL_TARGET} ${NODE_TOOL_LIBRARIES} pthread )
endif()
endif()
target_include_directories(${PROJECT_NAME} INTERFACE .)
if(UNIX)
target_include_directories(${PROJECT_NAME}-cli INTERFACE .)
target_include_directories(${PROJECT_NAME}-tool INTERFACE .)
if(UNIX AND NOT ANDROID)
target_include_directories(${NODE_CLI_TARGET} INTERFACE .)
target_include_directories(${NODE_TOOL_TARGET} INTERFACE .)
endif()
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*")
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
if(UNIX)
INSTALL(TARGETS ${PROJECT_NAME}-cli DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
INSTALL(TARGETS ${PROJECT_NAME}-tool DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
if(UNIX AND NOT ANDROID)
INSTALL(TARGETS ${NODE_CLI_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
INSTALL(TARGETS ${NODE_TOOL_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin )
endif()
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ )
......
#ifndef MAIN_H
#define MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __ANDROID__
#define LOG_PATH
int cellframe_node_Main(int argc, const char **argv);
int cellframe_node__cli_Main(int argc, const char *argv[]);
int cellframe_node_tool_Main(int argc, const char **argv);
#endif
#ifdef __cplusplus
}
#endif
#endif // MAIN_H
......@@ -129,13 +129,21 @@
#define MEMPOOL_URL "/mempool"
#define MAIN_URL "/"
#ifdef __ANDROID__
#include "cellframe_node.h"
#endif
void parse_args( int argc, const char **argv );
void exit_if_server_already_running( void );
static char s_pid_file_path[MAX_PATH];
static void s_auth_callback(enc_http_delegate_t *a_delegate, void * a_arg);
#ifdef __ANDROID__
int cellframe_node_Main(int argc, const char **argv)
#else
int main( int argc, const char **argv )
#endif
{
dap_server_t *l_server = NULL; // DAP Server instance
bool bDebugMode = true;
......@@ -154,6 +162,7 @@ int main( int argc, const char **argv )
memcpy(l_log_file_path, s_sys_dir_path, l_sys_dir_path_len);
memcpy(s_pid_file_path, s_sys_dir_path, l_sys_dir_path_len);
#endif
dap_snprintf(l_log_file_path + l_sys_dir_path_len, sizeof (l_log_file_path), "%s/%s.log", SYSTEM_LOGS_DIR, DAP_APP_NAME);
dap_mkdir_with_parents(SYSTEM_LOGS_DIR);
......@@ -161,6 +170,7 @@ int main( int argc, const char **argv )
printf( "Fatal Error: Can't init common functions module" );
return -2;
}
dap_snprintf(s_sys_dir_path + l_sys_dir_path_len, sizeof(s_sys_dir_path), "%s", SYSTEM_CONFIGS_DIR);
dap_config_init( s_sys_dir_path );
memset(s_sys_dir_path + l_sys_dir_path_len, '\0', MAX_PATH - l_sys_dir_path_len);
......
......@@ -34,6 +34,10 @@
#include "main_node_cli_net.h"
#include "main_node_cli_shell.h"
#ifdef __ANDROID__
#include "cellframe_node.h"
#endif
#ifdef _WIN32
#include "registry.h"
#endif
......@@ -181,9 +185,14 @@ int shell_reader_loop()
return 0;
}
int main(int argc, const char * argv[])
#ifdef __ANDROID__
int cellframe_node__cli_Main(int argc, const char *argv[])
#else
int main(int argc, const char *argv[])
#endif
{
#ifdef _WIN32
#if defined (_WIN32)
dap_sprintf(s_sys_dir_path, "%s/%s", regGetUsrPath(), DAP_APP_NAME);
l_sys_dir_path_len = strlen(s_sys_dir_path);
#endif
......
......@@ -101,13 +101,23 @@
#define MAIN_URL "/"
#define LOG_TAG "main_node_tool"
#ifdef __ANDROID__
#include "cellframe_node.h"
#endif
static int s_init( int argc, const char * argv[] );
static void s_help( );
static char s_system_ca_dir[MAX_PATH];
static const char *s_appname = "cellframe-node-tool";
int main(int argc, const char **argv) {
#ifdef __ANDROID__
int cellframe_node_tool_Main(int argc, const char **argv)
#else
int main(int argc, const char **argv)
#endif
{
int ret = s_init( argc, argv );
if ( ret ) {
......@@ -364,12 +374,14 @@ static int s_init( int argc, const char **argv )
{
char l_log_file_path[MAX_PATH];
l_sys_dir_path_len = 0;
#ifdef _WIN32
dap_sprintf(s_sys_dir_path, "%s/%s", regGetUsrPath(), DAP_APP_NAME);
l_sys_dir_path_len = strlen(s_sys_dir_path);
memcpy(s_system_ca_dir, s_sys_dir_path, l_sys_dir_path_len);
memcpy(l_log_file_path, s_sys_dir_path, l_sys_dir_path_len);
#endif
memcpy(l_log_file_path + l_sys_dir_path_len, SYSTEM_LOGS_DIR, sizeof(SYSTEM_LOGS_DIR));
dap_sprintf(l_log_file_path + l_sys_dir_path_len + sizeof(SYSTEM_LOGS_DIR) - 1, "/%s_tool_logs.txt", DAP_APP_NAME);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment