10 Commits

Author SHA1 Message Date
9e5a5970a3 Improved PIBlockingDeque constructors
- resolve creation from constant (see test construct_from_constant_is_max_size_eq_capacity)
- add tests for constructors
2020-08-11 12:30:28 +03:00
46d93c6c9f Improved PIBlockingDeque behaviour and unit tests for put, offer, take methods
- Methods put, offer, take begins working with move and copy semantics
- Mocking queue condition variables with GMock in Unit tests
- Rewrite part of unit tests
2020-08-07 19:12:09 +03:00
662a2fc464 Refactor PIBlockingDequeue 2020-08-07 10:10:05 +03:00
194389ef6d Refactor templates & submit doc 2020-08-06 13:23:49 +03:00
3cfdda7365 PIThreadPoolExecutor & PIBlockingDequeue improvements
- add support move & copy semantic
- introduce submit method for executor with future result
2020-08-05 22:59:33 +03:00
3ec1ecfb5b refactor concurrent module code 2020-08-04 16:39:08 +03:00
be51728570 Merge remote-tracking branch 'origin/master' into concurrent 2020-08-03 17:48:36 +03:00
41e54e5859 Merge pip2 2020-08-03 17:47:19 +03:00
badaa01deb Merge remote-tracking branch 'origin/master' into concurrent
# Conflicts:
#	lib/main/thread/pithreadpoolexecutor.cpp
#	lib/main/thread/pithreadpoolexecutor.h
#	tests/concurrent/ExecutorIntegrationTest.cpp
#	tests/concurrent/ExecutorUnitTest.cpp
#	tests/concurrent/testutil.h
2020-08-03 10:18:52 +03:00
8efd2cf447 Rewrite executor to template & come back executor unit tests 2020-07-17 18:36:28 +03:00
294 changed files with 5542 additions and 8090 deletions

1
.gitignore vendored
View File

@@ -2,4 +2,3 @@
/.svn /.svn
/doc/rtf /doc/rtf
_unsused _unsused
CMakeLists.txt.user*

View File

@@ -1,37 +1,46 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0017 NEW) # need include() with .cmake cmake_policy(SET CMP0017 NEW) # need include() with .cmake
project(pip) project(pip)
set(pip_MAJOR 2) set(_PIP_MAJOR 1)
set(pip_MINOR 15) set(_PIP_MINOR 99)
set(pip_REVISION 1) set(_PIP_REVISION 3)
set(pip_SUFFIX ) set(_PIP_SUFFIX _prebeta)
set(pip_COMPANY SHS) set(_PIP_COMPANY SHS)
set(pip_DOMAIN org.SHS) set(_PIP_DOMAIN org.SHS)
if ("x${CMAKE_MODULE_PATH}" STREQUAL "x") if ("x${CMAKE_MODULE_PATH}" STREQUAL "x")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
endif() endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
set(PIP_BUILD 1)
include(CheckFunctionExists) include(CheckFunctionExists)
include(GenerateExportHeader)
include(DeployMacros)
include(PIPMacros) include(PIPMacros)
include(SHSTKMacros) if(NOT DEFINED BUILD_NUMBER)
set(BUILD_NUMBER 9999)
shstk_begin_project(pip PIP) endif()
if("x${BUILD_NUMBER}" STREQUAL "x")
set(BUILD_NUMBER 0)
endif()
set(_ICU_DEFAULT OFF) set(_ICU_DEFAULT OFF)
if((NOT DEFINED WIN32) AND (NOT DEFINED ANDROID_PLATFORM) AND (NOT DEFINED APPLE)) if((NOT DEFINED WIN32) AND (NOT DEFINED ANDROID_PLATFORM) AND (NOT DEFINED APPLE))
set(_ICU_DEFAULT ON) set(_ICU_DEFAULT ON)
endif() endif()
set(PIP_DLL_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE STRING "")
# Options # Options
option(ICU "ICU support for convert codepages" ${_ICU_DEFAULT}) option(ICU "ICU support for convert codepages" ${_ICU_DEFAULT})
option(STD_IOSTREAM "Building with std iostream operators support" OFF) option(STD_IOSTREAM "Building with std iostream operators support" OFF)
option(INTROSPECTION "Build with introspection" OFF) option(INTROSPECTION "Build with introspection" OFF)
option(LIB "System install" ON)
option(STATIC_LIB OFF)
option(TESTS "Build tests and perform their before install step" OFF) option(TESTS "Build tests and perform their before install step" OFF)
option(COVERAGE "Build project with coverage info" OFF)
set(PIP_UTILS 1) set(PIP_UTILS 1)
if(LIBPROJECT)
set(PIP_UTILS ${UTILS})
endif()
set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
@@ -57,13 +66,11 @@ macro(pip_module NAME LIBS LABEL INCLUDES MSG)
set(HS) set(HS)
set(PHS) set(PHS)
set(CRES) set(CRES)
file(GLOB_RECURSE CPPS "libs/${NAME}/*.cpp") file(GLOB_RECURSE CPPS "lib/${NAME}/*.cpp")
file(GLOB_RECURSE HS "libs/${NAME}/*.h") file(GLOB_RECURSE HS "lib/${NAME}/*.h")
file(GLOB_RECURSE PHS "libs/${NAME}/*_p.h") file(GLOB_RECURSE PHS "lib/${NAME}/*_p.h")
file(GLOB_RECURSE RES "libs/${NAME}/*.conf") file(GLOB_RECURSE RES "lib/${NAME}/*conf.h")
if (NOT "x${PHS}" STREQUAL "x") list(REMOVE_ITEM HS "${PHS}")
list(REMOVE_ITEM HS ${PHS})
endif()
list(APPEND HDRS ${HS}) list(APPEND HDRS ${HS})
list(APPEND PHDRS ${PHS}) list(APPEND PHDRS ${PHS})
@@ -77,11 +84,11 @@ macro(pip_module NAME LIBS LABEL INCLUDES MSG)
string(TOUPPER "${_target}" DEF_NAME) string(TOUPPER "${_target}" DEF_NAME)
set(PIP_MSG_${NAME} "yes${MSG}") set(PIP_MSG_${NAME} "yes${MSG}")
import_version(${_target} pip) import_version(${_target} PIP)
set_deploy_property(${_target} ${pip_LIB_TYPE} set_deploy_property(${_target} ${PIP_LIB_TYPE}
LABEL "${LABEL}" LABEL "${LABEL}"
FULLNAME "${pip_DOMAIN}.${_target}" FULLNAME "${_PIP_DOMAIN}.${_target}"
COMPANY "${pip_COMPANY}" COMPANY "${_PIP_COMPANY}"
INFO "Platform-Independent Primitives") INFO "Platform-Independent Primitives")
make_rc(${_target} _RC) make_rc(${_target} _RC)
@@ -94,22 +101,23 @@ macro(pip_module NAME LIBS LABEL INCLUDES MSG)
endif() endif()
endforeach() endforeach()
if (NOT "x${RES}" STREQUAL "x") if (NOT "${RES}" STREQUAL "")
pip_resources(CRES "${RES}") pip_resources(CRES "${RES}")
endif() endif()
add_definitions(-D${DEF_NAME}) add_definitions(-D${DEF_NAME})
add_library(${_target} ${pip_LIB_TYPE} ${CPPS} ${CRES} ${_RC}) add_library(${_target} ${PIP_LIB_TYPE} ${CPPS} ${CRES} ${_RC})
target_include_directories(${_target} PUBLIC ${PIP_INCLUDES}) if (NOT "${RES}" STREQUAL "")
if (NOT "x${RES}" STREQUAL "x")
add_dependencies(${_target} pip_rc) add_dependencies(${_target} pip_rc)
endif() endif()
if (NOT "x${INCLUDES}" STREQUAL "x") if (NOT "${INCLUDES}" STREQUAL "")
target_include_directories(${_target} PRIVATE ${INCLUDES}) target_include_directories(${_target} PRIVATE ${INCLUDES})
endif() endif()
generate_export_header(${_target})
list(APPEND HDRS "${CMAKE_CURRENT_BINARY_DIR}/${_target}_export.h")
list(APPEND PIP_EXPORTS "${DEF_NAME}_EXPORT") list(APPEND PIP_EXPORTS "${DEF_NAME}_EXPORT")
target_link_libraries(${_target} ${LINK_LIBS}) target_link_libraries(${_target} ${LINK_LIBS})
list(APPEND PIP_MODULES ${_target}) list(APPEND PIP_MODULES ${_target})
if (NOT "x${LIBS}" STREQUAL "x") if (NOT "${LIBS}" STREQUAL "")
list(APPEND LIBS_STATUS ${LIBS}) list(APPEND LIBS_STATUS ${LIBS})
endif() endif()
endmacro() endmacro()
@@ -122,9 +130,67 @@ macro(pip_find_lib NAME)
endif() endif()
endmacro() endmacro()
# Version if (DEFINED ENV{QNX_HOST} OR PIP_FREERTOS)
list(APPEND HDRS "${CMAKE_CURRENT_BINARY_DIR}/pip_version.h") set(STATIC_LIB ON)
endif()
if(STATIC_LIB)
set(PIP_LIB_TYPE STATIC)
set(PIP_LIB_TYPE_MSG "Static")
add_definitions(-DPIP_STATIC_DEFINE)
else()
set(PIP_LIB_TYPE SHARED)
set(PIP_LIB_TYPE_MSG "Shared")
endif()
# Version
set_version(PIP
MAJOR "${_PIP_MAJOR}"
MINOR "${_PIP_MINOR}"
REVISION "${_PIP_REVISION}"
BUILD "${BUILD_NUMBER}"
SUFFIX "${_PIP_SUFFIX}"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/piversion.h")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PIP_SRC_MAIN}/piversion.h")
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/${PIP_SRC_MAIN}/piversion.h")
endif()
list(APPEND HDRS "${CMAKE_CURRENT_BINARY_DIR}/piversion.h")
if(MINGW)
find_package(MinGW REQUIRED)
list(APPEND CMAKE_LIBRARY_PATH ${MINGW_LIB})
else()
if(APPLE)
if(CMAKE_CROSSCOMPILING)
set(CMAKE_INSTALL_NAME_DIR "@rpath")
else()
include_directories(/usr/local/include)
link_directories(/usr/local/lib)
endif()
set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks;@executable_path/lib;@loader_path/../lib")
set(CMAKE_MACOSX_RPATH 1)
else()
set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib")
endif()
endif()
if(LIB)
if(WIN32)
if(MINGW)
set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
endif()
else()
if (DEFINED ANDROID_PLATFORM)
set(CMAKE_INSTALL_PREFIX ${ANDROID_SYSTEM_LIBRARY_PATH}/usr)
else()
if(CMAKE_CROSSCOMPILING)
set(CMAKE_INSTALL_PREFIX ${CMAKE_STAGING_PREFIX})
else()
set(CMAKE_INSTALL_PREFIX ${INSTALL_PREFIX}/usr/local)
endif()
endif()
endif()
endif()
if (NOT DEFINED PIP_CMG) if (NOT DEFINED PIP_CMG)
if (CMAKE_CROSSCOMPILING OR (DEFINED ANDROID_PLATFORM)) if (CMAKE_CROSSCOMPILING OR (DEFINED ANDROID_PLATFORM))
@@ -144,15 +210,18 @@ get_filename_component(C_COMPILER "${CMAKE_C_COMPILER}" NAME)
# Main lib # Main lib
file(GLOB PIP_FOLDERS LIST_DIRECTORIES TRUE "${CMAKE_CURRENT_SOURCE_DIR}/libs/main/*") file(GLOB PIP_FOLDERS LIST_DIRECTORIES TRUE "${CMAKE_CURRENT_SOURCE_DIR}/lib/main/*")
list(APPEND PIP_FOLDERS "${CMAKE_CURRENT_SOURCE_DIR}/libs/main") list(APPEND PIP_FOLDERS "${CMAKE_CURRENT_SOURCE_DIR}/lib/main")
set(PIP_INCLUDES "${CMAKE_CURRENT_BINARY_DIR}") set(PIP_MAIN_FOLDERS)
foreach(F ${PIP_FOLDERS}) foreach(F ${PIP_FOLDERS})
if (IS_DIRECTORY "${F}") if (IS_DIRECTORY "${F}")
list(APPEND PIP_INCLUDES "${F}") list(APPEND PIP_MAIN_FOLDERS "${F}")
#include_directories("${F}") include_directories("${F}")
endif() endif()
endforeach(F) endforeach(F)
if (DEFINED LIBPROJECT)
set(PIP_MAIN_FOLDERS "${PIP_MAIN_FOLDERS}" PARENT_SCOPE)
endif()
if (TESTS) if (TESTS)
set(PIP_ROOT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") set(PIP_ROOT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
@@ -162,7 +231,7 @@ endif()
if(PIP_FREERTOS) if(PIP_FREERTOS)
add_definitions(-DPIP_FREERTOS) add_definitions(-DPIP_FREERTOS)
set(ICU OFF) set(ICU OFF)
set(LOCAL ON) set(LIB OFF)
endif() endif()
# Check Bessel functions # Check Bessel functions
@@ -216,18 +285,6 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall")
endif() endif()
set(PIP_COVERAGE "no")
if (COVERAGE)
find_program(GCOV_EXECUTABLE gcov)
if (GCOV_EXECUTABLE)
set(PIP_COVERAGE "yes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
else()
message(STATUS "GCOV_EXECUTABLE: not found")
endif()
endif()
# Check if std::iostream operators support # Check if std::iostream operators support
set(PIP_STD_IOSTREAM "no") set(PIP_STD_IOSTREAM "no")
@@ -310,6 +367,7 @@ else()
pip_find_lib(${LIB_}) pip_find_lib(${LIB_})
endforeach() endforeach()
endif() endif()
import_version(pip PIP)
if(WIN32) if(WIN32)
add_definitions(-DPSAPI_VERSION=1) add_definitions(-DPSAPI_VERSION=1)
if(${C_COMPILER} STREQUAL "cl.exe") if(${C_COMPILER} STREQUAL "cl.exe")
@@ -326,15 +384,6 @@ set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
pip_module(main "${LIBS_MAIN}" "PIP main library" "" "") pip_module(main "${LIBS_MAIN}" "PIP main library" "" "")
generate_export_header(pip)
list(APPEND HDRS "${CMAKE_CURRENT_BINARY_DIR}/pip_export.h")
foreach(_m ${PIP_SRC_MODULES})
set_target_properties(pip PROPERTIES DEFINE_SYMBOL pip_${_m}_EXPORTS)
generate_export_header(pip BASE_NAME "pip_${_m}")
list(APPEND HDRS "${CMAKE_CURRENT_BINARY_DIR}/pip_${_m}_export.h")
endforeach()
set_target_properties(pip PROPERTIES DEFINE_SYMBOL pip_EXPORTS)
if (NOT CROSSTOOLS) if (NOT CROSSTOOLS)
if (NOT PIP_FREERTOS) if (NOT PIP_FREERTOS)
@@ -413,11 +462,7 @@ if (NOT CROSSTOOLS)
if(${CMAKE_VERSION} VERSION_LESS "3.7.0") if(${CMAKE_VERSION} VERSION_LESS "3.7.0")
target_link_libraries(_opencl_lib OpenCL) target_link_libraries(_opencl_lib OpenCL)
endif() endif()
set(_opencl_inc "${OpenCL_INCLUDE_DIRS}") pip_module(opencl "${_opencl_lib}" "PIP OpenCL support" "" " (${OpenCL_VERSION_STRING})")
if(APPLE)
set(_opencl_inc "${OpenCL_INCLUDE_DIRS}/Headers")
endif()
pip_module(opencl "${_opencl_lib}" "PIP OpenCL support" "${_opencl_inc}" " (${OpenCL_VERSION_STRING})")
endif() endif()
@@ -434,27 +479,39 @@ if (NOT CROSSTOOLS)
endif() endif()
find_package(Lua QUIET) find_package(Lua QUIET)
if (LUA_FOUND) if (LUA_FOUND)
pip_module(lua "LUA" "PIP Lua support" "${LUA_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/libs/lua/3rd" " (${LUA_VERSION_STRING})") pip_module(lua "LUA" "PIP Lua support" "${LUA_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/lib/lua/3rd" " (${LUA_VERSION_STRING})")
list(APPEND HDR_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/libs/lua/3rd/LuaBridge") list(APPEND HDR_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib/lua/3rd/LuaBridge")
endif() endif()
# Test program # Test program
if(PIP_UTILS) if(PIP_UTILS)
#add_library(pip_plugin SHARED "test_plugin.h" "test_plugin.cpp")
#target_link_libraries(pip_plugin pip)
add_executable(pip_test "main.cpp") add_executable(pip_test "main.cpp")
target_link_libraries(pip_test pip pip_cloud) target_link_libraries(pip_test pip)
if (LUA_FOUND) if (LUA_FOUND)
target_link_libraries(pip_test pip_lua ${LUA_LIBRARIES}) target_link_libraries(pip_test pip_lua ${LUA_LIBRARIES})
endif() endif()
endif() endif()
else() else()
pip_module(crypt "" "PIP crypt support" "" "")
pip_module(compress "" "PIP compression support" "" "") set(PIP_MSG_crypt "yes")
pip_module(io_utils "pip_crypt" "PIP I/O support" "" " (+crypt)") set(PIP_MSG_compress "yes")
set(PIP_MODULES pip)
add_definitions(-DPIP_CRYPT)
add_library(pip_crypt ${PIP_LIB_TYPE} ${CPP_LIB_CRYPT})
target_link_libraries(pip_crypt pip)
list(APPEND PIP_MODULES pip_crypt)
set(IO_UTILS_LIBS pip)
add_library(pip_io_utils ${PIP_LIB_TYPE} ${CPP_LIB_IO_UTILS})
list(APPEND IO_UTILS_LIBS pip_crypt)
target_link_libraries(pip_io_utils ${IO_UTILS_LIBS})
list(APPEND PIP_MODULES pip_io_utils)
add_definitions(-DPIP_COMPRESS)
add_library(pip_compress ${PIP_LIB_TYPE} ${CPP_LIB_COMPRESS})
target_link_libraries(pip_compress pip)
list(APPEND PIP_MODULES pip_compress)
endif() endif()
endif() endif()
@@ -463,10 +520,11 @@ target_compile_definitions(pip PRIVATE "PICODE_DEFINES=\"${PIP_EXPORTS_STR}\"")
# Install # Install
# Check if system or local install will be used (to system install use "-DLIB=" argument of cmake) # Check if system or local install will be used (to system install use "-DLIB=" argument of cmake)
if(NOT LOCAL) if(LIB)
if(WIN32) if(WIN32)
if(MINGW) if(MINGW)
if (NOT CROSSTOOLS) if (NOT CROSSTOOLS)
install(FILES ${HDRS} DESTINATION ${MINGW_INCLUDE}/pip)
install(FILES ${HDRS} DESTINATION ${MINGW_INCLUDE}/pip) install(FILES ${HDRS} DESTINATION ${MINGW_INCLUDE}/pip)
if(HDR_DIRS) if(HDR_DIRS)
install(DIRECTORY ${HDR_DIRS} DESTINATION ${MINGW_INCLUDE}/pip) install(DIRECTORY ${HDR_DIRS} DESTINATION ${MINGW_INCLUDE}/pip)
@@ -494,6 +552,8 @@ if(NOT LOCAL)
endif() endif()
install(TARGETS ${PIP_MODULES} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) install(TARGETS ${PIP_MODULES} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif() endif()
file(GLOB CMAKES "cmake/*.cmake" "cmake/*.in" "cmake/android_debug.keystore")
install(FILES ${CMAKES} DESTINATION ${CMAKE_ROOT}/Modules)
else() else()
if(NOT PIP_FREERTOS) if(NOT PIP_FREERTOS)
if(WIN32) if(WIN32)
@@ -508,8 +568,6 @@ else()
endif() endif()
endif() endif()
endif() endif()
file(GLOB CMAKES "cmake/*.cmake" "cmake/*.in")
install(FILES ${CMAKES} DESTINATION ${CMAKE_ROOT}/Modules)
if(NOT PIP_FREERTOS) if(NOT PIP_FREERTOS)
@@ -535,9 +593,11 @@ if(NOT PIP_FREERTOS)
endif() endif()
shstk_is_parent_exists(_pe) # Libraries messages
if (_pe) if(DEFINED LIBPROJECT)
set(PIP_MODULES ${PIP_MODULES} PARENT_SCOPE) set(PIP_MODULES ${PIP_MODULES} PARENT_SCOPE)
list(APPEND _ALL_TARGETS ${PIP_MODULES})
set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE)
endif() endif()
# #
@@ -547,12 +607,12 @@ if ((NOT PIP_FREERTOS) AND (NOT CROSSTOOLS))
include(PIPDocumentation) include(PIPDocumentation)
find_package(Doxygen) find_package(Doxygen)
if(DOXYGEN_FOUND) if(DOXYGEN_FOUND)
set(DOXY_PROJECT_NUMBER "${pip_VERSION}") set(DOXY_PROJECT_NUMBER "${PIP_VERSION}")
set(DOXY_QHP_CUST_FILTER_ATTRS "\"PIP ${pip_VERSION}\"") set(DOXY_QHP_CUST_FILTER_ATTRS "\"PIP ${PIP_VERSION}\"")
set(DOXY_QHP_SECT_FILTER_ATTRS "\"PIP ${pip_VERSION}\"") set(DOXY_QHP_SECT_FILTER_ATTRS "\"PIP ${PIP_VERSION}\"")
set(DOXY_EXAMPLE_PATH "\"${CMAKE_CURRENT_SOURCE_DIR}/doc/examples\"") set(DOXY_EXAMPLE_PATH "\"${CMAKE_CURRENT_SOURCE_DIR}/doc/examples\"")
set(DOXY_IMAGE_PATH "\"${CMAKE_CURRENT_SOURCE_DIR}/doc/images\"") set(DOXY_IMAGE_PATH "\"${CMAKE_CURRENT_SOURCE_DIR}/doc/images\"")
set(DOXY_EXCLUDE "\"${CMAKE_CURRENT_SOURCE_DIR}/libs/lua/3rd\"") set(DOXY_EXCLUDE "\"${CMAKE_CURRENT_SOURCE_DIR}/lib/lua/3rd\"")
if(DOXYGEN_DOT_EXECUTABLE) if(DOXYGEN_DOT_EXECUTABLE)
string(REPLACE "\\" "" _DOT_PATH "${DOXYGEN_DOT_PATH}") string(REPLACE "\\" "" _DOT_PATH "${DOXYGEN_DOT_PATH}")
set(DOXY_DOT_PATH "\"${_DOT_PATH}\"") set(DOXY_DOT_PATH "\"${_DOT_PATH}\"")
@@ -563,7 +623,7 @@ if ((NOT PIP_FREERTOS) AND (NOT CROSSTOOLS))
foreach(F ${PIP_MAIN_FOLDERS}) foreach(F ${PIP_MAIN_FOLDERS})
list(APPEND DOXY_INPUT "\"${F}\"") list(APPEND DOXY_INPUT "\"${F}\"")
endforeach(F) endforeach(F)
string(REPLACE ";" " " DOXY_INPUT "\"${CMAKE_CURRENT_SOURCE_DIR}/libs\"") string(REPLACE ";" " " DOXY_INPUT "\"${CMAKE_CURRENT_SOURCE_DIR}/lib\"")
string(REPLACE ";" " " DOXY_INCLUDE_PATH "${DOXY_INPUT}") string(REPLACE ";" " " DOXY_INCLUDE_PATH "${DOXY_INPUT}")
string(REPLACE ";" " " DOXY_DEFINES "${PIP_EXPORTS};DOXYGEN;PIOBJECT;PIOBJECT_SUBCLASS") string(REPLACE ";" " " DOXY_DEFINES "${PIP_EXPORTS};DOXYGEN;PIOBJECT;PIOBJECT_SUBCLASS")
add_documentation(doc doc/Doxyfile.in) add_documentation(doc doc/Doxyfile.in)
@@ -572,30 +632,13 @@ if ((NOT PIP_FREERTOS) AND (NOT CROSSTOOLS))
endif() endif()
set(_max_len 0)
foreach(_m ${PIP_SRC_MODULES})
string(LENGTH "${_m}" _clen)
if (_clen GREATER _max_len)
set(_max_len ${_clen})
endif()
endforeach()
macro(expand_to_length _out _str _len)
set(${_out} "${_str}")
while(TRUE)
string(LENGTH "${${_out}}" _clen)
if (_clen GREATER_EQUAL ${_len})
break()
endif()
string(APPEND ${_out} " ")
endwhile()
endmacro()
list(REMOVE_ITEM LIBS_STATUS ${PIP_MODULES}) list(REMOVE_ITEM LIBS_STATUS ${PIP_MODULES})
message("----------PIP----------") message("----------PIP----------")
message(" Version: ${pip_VERSION} ") message(" Version: ${PIP_VERSION} ")
message(" Linkage: ${pip_LIB_TYPE_MSG}") message(" Linkage: ${PIP_LIB_TYPE_MSG}")
message(" Type : ${pip_BUILD_TYPE}") message(" Type : ${PIP_BUILD_TYPE}")
if (NOT LOCAL) if(LIB)
message(" Install: \"${CMAKE_INSTALL_PREFIX}\"") message(" Install: \"${CMAKE_INSTALL_PREFIX}\"")
else() else()
if(NOT PIP_FREERTOS) if(NOT PIP_FREERTOS)
@@ -608,15 +651,13 @@ message(" std::iostream: ${PIP_STD_IOSTREAM}")
message(" ICU strings : ${PIP_ICU}") message(" ICU strings : ${PIP_ICU}")
message(" Timer types : ${PIP_TIMERS}") message(" Timer types : ${PIP_TIMERS}")
message(" Introspection: ${PIP_INTROSPECTION}") message(" Introspection: ${PIP_INTROSPECTION}")
message(" Coverage : ${PIP_COVERAGE}")
if(INTROSPECTION) if(INTROSPECTION)
message(STATUS " Warning: Introspection reduces the performance!") message(STATUS " Warning: Introspection reduces the performance!")
endif() endif()
message("") message("")
message(" Modules:") message(" Modules:")
foreach(_m ${PIP_SRC_MODULES}) foreach(_m ${PIP_SRC_MODULES})
expand_to_length(_m_e "${_m}" ${_max_len}) message(" ${_m}: ${PIP_MSG_${_m}}")
message(" ${_m_e}: ${PIP_MSG_${_m}}")
endforeach() endforeach()
message("") message("")
if (PIP_TESTS_LIST) if (PIP_TESTS_LIST)

1068
cmake/DeployMacros.cmake Normal file
View File

@@ -0,0 +1,1068 @@
#[[
Important! You should include this file
in your top-level CMakeLists.txt
set_version(<target> [MAJOR <value>] [MINOR <value>] [REVISION <value>] [SUFFIX <value>] [BUILD <value>] [OUTPUT <file>])
Set target version, optionally creates file
Create variable <target>_VERSION with full version name
If OUTPUT then generate header <file> with
version macros - <target>_VERSION_<NAME>
Also create macro <target>_VERSION_NAME with full string version
Attention: macro <target>_VERSION is byte-packed integer version!
set_lang(<target> <lang> [<lang> [...] ])
Set target translations, e.g. "ru" "fr"
import_version(<target> <source_target>)
Copy all version components and languages from <source_target>
import_deploy_properties(<target> <source_target>)
Copy all deploy properties from <source_target>
set_deploy_property(<target> [SHARED | STATIC] NAME <value> [NAME <value> [...] ])
Set target deploy property, where NAME one of:
* LABEL - application icon name
* FULLNAME - package name in format "*.*.*"
* COMPANY - company name
* ICON - icon file path
* INFO - additional info
Specify SHARED or STATIC if your target is library
You can setup several properties in one command
make_rc(<target> <rc_out_file>)
Generate Windows *.rc file from deploy properties
and return file path to <rc_out_file>
On other platforms this variable set to empty
You should set version and deploy properties
before call this macro, see
"set_version()" and "set_deploy_property()"
deploy_target(<target> [DEPLOY_DIR <dir>]
[DESTINATION <dir>]
[RESOURCES <dir|file> [<dir|file> ...] ]
[PLUGINS <dir|file> [<dir|file> ...] ]
[FILES <dir|file> [<dir|file> ...] ]
[LIBS <dir|file> [<dir|file> ...] ]
[OPTIONS <flag> ...]
[VERBOSE]
[DMG_NO_ZIP]
[DEB_USR_DIR] [DEB_ADD_SERVICE])
Create make target "deploy_<target>", depends on target "deploy".
On this target create release package, containing all dependencies:
* .zip on Windows
* .deb on Linux
* .dmg[.zip] on MacOS
* .apk/.aab on Android
If not defined DMG_NO_ZIP then *.dmg.zip will be created on MacOS.
You should set version and deploy properties
before call this macro, see
"set_version()" and "set_deploy_property()".
Example:
deploy_target(my_app DESTINATION packages)
DEPLOY_DIR - dir where you install
* executable on Windows, Linux
* <T>.app directory with executable on MacOS
DESTINATION - dir where macro place package
RESOURCES, PLUGINS and FILES - list of directories and files, copied to:
| | Windows | Linux | Linux (DEB_USR_DIR) | MacOS |
|-----------|---------|-------------------------|---------------------------|---------------------|
| RESOURCES | root | /opt/COMPANY/target | /usr/share/COMPANY/target | Contents/Resources |
| PLUGINS | root | /opt/COMPANY/target | /usr/lib/COMPANY/target | Contents/PlugIns |
| FILES | root | /opt/COMPANY/target | /usr/bin | Contents/MacOS |
| LIBS | root | /opt/COMPANY/target/lib | /usr/lib | Contents/Frameworks |
Relative paths are taken from DEPLOY_DIR
Also check library dependencies from PLUGINS and FILES
Important! RESOURCES, PLUGINS, FILES and LIBS lists check
at cmake-time, so if entry ends with "/" it treat
as directory, else - file
This macro using "deploy_tool" from PIP,
so make sure it can be executed from shell
OPTIONS allow you to pass custom flags to "deploy_tool"
You can see flags by launch "deploy_tool" without arguments
Using CMAKE_LDD, CMAKE_OTOOL or CMAKE_OBJDUMP variable,
depends on target platform
DEPLOY_ADD_LIBPATH variable used as additional
library search path
If DEB_ADD_SERVICE then <T>-service.deb package will be created.
This package use contents of CMAKE_CURRENT_SOURCE_DIR/debian-service directory:
* CMAKE_CURRENT_SOURCE_DIR/debian-service/DEBIAN/
* CMAKE_CURRENT_SOURCE_DIR/debian-service/*.service
.service file placed in /opt/COMPANY/target, you should copy it to system with script
You can use "postinst,postrm,preinst,prerm,config" files to configure service
]]
cmake_policy(SET CMP0011 NEW) # don`t affect includer policies
if (POLICY CMP0057)
cmake_policy(SET CMP0057 NEW) # Support if() IN_LIST
endif()
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
endif()
set(__prop_names "LABEL;FULLNAME;COMPANY;ICON;INFO")
list(APPEND __prop_names "ANDROID_TARGET_SDK;ANDROID_STORE_FILE;ANDROID_STORE_PASSWORD;ANDROID_KEY_PASSWORD;ANDROID_KEY_ALIAS;ANDROID_NEW_LOADER")
set(__version_names "MAJOR;MINOR;REVISION;BUILD;SUFFIX")
include(TargetArch)
if (NOT MY_ARCH)
target_architecture(MY_ARCH)
endif()
if (NOT _dep_exists)
set(_dep_exists 1)
add_custom_target(deploy COMMENT "Deploy")
endif()
set(_modules_dir "${CMAKE_ROOT}/Modules")
if (LIBPROJECT)
set(_modules_dir ${PIP_CMAKE_MODULE_PATH})
endif()
set(_dt_delim "::")
macro(set_version _T)
set(_VERSION_ 1) # macro version
set(_name)
set(_is_name 1)
set(_is_out 0)
set(_out)
foreach(_i ${ARGN})
if (_is_out)
set(_is_out 0)
set(_out "${_i}")
elseif ("x${_i}" STREQUAL "xOUTPUT")
set(_is_out 1)
elseif(_is_name)
set(_is_name 0)
if (_i IN_LIST __version_names)
else()
message(FATAL_ERROR "Invalid version component \"${_i}\"!")
endif()
set(_name ${_i})
else()
set(_is_name 1)
set(${_T}_VERSION_${_name} ${_i})
endif()
endforeach()
set(${_T}_VERSION_FULLSUFFIX "${${_T}_VERSION_SUFFIX}")
if (NOT ("x${${_T}_VERSION_FULLSUFFIX}" STREQUAL "x"))
if(NOT ("${${_T}_VERSION_FULLSUFFIX}" MATCHES "_.*"))
set(${_T}_VERSION_FULLSUFFIX "_${${_T}_VERSION_FULLSUFFIX}")
endif()
endif()
if ("x${${_T}_VERSION_MAJOR}" STREQUAL "x")
set(${_T}_VERSION_MAJOR "0")
endif()
if ("x${${_T}_VERSION_MINOR}" STREQUAL "x")
set(${_T}_VERSION_MINOR "0")
endif()
if ("x${${_T}_VERSION_REVISION}" STREQUAL "x")
set(${_T}_VERSION_REVISION "0")
endif()
if ("x${${_T}_VERSION_BUILD}" STREQUAL "x")
set(${_T}_VERSION_BUILD "0")
endif()
set(${_T}_VERSION "${${_T}_VERSION_MAJOR}.${${_T}_VERSION_MINOR}.${${_T}_VERSION_REVISION}${${_T}_VERSION_FULLSUFFIX}")
set(_${_T}_VERSION_WB "${${_T}_VERSION}-${${_T}_VERSION_BUILD}")
if (_out)
set(_${_T}_VERSION_CHANGED 0)
if ((NOT _${_T}_CACHED_VERSION) OR (NOT ("x${_${_T}_CACHED_VERSION}" STREQUAL "x${_${_T}_VERSION_WB}")))
set(_${_T}_CACHED_VERSION "${_${_T}_VERSION_WB}" CACHE STRING "" FORCE)
set(_${_T}_VERSION_CHANGED 1)
endif()
if ((NOT _${_T}_CACHED_VERSION_VER) OR (NOT ("x${_${_T}_CACHED_VERSION_VER}" STREQUAL "x${_VERSION_}")))
set(_${_T}_CACHED_VERSION_VER "${_VERSION_}" CACHE STRING "" FORCE)
set(_${_T}_VERSION_CHANGED 1)
endif()
if ((NOT EXISTS "${_out}") OR _${_T}_VERSION_CHANGED)
get_filename_component(_def "${_out}" NAME)
string(MAKE_C_IDENTIFIER "${_T}_${_def}" _def)
string(TOUPPER "${_def}" _def)
string(TOUPPER "${_T}" _TN)
string(TIMESTAMP _cur_date "%d.%m.%Y %H:%M")
file(WRITE "${_out}"
"// This file generated by CMake set_version() version ${_VERSION_}
#ifndef ${_def}
#define ${_def}
// Project
#define ${_TN}_VERSION_MAJOR ${${_T}_VERSION_MAJOR}
#define ${_TN}_VERSION_MINOR ${${_T}_VERSION_MINOR}
#define ${_TN}_VERSION_REVISION ${${_T}_VERSION_REVISION}
#define ${_TN}_VERSION_BUILD ${${_T}_VERSION_BUILD}
#define ${_TN}_VERSION_SUFFIX \"${${_T}_VERSION_SUFFIX}\"
#define ${_TN}_VERSION_NAME \"${${_T}_VERSION}\"
#define ${_TN}_VERSION ((${_TN}_VERSION_MAJOR << 16) | (${_TN}_VERSION_MINOR << 8) | ${_TN}_VERSION_REVISION)
// Tools
#define ${_TN}_CMAKE_VERSION \"${CMAKE_VERSION}\"
#define ${_TN}_CXX_COMPILER \"${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}\"
#define ${_TN}_BUILD_DATE \"${_cur_date}\"
#define ${_TN}_ARCH \"${MY_ARCH}\"
#endif // ${_def}
")
endif()
endif()
endmacro()
macro(set_lang _T)
set(${_T}_LANG)
foreach(_i ${ARGN})
list(APPEND ${_T}_LANG "${_i}")
endforeach()
endmacro()
macro(import_version _T _F)
set(_names "${__version_names};FULLSUFFIX")
foreach(_i ${_names})
set(${_T}_VERSION_${_i} "${${_F}_VERSION_${_i}}")
endforeach()
set(${_T}_VERSION "${${_F}_VERSION}")
set(${_T}_LANG "${${_F}_LANG}")
endmacro()
macro(import_deploy_properties _T _F)
foreach(_i ${__prop_names})
set(${_T}_${_i} "${${_F}_${_i}}")
endforeach()
endmacro()
macro(set_deploy_property _T)
set(_name)
set(_is_name 1)
foreach(_i ${ARGN})
if (("x${_i}" STREQUAL "xSHARED") OR ("x${_i}" STREQUAL "xSTATIC"))
set(${_T}_TYPE "${_i}")
elseif(_is_name)
set(_is_name 0)
if (_i IN_LIST __prop_names)
else()
message(FATAL_ERROR "Invalid property name \"${_i}\"!")
endif()
set(_name ${_i})
else()
set(_is_name 1)
set(${_T}_${_name} ${_i})
endif()
endforeach()
endmacro()
macro(make_rc _T _out)
if (WIN32)
if ("x${${_T}_VERSION_MAJOR}" STREQUAL "x")
message(FATAL_ERROR "Version for \"${_T}\" not set, use set_version()!")
endif()
string(REPLACE "\"" "\"\"" WINDOWS_RC_FULLNAME "${${_T}_FULLNAME}")
string(REPLACE "\"" "\"\"" WINDOWS_RC_VERSION "${${_T}_VERSION}" )
string(REPLACE "\"" "\"\"" WINDOWS_RC_LABEL "${${_T}_LABEL}" )
string(REPLACE "\"" "\"\"" WINDOWS_RC_COMPANY "${${_T}_COMPANY}" )
string(REPLACE "\"" "\"\"" WINDOWS_RC_INFO "${${_T}_INFO}" )
if (("x${${_T}_TYPE}" STREQUAL "x") OR ("x${${_T}_TYPE}" STREQUAL "xEXECUTABLE"))
set(WINDOWS_RC_FILETYPE "0x1L")
set(_rc_prefix "")
set(_rc_ext "exe")
elseif ("x${${_T}_TYPE}" STREQUAL "xSHARED")
set(WINDOWS_RC_FILETYPE "0x2L")
set(_rc_prefix "lib")
set(_rc_ext "dll")
elseif ("x${${_T}_TYPE}" STREQUAL "xSTATIC")
set(WINDOWS_RC_FILETYPE "0x7L")
set(_rc_prefix "lib")
set(_rc_ext "a")
endif()
set(_rc_version "${${_T}_VERSION_MAJOR},${${_T}_VERSION_MINOR},${${_T}_VERSION_REVISION},${${_T}_VERSION_BUILD}")
set(_icon)
if (NOT ("x${${_T}_ICON}" STREQUAL "x"))
get_filename_component(WINDOWS_RC_ICON "${${_T}_ICON}" REALPATH BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(_icon "1 ICON \"${WINDOWS_RC_ICON}\"")
endif()
set(_rc_file "${CMAKE_CURRENT_BINARY_DIR}/${_T}_winres.rc")
file(WRITE "${_rc_file}"
"# if defined(UNDER_CE)
# include <winbase.h>
# else
# include <winver.h>
# endif
#pragma code_page(65001)
${_icon}
VS_VERSION_INFO VERSIONINFO
FILEVERSION ${_rc_version}
PRODUCTVERSION ${_rc_version}
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L
FILEOS 0x40004L
FILETYPE ${WINDOWS_RC_FILETYPE}
FILESUBTYPE 0x0L
BEGIN
BLOCK \"StringFileInfo\"
BEGIN
BLOCK \"041904B0\"
BEGIN
VALUE \"Comments\", \"\\0\"
VALUE \"CompanyName\", \"${WINDOWS_RC_COMPANY}\\0\"
VALUE \"FileDescription\", \"${WINDOWS_RC_INFO}\\0\"
VALUE \"FileVersion\", \"${WINDOWS_RC_VERSION}\\0\"
VALUE \"InternalName\", \"${WINDOWS_RC_FULLNAME}\\0\"
VALUE \"LegalTrademarks\", \"\\0\"
VALUE \"LegalCopyright\", \"${WINDOWS_RC_COMPANY}\\0\"
VALUE \"OriginalFilename\", \"${_rc_prefix}${_T}.${_rc_ext}\\0\"
VALUE \"ProductName\", \"${WINDOWS_RC_LABEL}\\0\"
VALUE \"ProductVersion\", \"${WINDOWS_RC_VERSION}\\0\"
END
END
BLOCK \"VarFileInfo\"
BEGIN
VALUE \"Translation\", 0x0419, 0x04B0, 0x0409, 0x04B0
END
END
")
set(${_out} ${_rc_file})
else()
set(${_out})
endif()
endmacro()
# Help macros begin
macro(__add_file_or_dir _DIR_VAR _FILE_VAR _PATH _RELPATH)
set(_p)
set(_abs 0)
if (IS_ABSOLUTE "${_PATH}")
set(_abs 1)
endif()
if ("${_PATH}" MATCHES "^\$<")
set(_abs 1)
endif()
if (_abs)
set(_p "${_PATH}")
else()
set(_p "${_RELPATH}/${_PATH}")
endif()
if ("${_p}" MATCHES ".*/$")
string(LENGTH "${_p}" __sl)
math(EXPR __sl ${__sl}-1)
string(SUBSTRING "${_p}" 0 ${__sl} _p)
list(APPEND ${_DIR_VAR} "${_p}")
else()
list(APPEND ${_FILE_VAR} "${_p}")
endif()
endmacro()
set(__win_host 0)
set(__mac_host 0)
if ("x${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "xWindows")
set(__win_host 1)
endif()
if ("x${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "xDarwin")
set(__mac_host 1)
endif()
macro(__make_win_path _in_path _out_var _is_dir _out_dir)
set(_add "")
if (${_is_dir})
set(_add "/")
endif()
file(TO_NATIVE_PATH "${_in_path}" ${_out_var})
string(REPLACE "//" "/" ${_out_var} "${${_out_var}}${_add}")
if (NOT "x${_out_dir}" STREQUAL "x")
string(LENGTH "${${_out_var}}" __sl)
math(EXPR __sl ${__sl}-1)
string(SUBSTRING "${${_out_var}}" 0 ${__sl} __substr)
get_filename_component(${_out_dir} "${__substr}" NAME)
#message("dirname src=\"${${_out_var}}\", len=${__sl} \"${__substr}\" = \"${${_out_dir}}\"")
endif()
string(REPLACE "/" "\\" ${_out_var} "${${_out_var}}")
endmacro()
macro(__make_dir _cmd _dest)
if (__win_host)
__make_win_path("${_dest}" __d 1 "")
set(${_cmd} ${${_cmd}} COMMAND if not exist "\"${__d}\"" mkdir "\"${__d}\"")
else()
set(${_cmd} ${${_cmd}} COMMAND mkdir ${_VERB} -p "${_dest}")
endif()
endmacro()
macro(__make_copy _cmd _dirs _files _dest)
if (${_dirs} OR ${_files})
__make_dir(${_cmd} "${_dest}")
endif()
if (__win_host)
__make_win_path("${_dest}" _wdest 1 "")
foreach(_d ${${_dirs}})
__make_win_path("${_d}" _wsrc 1 _dirname)
__make_dir(${_cmd} "${_dest}/${_dirname}")
set(${_cmd} ${${_cmd}} COMMAND xcopy /y /r /e "${_wsrc}*" "\"${_wdest}${_dirname}\\\"" ${_WVERB})
endforeach()
foreach(_f ${${_files}})
__make_win_path("${_f}" _wsrc 0 "")
set(${_cmd} ${${_cmd}} COMMAND xcopy /y /r "\"${_wsrc}\"" "\"${_wdest}\"" ${_WVERB})
endforeach()
else()
foreach(_d ${${_dirs}})
set(${_cmd} ${${_cmd}} COMMAND cp ${_VERB} -rf "${_d}" "${_dest}/")
endforeach()
foreach(_f ${${_files}})
set(${_cmd} ${${_cmd}} COMMAND cp ${_VERB} -f "${_f}" "${_dest}/")
endforeach()
endif()
endmacro()
macro(__gather_deps _T _search_path_var _dep_libs_var _dep_libs_cs_var _added_)
get_target_property(_LL${_T} ${_T} LINK_LIBRARIES)
foreach (_L${_T} ${_LL${_T}})
if (TARGET ${_L${_T}})
get_target_property(_II${_T} ${_L${_T}} IMPORTED)
if (NOT _II${_T})
#message("depend on ${_L${_T}}")
get_target_property(_LT${_T} ${_L${_T}} TYPE)
if (("x${_LT${_T}}" STREQUAL "xSHARED_LIBRARY") OR ("x${_LT${_T}}" STREQUAL "xSTATIC_LIBRARY"))
if (NOT _L${_T} IN_LIST ${_added_})
list(APPEND ${_added_} ${_L${_T}})
__gather_deps(${_L${_T}} ${_search_path_var} ${_dep_libs_var} ${_dep_libs_cs_var} ${_added_})
if ("x${_LT${_T}}" STREQUAL "xSHARED_LIBRARY")
if (NOT DEFINED ANDROID_PLATFORM)
set(${_search_path_var} "${${_search_path_var}}${_dt_delim}$<TARGET_FILE_DIR:${_L${_T}}>")
endif()
set(${_dep_libs_cs_var} "${${_dep_libs_cs_var}}${_dt_delim}$<TARGET_FILE_DIR:${_L${_T}}>/$<TARGET_FILE_NAME:${_L${_T}}>")
set(${_dep_libs_var} "${${_dep_libs_var}}" "$<TARGET_FILE_DIR:${_L${_T}}>/$<TARGET_FILE_NAME:${_L${_T}}>")
endif()
endif()
endif()
endif()
endif()
endforeach()
endmacro()
set(__macos_privacy_text "Application request permission")
set(__macos_privacies
"<key>NFCReaderUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSAppleMusicUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSCalendarsUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSCameraUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSContactsUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSFaceIDUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSHealthShareUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSHealthUpdateUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSHomeKitUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSMicrophoneUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSMotionUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSRemindersUsageDescription</key>
<string>${__macos_privacy_text}</string>
<key>NSVideoSubscriberAccountUsageDescription</key>
<string>${__macos_privacy_text}</string>"
)
set(__gradle_lang_start
" defaultConfig {
resConfigs ")
set(__gradle_sign
" signingConfigs {
debug {
storeFile file(DEBUG_STORE_FILE)
}
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyPassword RELEASE_KEY_PASSWORD
keyAlias RELEASE_KEY_ALIAS
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
}
}")
# Help macros end
macro(deploy_target _T)
set(_DESTINATION "${CMAKE_INSTALL_PREFIX}")
set(_DEPLOY_DIR "${CMAKE_INSTALL_PREFIX}")
set(_RES_DIRS)
set(_RES_FILES)
set(_PLUG_DIRS)
set(_PLUG_FILES)
set(_FILE_DIRS)
set(_FILE_FILES)
set(_LIBS_DIRS)
set(_LIBS_FILES)
set(_VERB)
set(_WVERB 1> NUL)
set(_OPTIONS)
set(_ZIP_DMG 1)
set(_DEB_OPT 1)
set(_DEB_SERVICE 0)
set(_cur_arg)
set(__args "DESTINATION;DEPLOY_DIR;RESOURCES;PLUGINS;FILES;LIBS;OPTIONS;VERBOSE;DMG_NO_ZIP;DEB_USR_DIR;DEB_ADD_SERVICE")
foreach(_i ${ARGN})
if (_i IN_LIST __args)
set(_cur_arg "${_i}")
if ("${_cur_arg}" STREQUAL "VERBOSE")
set(_VERB -v)
set(_WVERB)
elseif("${_cur_arg}" STREQUAL "DMG_NO_ZIP")
set(_ZIP_DMG 0)
elseif("${_cur_arg}" STREQUAL "DEB_USR_DIR")
set(_DEB_OPT 0)
elseif("${_cur_arg}" STREQUAL "DEB_ADD_SERVICE")
set(_DEB_SERVICE 1)
endif()
elseif ("${_cur_arg}" STREQUAL "DESTINATION")
set(_cur_arg)
set(_DESTINATION "${_i}/")
elseif ("${_cur_arg}" STREQUAL "DEPLOY_DIR")
set(_cur_arg)
set(_DEPLOY_DIR "${_i}/")
elseif ("${_cur_arg}" STREQUAL "RESOURCES")
__add_file_or_dir(_RES_DIRS _RES_FILES "${_i}" "${_DEPLOY_DIR}")
elseif ("${_cur_arg}" STREQUAL "PLUGINS")
__add_file_or_dir(_PLUG_DIRS _PLUG_FILES "${_i}" "${_DEPLOY_DIR}")
elseif ("${_cur_arg}" STREQUAL "FILES")
__add_file_or_dir(_FILE_DIRS _FILE_FILES "${_i}" "${_DEPLOY_DIR}")
elseif ("${_cur_arg}" STREQUAL "LIBS")
__add_file_or_dir(_LIBS_DIRS _LIBS_FILES "${_i}" "${_DEPLOY_DIR}")
elseif ("${_cur_arg}" STREQUAL "OPTIONS")
list(APPEND _OPTIONS "${_i}")
endif()
#message("-i = ${_i}")
endforeach()
get_filename_component(_ICON_NAME "${${_T}_ICON}" NAME)
get_filename_component(_ICON_FN "${${_T}_ICON}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(_TV "${_T}_${${_T}_VERSION}")
set(_DEP_LIBPATH)
set(_DEP_LIBS_CS)
set(_DEP_LIBS)
set(_add_search_path)
set(_added_)
set(_ADD_DEPS ${_PLUG_DIRS} ${_PLUG_FILES} ${_FILE_DIRS} ${_FILE_FILES} ${_LIBS_DIRS} ${_LIBS_FILES})
__gather_deps(${_T} _add_search_path _DEP_LIBS _DEP_LIBS_CS _added_)
foreach (_L ${DEPLOY_ADD_LIBPATH})
set(_add_search_path "${_add_search_path}${_dt_delim}${_L}")
endforeach()
#message("app depend ${_T} libpath ${_add_search_path}")
set(_CMD_)
set(_deployed)
if ("x${CMAKE_SYSTEM_NAME}" STREQUAL "xLinux")
set(_os_id "")
set(_os_ver "")
set(_paths "/usr/lib" "/etc")
if (CMAKE_CROSSCOMPILING)
set(_paths "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/../etc")
endif()
find_file(_release_file NAMES os-release lsb-release PATHS ${_paths} NO_DEFAULT_PATH)
if (NOT "x${_release_file}" STREQUAL "x")
file(STRINGS "${_release_file}" _lines)
foreach(_l ${_lines})
if ("${_l}" MATCHES "VERSION_ID=.*")
string(SUBSTRING "${_l}" 11 -1 _os_ver)
string(REPLACE "\"" "" _os_ver "${_os_ver}")
#message("VERSION_ID ${_os_ver}")
elseif ("${_l}" MATCHES "ID=.*")
string(SUBSTRING "${_l}" 3 -1 _os_id)
string(REPLACE "\"" "" _os_id "${_os_id}")
#message("ID ${_os_id}")
endif()
endforeach()
endif()
set(_build "${${_T}_VERSION_BUILD}")
if (NOT "x${_build}" STREQUAL "x")
set(_build "-${_build}")
endif()
string(TOLOWER "${_os_id}${_os_ver}" _TARGET_OS)
if ("x${_TARGET_OS}" STREQUAL "x")
set(_TARGET_OS "linux")
endif()
string(REPLACE "_" "-" _DEBNAME "${_T}")
string(REPLACE "_" "-" _DEBVERSION "${${_T}_VERSION}${_build}+${_TARGET_OS}")
string(TOLOWER "${_DEBNAME}" _DEBNAME)
set(_DEB_ARCH)
if("_${MY_ARCH}" STREQUAL "_arm64")
set(_DEB_ARCH "arm64")
elseif("_${MY_ARCH}" STREQUAL "_armv7")
set(_DEB_ARCH "armhf")
elseif("_${MY_ARCH}" STREQUAL "_i386")
set(_DEB_ARCH "i386")
elseif("_${MY_ARCH}" STREQUAL "_x86_64")
set(_DEB_ARCH "amd64")
elseif("_${MY_ARCH}" STREQUAL "_ppc")
set(_DEB_ARCH "PowerPC")
elseif("_${MY_ARCH}" STREQUAL "_ppc64")
set(_DEB_ARCH "PPC64")
elseif("_${MY_ARCH}" STREQUAL "_ia64")
set(_DEB_ARCH "ia64")
endif()
set(_DEB "${_TV}_deb_${_DEB_ARCH}")
set(_AGD "${_DEPLOY_DIR}/${_DEB}")
set(_C_echof ">" "${_AGD}/DEBIAN/control")
set(_C_echo ">>" "${_AGD}/DEBIAN/control")
set(_D_echof ">" "${_AGD}/usr/share/applications/${_DEBNAME}.desktop")
set(_D_echo ">>" "${_AGD}/usr/share/applications/${_DEBNAME}.desktop")
set(_bin_path "${_AGD}/usr/bin")
set(_lib_path "${_AGD}/usr/lib")
set(_pli_path "${_AGD}/usr/lib/${${_T}_COMPANY}/${_T}")
set(_res_path "${_AGD}/usr/share/${${_T}_COMPANY}/${_T}")
set(_ico_path "${_AGD}/usr/share/pixmaps")
set(_app_bin_path "/usr/bin")
set(_app_ico_path "/usr/share/pixmaps")
if(_DEB_OPT)
set(_bin_path "${_AGD}/opt/${${_T}_COMPANY}/${_T}")
set(_lib_path "${_AGD}/opt/${${_T}_COMPANY}/${_T}/lib")
set(_pli_path "${_AGD}/opt/${${_T}_COMPANY}/${_T}")
set(_res_path "${_AGD}/opt/${${_T}_COMPANY}/${_T}")
set(_ico_path "${_AGD}/opt/${${_T}_COMPANY}/${_T}/pixmaps")
set(_app_bin_path "/opt/${${_T}_COMPANY}/${_T}")
set(_app_ico_path "/opt/${${_T}_COMPANY}/${_T}/pixmaps")
endif()
set(_CMD_ ${_CMD_} COMMAND mkdir ${_VERB} -p "${_bin_path}")
set(_CMD_ ${_CMD_} COMMAND mkdir ${_VERB} -p "${_lib_path}")
set(_CMD_ ${_CMD_} COMMAND mkdir ${_VERB} -p "${_pli_path}")
set(_CMD_ ${_CMD_} COMMAND mkdir ${_VERB} -p "${_res_path}")
set(_CMD_ ${_CMD_} COMMAND mkdir ${_VERB} -p "${_ico_path}")
set(_CMD_ ${_CMD_} COMMAND mkdir ${_VERB} -p "${_AGD}/usr/share/applications")
__make_copy(_CMD_ _FILE_DIRS _FILE_FILES ${_bin_path})
__make_copy(_CMD_ _PLUG_DIRS _PLUG_FILES ${_pli_path})
__make_copy(_CMD_ _RES_DIRS _RES_FILES ${_res_path})
__make_copy(_CMD_ _LIBS_DIRS _LIBS_FILES ${_lib_path})
set(_CMD_ ${_CMD_} COMMAND cp ${_VERB} -f "${_DEPLOY_DIR}/${_T}" "${_bin_path}/")
if (_DEP_LIBS)
set(_CMD_ ${_CMD_} COMMAND cp ${_VERB} -f "${_DEP_LIBS}" "${_lib_path}/")
endif()
if (_ICON_NAME)
set(_CMD_ ${_CMD_} COMMAND cp ${_VERB} -f "${_ICON_FN}" "${_ico_path}/")
endif()
if(_DEB_OPT)
set(_CMD_ ${_CMD_} COMMAND mkdir ${_VERB} -p "${_AGD}/usr/bin")
set(_CMD_ ${_CMD_} COMMAND ln -srf ${_VERB} "${_bin_path}/${_T}" "${_AGD}/usr/bin/${_T}")
endif()
file(GLOB _files "${CMAKE_CURRENT_SOURCE_DIR}/debian/DEBIAN/*")
foreach (_f ${_files})
set(_CMD_ ${_CMD_} COMMAND cp ${_VERB} -f "${_f}" "${_AGD}/DEBIAN/")
endforeach()
file(GLOB _files "${_AGD}/DEBIAN/p*inst" "${_AGD}/DEBIAN/p*rm" "${_AGD}/DEBIAN/config")
foreach (_f ${_files})
set(_CMD_ ${_CMD_} COMMAND chmod 0755 ${_VERB} "${_f}")
endforeach()
if (NOT CMAKE_LDD)
find_program(CMAKE_LDD ldd)
endif()
set(_dt_opts -l "${CMAKE_LDD}")
if (CMAKE_CROSSCOMPILING)
set(_dt_searchdirs "${CMAKE_PREFIX_PATH}/lib")
if (NOT "x${CMAKE_LIBRARY_ARCHITECTURE}" STREQUAL "x")
set(_dt_searchdirs "${_dt_searchdirs}${_dt_delim}${CMAKE_PREFIX_PATH}/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
set(_dt_searchdirs "${_dt_searchdirs}${_dt_delim}${CMAKE_PREFIX_PATH}/../lib/${CMAKE_LIBRARY_ARCHITECTURE}")
endif()
set(_dt_opts -L "${CMAKE_READELF}" --dpkg-workdir "${CMAKE_DPKG_WORKDIR}" -s "${_dt_searchdirs}")
endif()
set(_deb_name "${_TV}_${_TARGET_OS}_${_DEB_ARCH}.deb")
#message("VER = \"${_DEBVERSION}\"")
#message("DEB = \"${_deb_name}\"")
list(APPEND _CMD_ COMMAND echo "Package: ${_DEBNAME}" ${_C_echof})
list(APPEND _CMD_ COMMAND echo "Version: ${_DEBVERSION}" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Architecture: ${_DEB_ARCH}" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Maintainer: ${${_T}_COMPANY} <>" ${_C_echo})
list(APPEND _CMD_ COMMAND ${PIP_DEPLOY_TOOL} ${_OPTIONS} --prefix "Depends: " --dependencies ${_dt_opts} -a "${_DEP_LIBS_CS}" -o "${_lib_path}" ${_DEPLOY_DIR}/${_T} ${_ADD_DEPS} ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Conflicts:" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Replaces:" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Section: misc" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Priority: optional" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Description: ${${_T}_INFO}" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "[Desktop Entry]" ${_D_echof})
list(APPEND _CMD_ COMMAND echo "Encoding=UTF-8" ${_D_echo})
list(APPEND _CMD_ COMMAND echo "Type=Application" ${_D_echo})
list(APPEND _CMD_ COMMAND echo "Name=${${_T}_LABEL}" ${_D_echo})
list(APPEND _CMD_ COMMAND echo "GenericName=${${_T}_LABEL}" ${_D_echo})
list(APPEND _CMD_ COMMAND echo "Comment=${${_T}_INFO}" ${_D_echo})
list(APPEND _CMD_ COMMAND echo "Exec=${_app_bin_path}/${_T}" ${_D_echo})
list(APPEND _CMD_ COMMAND echo "Icon=${_app_ico_path}/${_ICON_NAME}" ${_D_echo})
list(APPEND _CMD_ COMMAND echo "Terminal=false" ${_D_echo})
list(APPEND _CMD_ COMMAND echo "StartupNotify=true" ${_D_echo})
list(APPEND _CMD_ COMMAND echo "Categories=Utility;" ${_D_echo})
add_custom_target(deploy_${_T}
# gather deb dir
COMMAND rm -rf ${_VERB} "${_AGD}"
COMMAND mkdir ${_VERB} -p "${_AGD}/DEBIAN"
${_CMD_}
# generate deb
COMMAND cd ${_AGD} "&&" md5deep -rl opt usr ">" DEBIAN/md5sums
COMMAND mkdir ${_VERB} -p ${_DESTINATION}
COMMAND dpkg-deb -Z gzip -b ${_AGD} ${_DESTINATION}/${_deb_name}
VERBATIM
COMMENT "Generating ${_deb_name}"
)
set(_deployed "deploy_${_T}")
if (_DEB_SERVICE)
set(_CMD_)
set(_DEB "${_TV}-service_deb_${_DEB_ARCH}")
set(_AGD "${_DEPLOY_DIR}/${_DEB}")
set(_C_echof ">" "${_AGD}/DEBIAN/control")
set(_C_echo ">>" "${_AGD}/DEBIAN/control")
set(_opt_path "${_AGD}/opt/${${_T}_COMPANY}/${_T}")
set(_CMD_ ${_CMD_} COMMAND mkdir ${_VERB} -p "${_opt_path}")
file(GLOB _files "${CMAKE_CURRENT_SOURCE_DIR}/debian-service/*.service")
foreach (_f ${_files})
set(_CMD_ ${_CMD_} COMMAND cp ${_VERB} -f "${_f}" "${_opt_path}/")
endforeach()
set(__deb_dir "${CMAKE_CURRENT_SOURCE_DIR}/debian-service/DEBIAN")
file(GLOB _files "${__deb_dir}/*")
foreach (_f ${_files})
set(_CMD_ ${_CMD_} COMMAND cp ${_VERB} -f "${_f}" "${_AGD}/DEBIAN/")
endforeach()
file(GLOB _files RELATIVE "${__deb_dir}" "${__deb_dir}/p*inst" "${__deb_dir}/p*rm" "${__deb_dir}/config")
foreach (_f ${_files})
set(_CMD_ ${_CMD_} COMMAND chmod 0755 ${_VERB} "${_AGD}/DEBIAN/${_f}")
endforeach()
set(_deb_name "${_TV}-service_${_TARGET_OS}_${_DEB_ARCH}.deb")
#message("VER = \"${_DEBVERSION}\"")
#message("DEB = \"${_deb_name}\"")
list(APPEND _CMD_ COMMAND echo "Package: ${_DEBNAME}-service" ${_C_echof})
list(APPEND _CMD_ COMMAND echo "Version: ${_DEBVERSION}" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Architecture: ${_DEB_ARCH}" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Maintainer: ${${_T}_COMPANY} <>" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Depends: ${_DEBNAME} (>= ${_DEBVERSION})" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Conflicts:" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Replaces:" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Section: misc" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Priority: optional" ${_C_echo})
list(APPEND _CMD_ COMMAND echo "Description: ${${_T}_LABEL} service" ${_C_echo})
add_custom_target(deploy_${_T}-service
# gather deb dir
COMMAND rm -rf ${_VERB} "${_AGD}"
COMMAND mkdir ${_VERB} -p "${_AGD}/DEBIAN"
${_CMD_}
# generate deb
COMMAND mkdir ${_VERB} -p ${_DESTINATION}
COMMAND dpkg-deb -Z gzip -b ${_AGD} ${_DESTINATION}/${_deb_name}
VERBATIM
COMMENT "Generating ${_deb_name}"
)
list(APPEND _deployed "deploy_${_T}-service")
endif()
elseif(WIN32)
if (NOT CMAKE_OBJDUMP)
find_program(CMAKE_OBJDUMP objdump)
endif()
set(_AGD "${_DEPLOY_DIR}/${_TV}_win_${MY_ARCH}/")
if (__win_host)
string(REPLACE "/" "\\" CMAKE_OBJDUMP "${CMAKE_OBJDUMP}")
endif()
set(_var_exe "${_DEPLOY_DIR}/${_T}.exe")
set(_var_empty)
__make_dir(_CMD_ "${_AGD}")
__make_dir(_CMD_ "${_DESTINATION}")
__make_copy(_CMD_ _var_empty _var_exe "${_AGD}")
__make_copy(_CMD_ _RES_DIRS _RES_FILES "${_AGD}")
__make_copy(_CMD_ _PLUG_DIRS _PLUG_FILES "${_AGD}")
__make_copy(_CMD_ _FILE_DIRS _FILE_FILES "${_AGD}")
__make_copy(_CMD_ _LIBS_DIRS _LIBS_FILES "${_AGD}")
set(_zip_name "${_TV}_windows_${MY_ARCH}.zip")
add_custom_target(deploy_${_T}
# gather dir
${_CMD_}
COMMAND ${PIP_DEPLOY_TOOL} ${_VERB} ${_OPTIONS} -W "\"${CMAKE_OBJDUMP}\"" -P windows,minimal -S windows -q "\"${Qt5_ROOT}\"" -s "\"${CMAKE_PREFIX_PATH}/bin${_dt_delim}${MINGW_BIN}${_add_search_path}\"" -o ${_AGD} -p ${_AGD} "\"${_AGD}${_T}.exe\"" ${_ADD_DEPS}
# zip
COMMAND cd "\"${_DEPLOY_DIR}\"" "&&" zip -q -r "\"${_DESTINATION}/${_zip_name}\"" "\"${_TV}_win_${MY_ARCH}\""
COMMENT "Generating ${_zip_name}"
)
set(_deployed "deploy_${_T}")
elseif (APPLE)
set(MACOSX_BUNDLE_GUI_IDENTIFIER "${${_T}_FULLNAME}")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${${_T}_VERSION}")
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${${_T}_VERSION}")
set(MACOSX_BUNDLE_ICON_FILE "${_ICON_NAME}")
set(MACOSX_BUNDLE_BUNDLE_NAME "${${_T}_LABEL}")
set(MACOSX_BUNDLE_COPYRIGHT "${${_T}_COMPANY}")
set(MACOSX_BUNDLE_INFO_STRING "${${_T}_INFO}")
set(MACOSX_BUNDLE_BUNDLE_VERSION "6.0")
set(MACOSX_BUNDLE_SIGNATURE "????")
set(MACOSX_BUNDLE_PRIVACIES "${__macos_privacies}")
set_target_properties(${_T} PROPERTIES MACOSX_BUNDLE TRUE)
set_target_properties(${_T} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${_modules_dir}/PIMacOSBundle.plist.in")
set(_AGD "${_DEPLOY_DIR}/${_T}.app")
set(_DMG "${CMAKE_CURRENT_BINARY_DIR}/dmg")
__make_copy(_CMD_ _RES_DIRS _RES_FILES "${_AGD}/Contents/Resources")
__make_copy(_CMD_ _PLUG_DIRS _PLUG_FILES "${_AGD}/Contents/PlugIns")
__make_copy(_CMD_ _FILE_DIRS _FILE_FILES "${_AGD}/Contents/MacOS")
__make_copy(_CMD_ _LIBS_DIRS _LIBS_FILES "${_AGD}/Contents/Frameworks")
if (_ICON_NAME)
set(_CMD_ ${_CMD_} COMMAND cp ${_VERB} -f ${_ICON_FN} ${_AGD}/Contents/Resources)
endif()
if (NOT CMAKE_OTOOL)
set(CMAKE_OTOOL "otool")
endif()
if (NOT CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH "/usr/local")
endif()
set(_dmg_name "${_TV}_macosx_x64.dmg")
set(_cmd_gen_dmg COMMAND genisoimage -quiet -V "${MACOSX_BUNDLE_BUNDLE_NAME}" -D -R -apple -no-pad -o ${_DESTINATION}/${_dmg_name} ${_DMG})
if (__mac_host)
set(_cmd_gen_dmg COMMAND hdiutil create ${_DESTINATION}/${_dmg_name} -ov -volname "${MACOSX_BUNDLE_BUNDLE_NAME}" -fs HFS+ -srcfolder ${_DMG})
endif()
if (_ZIP_DMG)
set(_cmd_gen_dmg ${_cmd_gen_dmg} COMMAND zip -q -r "\"${_DESTINATION}/${_dmg_name}.zip\"" "\"${_DESTINATION}/${_dmg_name}\"")
set(_cmd_gen_dmg ${_cmd_gen_dmg} COMMAND rm "\"${_DESTINATION}/${_dmg_name}\"")
endif()
set(_comment "Generating ${_dmg_name}")
if (_ZIP_DMG)
set(_comment "${_comment}.zip")
endif()
add_custom_target(deploy_${_T}
# gather .app dir
COMMAND mkdir ${_VERB} -p ${_AGD}/Contents/Resources
COMMAND mkdir ${_VERB} -p ${_AGD}/Contents/Frameworks
COMMAND mkdir ${_VERB} -p ${_DESTINATION}
${_CMD_}
COMMAND ${PIP_DEPLOY_TOOL} ${_VERB} ${_OPTIONS} -M "${CMAKE_OTOOL}" -P cocoa,minimal -S mac -q ${Qt5_ROOT} -s "\"${CMAKE_PREFIX_PATH}/lib${_add_search_path}\"" -o ${_AGD}/Contents/Frameworks -p ${_AGD}/Contents/PlugIns ${_AGD}/Contents/MacOS/${_T} ${_ADD_DEPS}
# prepare dmg dir
COMMAND rm -rf ${_DMG}
COMMAND mkdir ${_VERB} -p ${_DMG}
COMMAND cp -r ${_AGD} ${_DMG}
COMMAND ln ${_VERB} -s /Applications ${_DMG}
# generate dmg
${_cmd_gen_dmg}
COMMENT "${_comment}"
)
set(_deployed "deploy_${_T}")
elseif (DEFINED ANDROID_PLATFORM)
set(_res_files)
set(_res_files "${_res_files}\n <qresource prefix=\"/\">")
foreach (_f ${_RES_FILES})
set(_res_files "${_res_files}\n <file>${_f}</file>")
endforeach()
set(_res_files "${_res_files}\n </qresource>")
foreach (_d ${_RES_DIRS})
file(GLOB_RECURSE _df "${_d}/*")
#message("FILES ${_d} = ${_df}")
get_filename_component(_dn "${_d}" NAME)
set(_res_files "${_res_files}\n <qresource prefix=\"${_dn}\">")
foreach (_f ${_df})
get_filename_component(_fn "${_f}" NAME)
set(_res_files "${_res_files}\n <file alias=\"${_fn}\">${_f}</file>")
endforeach()
set(_res_files "${_res_files}\n </qresource>")
endforeach()
set(_res_qrc "${CMAKE_CURRENT_BINARY_DIR}/android_res.qrc")
file(WRITE "${_res_qrc}" "<RCC>${_res_files}\n</RCC>")
set(_AT ${_T}_lib)
set(_ATA ${_AT}_${ANDROID_ABI})
get_target_property(_sources ${_T} SOURCES)
get_target_property(_libs ${_T} LINK_LIBRARIES)
get_target_property(_incs ${_T} INCLUDE_DIRECTORIES)
get_target_property(_defs ${_T} COMPILE_DEFINITIONS)
qt5_add_resources(_res_out "${_res_qrc}")
add_library(${_ATA} SHARED ${_sources} ${_res_out})
target_link_libraries(${_ATA} ${_libs})
target_include_directories(${_ATA} PRIVATE ${_incs})
target_compile_definitions(${_ATA} PRIVATE ${_defs})
set_target_properties(${_T} PROPERTIES EXCLUDE_FROM_ALL 1)
#message("create new target ${_ATA} ${_sources} ${_libs}")
set(_AGD "${_DEPLOY_DIR}/${_T}.android")
__make_dir(_CMD_ "${_AGD}")
set(_file)
set(_dir "${CMAKE_BINARY_DIR}/android-build/libs" "${CMAKE_CURRENT_SOURCE_DIR}/android/res" "${CMAKE_CURRENT_SOURCE_DIR}/android/src")
__make_copy(_CMD_ _dir _file "${_AGD}")
set(_dir)
set(_file "${Qt5_ROOT}/src/android/templates/res/values/libs.xml")
__make_copy(_CMD_ _dir _file "${_AGD}/res/values")
set(_dir "${Qt5_ROOT}/src/3rdparty/gradle/gradle")
set(_file "${Qt5_ROOT}/src/3rdparty/gradle/gradlew"
"${Qt5_ROOT}/src/3rdparty/gradle/gradlew.bat")
__make_copy(_CMD_ _dir _file "${_AGD}")
#message("bindir = ${CMAKE_CURRENT_SOURCE_DIR}")
set(SDK_ROOT "$ENV{ANDROID_SDK_ROOT}")
if("x${SDK_ROOT}" STREQUAL "x")
set(SDK_ROOT "$ENV{ANDROID_HOME}")
endif()
set(__archs "armeabi-v7a" "arm64-v8a" "x86" "x86_64")
set(QT_ANDROID_ARCHITECTURES)
find_library(_lib_ c++_shared)
foreach (_a ${__archs})
set(_aname "${_a}")
if ("${_a}" STREQUAL "armeabi-v7a")
set(_aname "arm")
elseif ("${_a}" STREQUAL "arm64-v8a")
set(_aname "arm64")
endif()
set(_exist 0)
if ("${_a}" STREQUAL "${ANDROID_ABI}")
set(_exist 1)
elseif (EXISTS "${CMAKE_BINARY_DIR}/android-build/libs/${_a}")
set(_exist 1)
endif()
if (_exist)
string(REPLACE "${ANDROID_ABI}" "${_a}" _a_prefix "${CMAKE_PREFIX_PATH}")
string(REPLACE "arch-${ANDROID_ARCH_NAME}" "arch-${_aname}" _a_prefix "${_a_prefix}")
list(APPEND QT_ANDROID_ARCHITECTURES " \"${_a}\" : \"${ANDROID_SYSROOT_${_a}}\"")
string(REPLACE "${ANDROID_SYSROOT_${ANDROID_ABI}}" "${ANDROID_SYSROOT_${_a}}" _lib_${_a} "${_lib_}")
#message("search = ${_a_prefix}/lib")
__make_copy(_CMD_ _empty _lib_${_a} "${_AGD}/libs/${_a}")
set(_CMD_ ${_CMD_} COMMAND ${PIP_DEPLOY_TOOL} ${_VERB} ${_OPTIONS} -W "\"${CMAKE_OBJDUMP}\"" -s "${_a_prefix}/lib${_dt_delim}${Qt5_ROOT}/lib${_add_search_path}" -o "\"${_AGD}/libs/${_a}\"" --ignore "\"c${_dt_delim}m${_dt_delim}z${_dt_delim}dl${_dt_delim}log\"" "\"${_AGD}/libs/${_a}/lib${_AT}_${_a}.so\"" ${_ADD_DEPS})
#message("c++_${_a} -> ${_lib_${_a}}")
endif()
endforeach()
string(REPLACE ";" ",\n" QT_ANDROID_ARCHITECTURES "${QT_ANDROID_ARCHITECTURES}")
set(QT_ANDROID_APPLICATION_BINARY ${_AT})
set(ANDROID_LABEL "${${_T}_LABEL}")
set(ANDROID_ICON "${${_T}_ICON}")
set(ANDROID_VERSION "${${_T}_VERSION}")
set(ANDROID_BUILD "${${_T}_VERSION_BUILD}")
set(ANDROID_PACKAGE "${${_T}_FULLNAME}")
set(ANDROID_TARGET_SDK "${${_T}_ANDROID_TARGET_SDK}")
set(ANDROID_STORE_FILE "${${_T}_ANDROID_STORE_FILE}")
set(ANDROID_STORE_PASSWORD "${${_T}_ANDROID_STORE_PASSWORD}")
set(ANDROID_KEY_PASSWORD "${${_T}_ANDROID_KEY_PASSWORD}")
set(ANDROID_KEY_ALIAS "${${_T}_ANDROID_KEY_ALIAS}")
if (NOT IS_ABSOLUTE "${ANDROID_STORE_FILE}")
set(ANDROID_STORE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/android/${ANDROID_STORE_FILE}")
endif()
if (${_T}_ANDROID_NEW_LOADER)
set(ANDROID_NEW_LOADER "true")
else()
set(ANDROID_NEW_LOADER "false")
endif()
set(__ANDROID_DEBUG_KEYSTORE__ "${_modules_dir}/android_debug.keystore")
set(QT_DIR ${Qt5_ROOT})
set(_out_json "${CMAKE_CURRENT_BINARY_DIR}/${_T}_android_deployment_settings.json")
configure_file("${CMAKE_BINARY_DIR}/android_deployment_settings.json.in" "${_out_json}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/android/AndroidManifest.xml.in" "${_AGD}/AndroidManifest.xml")
configure_file("${_modules_dir}/gradle.properties.in" "${_AGD}/gradle.properties")
set(_depstr)
foreach (_d ${ANDROID_GRADLE_DEPENDENCIES})
set(_depstr "${_depstr}\n ${_d}")
endforeach()
set(__gradle_lang)
foreach (_l ${${_T}_LANG})
if (NOT "x${__gradle_lang}" STREQUAL "x")
set(__gradle_lang "${__gradle_lang}, ")
endif()
set(__gradle_lang "${__gradle_lang}\"${_l}\"")
endforeach()
if ("x${__gradle_lang}" STREQUAL "x")
set(__gradle_lang "\"en\"")
endif()
file(READ "${Qt5_ROOT}/src/android/templates/build.gradle" _file)
string(REPLACE "\ndependencies {" "\ndependencies {${_depstr}" _file "${_file}")
string(REPLACE "\nandroid {" "\nandroid {\n${__gradle_sign}\n${__gradle_lang_start}${__gradle_lang}\n\t}\n" _file "${_file}")
string(REPLACE "['resources']" "['res']" _file "${_file}")
file(WRITE "${_AGD}/build.gradle" "${_file}")
set(_gradle_home)
if (NOT __win_host)
set(_gradle_home "-g" "${CMAKE_BINARY_DIR}")
endif()
set(_CMD_ ${_CMD_} COMMAND "${Qt5_BIN}/androiddeployqt" --aux-mode --android-platform ${ANDROID_PLATFORM} --output "\"${_AGD}\"" --input "\"${_out_json}\"")
set(_CMD_ ${_CMD_} COMMAND "${_AGD}/gradlew" ${_gradle_home} --no-daemon -p "\"${_AGD}\"" assembleDebug)
set(_CMD_ ${_CMD_} COMMAND "${_AGD}/gradlew" ${_gradle_home} --no-daemon -p "\"${_AGD}\"" bundleRelease)
set(_base_name "${_TV}_android_all")
set(_CMD_ ${_CMD_} COMMAND "${CMAKE_COMMAND}" -E copy "${_AGD}/build/outputs/apk/debug/${_T}.android-debug.apk" "${_DESTINATION}/${_base_name}.apk")
if (ANDROID_STORE_FILE)
set(_CMD_ ${_CMD_} COMMAND "${CMAKE_COMMAND}" -E copy "${_AGD}/build/outputs/bundle/release/${_T}.android-release.aab" "${_DESTINATION}/${_base_name}.aab")
endif()
add_custom_target(deploy_${_T}
# gather .app dir
${_CMD_}
COMMENT "Generating ${_base_name}.apk/aab"
)
set(_deployed "deploy_${_T}")
endif()
foreach (_d ${_deployed})
add_dependencies(deploy ${_d})
endforeach()
endmacro()

31
cmake/DownloadGTest.cmake Normal file
View File

@@ -0,0 +1,31 @@
# Download and unpack googletest at configure time
configure_file(GTestCMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()

24
cmake/FindMinGW.cmake Normal file
View File

@@ -0,0 +1,24 @@
if(${MINGW})
if(NOT DEFINED MINGW_DIR)
get_filename_component(MINGW_BIN ${CMAKE_CXX_COMPILER} PATH)
get_filename_component(MINGW_DIR ${MINGW_BIN} PATH)
find_path(MINGW_INCLUDE
windows.h
PATHS
ENV INCLUDE
${MINGW_DIR}
${MINGW_DIR}/i686-w64-mingw32
${MINGW_DIR}/x86_64-w64-mingw32
PATH_SUFFIXES
include)
#message(STATUS "Find MinGW = ${MINGW_INCLUDE}")
find_library(MINGW_LIB m HINTS ${MINGW_BIN}/../lib ${MINGW_INCLUDE}/../lib)
get_filename_component(MINGW_LIB ${MINGW_LIB} PATH)
if (NOT _MGW_MSG)
set(_MGW_MSG 1 CACHE BOOL "msg_mingw" FORCE)
message(STATUS "Found MinGW binary path = ${MINGW_BIN}")
message(STATUS "Found MinGW include path = ${MINGW_INCLUDE}")
message(STATUS "Found MinGW library path = ${MINGW_LIB}")
endif()
endif()
endif(${MINGW})

View File

@@ -1,6 +1,6 @@
#[[ #[[
Create imported targets: Also create imported targets:
* PIP - main library * PIP - main library
* PIP::USB * PIP::USB
* PIP::Console * PIP::Console
@@ -18,64 +18,85 @@ main library
]] ]]
cmake_policy(SET CMP0011 NEW) # don`t affect includer policies cmake_policy(SET CMP0011 NEW) # don`t affect includer policies
include(SHSTKMacros) if(WIN32)
find_package(MinGW REQUIRED)
shstk_set_find_dirs(pip)
if(PIP_DIR)
list(APPEND pip_LIBDIR "${PIP_DIR}/lib")
list(APPEND pip_INCDIR "${PIP_DIR}/include/pip")
list(APPEND pip_BINDIR "${PIP_DIR}/bin")
endif() endif()
set(__libs "usb;crypt;console;fftw;compress;io_utils;opencl;cloud;lua") set(_PIP_INCDIR "${PIP_DIR}/include/pip")
set(_PIP_LIBDIR "${PIP_DIR}/lib")
set(_PIP_BINDIR)
set(_PIP_FP_DP)
if (BUILDING_pip) if(MINGW_INCLUDE)
#set(_libs "pip;pip_usb;pip_console;pip_crypt;pip_fftw;pip_compress;pip_opencl;pip_io_utils;pip_cloud;pip_lua") list(APPEND _PIP_INCDIR "${MINGW_INCLUDE}/pip")
#set(_bins "pip_cmg;pip_rc;deploy_tool") list(APPEND _PIP_LIBDIR "${MINGW_LIB}")
#get_target_property(_path pip BINARY_DIR) endif()
#get_target_property(_path pip LIBRARY_OUTPUT_NAME) if(CMAKE_CROSSCOMPILING)
#message("${_path}") list(APPEND _PIP_INCDIR "${CMAKE_PREFIX_PATH}/include/pip")
#set(PIP_LIBRARY "$<TARGET_FILE_DIR:pip>/$<TARGET_FILE_NAME:pip>" CACHE STRING "") list(APPEND _PIP_LIBDIR "${CMAKE_PREFIX_PATH}/lib")
set(PIP_LIBRARY pip CACHE STRING "")
set(PIP_FOUND ON CACHE BOOL "")
else() else()
find_library(PIP_LIBRARY pip HINTS ${pip_LIBDIR}) if(NOT WIN32)
foreach (_l ${__libs}) list(APPEND _PIP_INCDIR "/usr/include/pip" "/usr/local/include/pip")
find_library(PIP_LIBRARY_${_l} pip_${_l} HINTS ${pip_LIBDIR}) list(APPEND _PIP_LIBDIR "/usr/lib" "/usr/local/lib")
endforeach()
endif()
if (BUILDING_pip AND (NOT CMAKE_CROSSCOMPILING))
set(PIP_CMG "$<TARGET_FILE_DIR:pip_cmg>/$<TARGET_FILE_NAME:pip_cmg>" CACHE STRING "")
set(PIP_RC "$<TARGET_FILE_DIR:pip_rc>/$<TARGET_FILE_NAME:pip_rc>" CACHE STRING "")
set(PIP_DEPLOY_TOOL "$<TARGET_FILE_DIR:deploy_tool>/$<TARGET_FILE_NAME:deploy_tool>" CACHE STRING "")
else()
find_program(PIP_CMG pip_cmg${pip_BINEXT} HINTS ${pip_BINDIR} ${pip_FIND_PROGRAM_ARG})
find_program(PIP_RC pip_rc${pip_BINEXT} HINTS ${pip_BINDIR} ${pip_FIND_PROGRAM_ARG})
find_program(PIP_DEPLOY_TOOL deploy_tool${pip_BINEXT} HINTS ${pip_BINDIR} ${pip_FIND_PROGRAM_ARG})
endif()
if (NOT PIP_LIBRARY)
if(PIP_FIND_REQUIRED)
message(FATAL_ERROR "Can`t find PIP library!")
endif() endif()
return() if(APPLE)
include_directories(/usr/local/include)
link_directories(/usr/local/lib)
endif()
endif()
list(APPEND _PIP_LIBDIR "$ENV{SMSDK_DIR}/lib")
if(MINGW_INCLUDE)
list(APPEND _PIP_BINDIR "${MINGW_BIN}")
endif()
if(CMAKE_CROSSCOMPILING)
set(_PIP_FP_DP "NO_DEFAULT_PATH")
list(APPEND _PIP_BINDIR "/usr/bin" "/usr/local/bin")
else()
list(APPEND _PIP_BINDIR "${CMAKE_PREFIX_PATH}/bin")
endif()
list(APPEND _PIP_BINDIR "${PIP_DIR}/bin")
set(_pip_suffix "")
find_library(PIP_LIBRARY pip${_pip_suffix} HINTS ${_PIP_LIBDIR})
find_library(PIP_USB_LIBRARY pip_usb${_pip_suffix} HINTS ${_PIP_LIBDIR})
find_library(PIP_CONSOLE_LIBRARY pip_console${_pip_suffix} HINTS ${_PIP_LIBDIR})
find_library(PIP_CRYPT_LIBRARY pip_crypt${_pip_suffix} HINTS ${_PIP_LIBDIR})
find_library(PIP_FFTW_LIBRARY pip_fftw${_pip_suffix} HINTS ${_PIP_LIBDIR})
find_library(PIP_COMPRESS_LIBRARY pip_compress${_pip_suffix} HINTS ${_PIP_LIBDIR})
find_library(PIP_OPENCL_LIBRARY pip_opencl${_pip_suffix} HINTS ${_PIP_LIBDIR})
find_library(PIP_IO_UTILS_LIBRARY pip_io_utils${_pip_suffix} HINTS ${_PIP_LIBDIR})
find_library(PIP_CLOUD_LIBRARY pip_cloud HINTS${_pip_suffix} ${_PIP_LIBDIR})
find_library(PIP_LUA_LIBRARY pip_lua HINTS${_pip_suffix} ${_PIP_LIBDIR})
find_file(PIP_H_INCLUDE "pip.h" HINTS ${_PIP_INCDIR} $ENV{SMSDK_DIR}/include/pip)
get_filename_component(PIP_INCLUDES ${PIP_H_INCLUDE} PATH)
set(__ext "")
if ("x${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "xWindows")
set(__ext ".exe")
if (CMAKE_CROSSCOMPILING)
set(_PIP_FP_DP)
endif()
endif()
#message("FIND \"${__ext}\" -> ${_PIP_BINDIR}")
find_program(PIP_CMG pip_cmg${__ext} HINTS ${_PIP_BINDIR} ${_PIP_FP_DP})
find_program(PIP_RC pip_rc${__ext} HINTS ${_PIP_BINDIR} ${_PIP_FP_DP})
find_program(PIP_DEPLOY_TOOL deploy_tool${__ext} HINTS ${_PIP_BINDIR} ${_PIP_FP_DP})
if (NOT PIP_LIBRARY)
message(FATAL_ERROR "Can`t find PIP library!")
endif() endif()
set(_PIP_LIBRARY_PATH_ "${PIP_LIBRARY}") set(_PIP_LIBRARY_PATH_ "${PIP_LIBRARY}")
set(_PIP_ADD_LIBS_ "") set(_PIP_ADD_LIBS_ "")
if (NOT BUILDING_pip) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") find_library(DL_LIBRARY dl)
find_library(DL_LIBRARY dl) list(APPEND PIP_LIBRARY ${DL_LIBRARY})
list(APPEND PIP_LIBRARY ${DL_LIBRARY}) if (NOT DEFINED ANDROID_PLATFORM)
if (NOT DEFINED ANDROID_PLATFORM) find_library(PTHREAD_LIBRARY pthread)
find_library(PTHREAD_LIBRARY pthread) find_library(UTIL_LIBRARY util)
find_library(UTIL_LIBRARY util) set(_PIP_ADD_LIBS_ ${PTHREAD_LIBRARY} ${UTIL_LIBRARY})
set(_PIP_ADD_LIBS_ ${PTHREAD_LIBRARY} ${UTIL_LIBRARY}) list(APPEND PIP_LIBRARY ${_PIP_ADD_LIBS_})
list(APPEND PIP_LIBRARY ${_PIP_ADD_LIBS_})
endif()
endif() endif()
endif() endif()
if(PIP_LIBRARY_lua) if(PIP_LUA_LIBRARY)
if (NOT LUA_FOUND) if (NOT LUA_FOUND)
if(MINGW) if(MINGW)
set(LUA_INCLUDE_DIR ${MINGW_INCLUDE}) set(LUA_INCLUDE_DIR ${MINGW_INCLUDE})
@@ -89,81 +110,62 @@ if(PIP_LIBRARY_lua)
endif() endif()
endif() endif()
if (NOT BUILDING_pip) if(NOT PIP_VERSION)
shstk_find_header(pip PIP "pip_version.h" "${_PIP_LIBRARY_PATH_}") include(CheckSymbolExists)
check_symbol_exists(PIP_VERSION_NAME "${PIP_INCLUDES}/piversion.h" HAVE_PIP_VERSION)
if (HAVE_PIP_VERSION)
file(STRINGS "${PIP_INCLUDES}/piversion.h" _VERSION REGEX "^[ \t]*#define[ \t]+PIP_VERSION_NAME+[ \t]+.*$")
string(REGEX MATCH "\".*\"" _VERSION ${_VERSION})
string(LENGTH ${_VERSION} SL)
math(EXPR SL ${SL}-2)
string(SUBSTRING ${_VERSION} 1 ${SL} _VERSION)
set(PIP_VERSION ${_VERSION} CACHE STRING "VERSION")
if (NOT _PIP_MSG)
set(_PIP_MSG 1 CACHE BOOL "msg_pip" FORCE)
message(STATUS "Found PIP: ${_PIP_LIBRARY_PATH_} (version \"${PIP_VERSION}\")")
endif()
else()
message(FATAL_ERROR "Can`t find PIP version file!")
endif()
endif() endif()
if(PIP_FIND_VERSION VERSION_GREATER PIP_VERSION) if(PIP_FIND_VERSION VERSION_GREATER PIP_VERSION)
message(FATAL_ERROR "PIP version ${PIP_VERSION} is available, but ${PIP_FIND_VERSION} requested!") message(FATAL_ERROR "PIP version ${PIP_VERSION} is available, but ${PIP_FIND_VERSION} requested!")
endif() endif()
set(__module_usb USB ) set(__modules "USB;Crypt;Console;FFTW;Compress;IOUtils;Cloud;Lua")
set(__module_console Console ) set(__module_USB "${PIP_USB_LIBRARY}" )
set(__module_crypt Crypt ) set(__module_Console "${PIP_CONSOLE_LIBRARY}" )
set(__module_fftw FFTW ) set(__module_Crypt "${PIP_CRYPT_LIBRARY}" )
set(__module_compress Compress ) set(__module_FFTW "${PIP_FFTW_LIBRARY}" )
set(__module_opencl OpenCL ) set(__module_Compress "${PIP_COMPRESS_LIBRARY}" )
set(__module_io_utils IOUtils ) set(__module_OpenCL "${PIP_OPENCL_LIBRARY}" )
set(__module_cloud Cloud ) set(__module_IOUtils "${PIP_IO_UTILS_LIBRARY}" )
set(__module_lua Lua ) set(__module_Cloud "${PIP_CLOUD_LIBRARY}" )
set(__module_Lua "${PIP_LUA_LIBRARY}" )
foreach (_l ${__libs}) if((NOT TARGET PIP) AND PIP_LIBRARY)
set( __inc_${_l} "") add_library(PIP UNKNOWN IMPORTED)
set(__deps_${_l} "") set_target_properties(PIP PROPERTIES
set(__libs_${_l} "") IMPORTED_LOCATION "${_PIP_LIBRARY_PATH_}"
endforeach() INTERFACE_INCLUDE_DIRECTORIES "${PIP_INCLUDES}"
INTERFACE_LINK_LIBRARIES "${_PIP_ADD_LIBS_}")
set( __inc_lua "${LUA_INCLUDE_DIR}") endif()
foreach (_m ${__modules})
set(__deps_io_utils "PIP::Crypt") if((NOT TARGET PIP::${_m}) AND __module_${_m})
set(__deps_cloud "PIP::IOUtils") add_library(PIP::${_m} UNKNOWN IMPORTED)
set_target_properties(PIP::${_m} PROPERTIES
set(__libs_lua "${LUA_LIBRARIES}") IMPORTED_LOCATION "${__module_${_m}}"
INTERFACE_LINK_LIBRARIES "PIP")
endif()
if (BUILDING_pip) endforeach()
if(__module_IOUtils AND __module_Crypt)
if (NOT SET_TARGETS_pip) set_target_properties(PIP::IOUtils PROPERTIES INTERFACE_LINK_LIBRARIES "PIP::Crypt")
set(SET_TARGETS_pip ON CACHE BOOL "") endif()
#message("create aliases") if(__module_Cloud AND __module_IOUtils)
if((NOT TARGET PIP) AND PIP_LIBRARY) set_target_properties(PIP::Cloud PROPERTIES INTERFACE_LINK_LIBRARIES "PIP::IOUtils")
#message("alias PIP = pip") endif()
add_library(PIP ALIAS pip) if(__module_Lua)
endif() set_target_properties(PIP::Lua PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}" INTERFACE_LINK_LIBRARIES "PIP;${LUA_LIBRARIES}")
foreach (_l ${__libs})
set(_m ${__module_${_l}})
if((NOT TARGET PIP::${_m}) AND TARGET pip_${_l})
#message("alias PIP::${_m} = pip_${_l}")
add_library(PIP::${_m} ALIAS pip_${_l})
endif()
endforeach()
endif()
else()
#message("create interfaces")
if((NOT TARGET PIP) AND PIP_LIBRARY)
add_library(PIP UNKNOWN IMPORTED)
set_target_properties(PIP PROPERTIES
IMPORTED_LOCATION "${_PIP_LIBRARY_PATH_}"
INTERFACE_INCLUDE_DIRECTORIES "${pip_INCLUDES}"
INTERFACE_LINK_LIBRARIES "${_PIP_ADD_LIBS_}")
#message("imported PIP = ${PIP_LIBRARY}")
endif()
foreach (_l ${__libs})
set(_m ${__module_${_l}})
if((NOT TARGET PIP::${_m}) AND PIP_LIBRARY_${_l})
add_library(PIP::${_m} UNKNOWN IMPORTED)
set_target_properties(PIP::${_m} PROPERTIES
IMPORTED_LOCATION "${PIP_LIBRARY_${_l}}"
INTERFACE_INCLUDE_DIRECTORIES "${__inc_${_l}}"
INTERFACE_LINK_LIBRARIES "PIP;${__deps_${_l}};${__libs_${_l}}")
#message("imported PIP::${_m} = ${PIP_LIBRARY_${_l}} ${__deps_${_l}} ${__libs_${_l}} ${__inc_${_l}}")
endif()
endforeach()
endif() endif()
set(PIP_FOUND ON CACHE BOOL "")
include(PIPMacros) include(PIPMacros)

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CFBundleLongVersionString</key>
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key>
<string>${MACOSX_BUNDLE_SIGNATURE}</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>NSSupportsAutomaticTermination</key>
<true/>
<key>NSSupportsSuddenTermination</key>
<true/>
${MACOSX_BUNDLE_PRIVACIES}
</dict>
</plist>

View File

@@ -1,11 +1,11 @@
#[[ #[[
pip_code_model(<out_var> file0 [file1 ...] [OPTIONS opt0 [opt1 ...] ]) pip_code_model(<out_var> file0 [file1 ...] [OPTIONS opt0 [opt1 ...] ] [ABSOLUTE])
Generate code model files for source files file0 [file1 ...] Generate code model files for source files file0 [file1 ...]
Options you can see by exec "pip_cmg -h" Options you can see by exec "pip_cmg -h"
Relative files pathes read from CMAKE_CURRENT_SOURCE_DIR If not ABSOLUTE source files will be prepended by CMAKE_CURRENT_SOURCE_DIR
You should add ${<out_var>} to your target You should add ${<out_var>} to your target
@@ -53,13 +53,15 @@ macro(pip_code_model RESULT)
set(CCM_OUT ${CMAKE_CURRENT_BINARY_DIR}/ccm_${PROJECT_NAME}.cpp) set(CCM_OUT ${CMAKE_CURRENT_BINARY_DIR}/ccm_${PROJECT_NAME}.cpp)
set(${RESULT} ${${RESULT}} ${CCM_OUT}) set(${RESULT} ${${RESULT}} ${CCM_OUT})
set(CCM_FILES) set(CCM_FILES)
foreach(csrc ${CCM_SRC}) if (ABS)
if (IS_ABSOLUTE "${csrc}") foreach(csrc ${CCM_SRC})
list(APPEND CCM_FILES "${csrc}") list(APPEND CCM_FILES "${csrc}")
else() endforeach()
else()
foreach(csrc ${CCM_SRC})
list(APPEND CCM_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${csrc}") list(APPEND CCM_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${csrc}")
endif() endforeach()
endforeach() endif()
#message(STATUS "CCM = ${RESULT}") #message(STATUS "CCM = ${RESULT}")
if(NOT DEFINED PIP_DLL_DIR) if(NOT DEFINED PIP_DLL_DIR)
set(PIP_DLL_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(PIP_DLL_DIR ${CMAKE_CURRENT_BINARY_DIR})
@@ -83,6 +85,7 @@ macro(pip_resources RESULT INPUT)
set(SRC_RC_OUT "${RC_OUT}") set(SRC_RC_OUT "${RC_OUT}")
set(RC_OUT ${CMAKE_CURRENT_BINARY_DIR}/${RC_FILE}) set(RC_OUT ${CMAKE_CURRENT_BINARY_DIR}/${RC_FILE})
set(${RESULT} ${${RESULT}} ${RC_OUT}) set(${RESULT} ${${RESULT}} ${RC_OUT})
set(CCM_FILES)
if(IS_ABSOLUTE "${INPUT}") if(IS_ABSOLUTE "${INPUT}")
set(RC_FILES "${INPUT}") set(RC_FILES "${INPUT}")
else() else()
@@ -93,7 +96,7 @@ macro(pip_resources RESULT INPUT)
set(PIP_DLL_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(PIP_DLL_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif() endif()
set(RC_DEPS ${RC_FILES}) set(RC_DEPS ${RC_FILES})
if(NOT BUILDING_pip) if(NOT PIP_BUILD)
execute_process(COMMAND "${PIP_RC}" -l -i "${RC_FILES}" execute_process(COMMAND "${PIP_RC}" -l -i "${RC_FILES}"
WORKING_DIRECTORY ${PIP_DLL_DIR} WORKING_DIRECTORY ${PIP_DLL_DIR}
OUTPUT_VARIABLE RC_LIST) OUTPUT_VARIABLE RC_LIST)

136
cmake/TargetArch.cmake Normal file
View File

@@ -0,0 +1,136 @@
# Based on the Qt 5 processor detection code, so should be very accurate
# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h
# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64)
# Regarding POWER/PowerPC, just as is noted in the Qt source,
# "There are many more known variants/revisions that we do not handle/detect."
set(archdetect_c_code "
#if defined(__aarch64__)
#error cmake_ARCH arm64
#elif defined(__arm__) || defined(__TARGET_ARCH_ARM)
#if defined(__ARM_ARCH_7__) \\
|| defined(__ARM_ARCH_7A__) \\
|| defined(__ARM_ARCH_7R__) \\
|| defined(__ARM_ARCH_7M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7)
#error cmake_ARCH armv7
#elif defined(__ARM_ARCH_6__) \\
|| defined(__ARM_ARCH_6J__) \\
|| defined(__ARM_ARCH_6T2__) \\
|| defined(__ARM_ARCH_6Z__) \\
|| defined(__ARM_ARCH_6K__) \\
|| defined(__ARM_ARCH_6ZK__) \\
|| defined(__ARM_ARCH_6M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6)
#error cmake_ARCH armv6
#elif defined(__ARM_ARCH_5TEJ__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5)
#error cmake_ARCH armv5
#else
#error cmake_ARCH arm
#endif
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#error cmake_ARCH i386
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
#error cmake_ARCH x86_64
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#error cmake_ARCH ia64
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
|| defined(_M_MPPC) || defined(_M_PPC)
#if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#error cmake_ARCH ppc64
#else
#error cmake_ARCH ppc
#endif
#endif
#error cmake_ARCH unknown
")
# Set ppc_support to TRUE before including this file or ppc and ppc64
# will be treated as invalid architectures since they are no longer supported by Apple
function(target_architecture output_var)
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
# First let's normalize the order of the values
# Note that it's not possible to compile PowerPC applications if you are using
# the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
# disable it by default
# See this page for more information:
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
set(osx_arch_ppc TRUE)
elseif("${osx_arch}" STREQUAL "i386")
set(osx_arch_i386 TRUE)
elseif("${osx_arch}" STREQUAL "x86_64")
set(osx_arch_x86_64 TRUE)
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
set(osx_arch_ppc64 TRUE)
else()
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
endif()
endforeach()
# Now add all the architectures in our normalized order
if(osx_arch_ppc)
list(APPEND ARCH ppc)
endif()
if(osx_arch_i386)
list(APPEND ARCH i386)
endif()
if(osx_arch_x86_64)
list(APPEND ARCH x86_64)
endif()
if(osx_arch_ppc64)
list(APPEND ARCH ppc64)
endif()
else()
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
enable_language(C)
# Detect the architecture in a rather creative way...
# This compiles a small C program which is a series of ifdefs that selects a
# particular #error preprocessor directive whose message string contains the
# target architecture. The program will always fail to compile (both because
# file is not a valid C program, and obviously because of the presence of the
# #error preprocessor directives... but by exploiting the preprocessor in this
# way, we can detect the correct target architecture even when cross-compiling,
# since the program itself never needs to be run (only the compiler/preprocessor)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)
# Parse the architecture name from the compiler output
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
# Get rid of the value marker leaving just the architecture name
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
# If we are compiling with an unknown architecture this variable should
# already be set to "unknown" but in the case that it's empty (i.e. due
# to a typo in the code), then set it to unknown
if (NOT ARCH)
set(ARCH unknown)
endif()
endif()
set(${output_var} "${ARCH}" PARENT_SCOPE)
endfunction()

Binary file not shown.

View File

@@ -0,0 +1,10 @@
androidBuildToolsVersion=
androidCompileSdkVersion=@ANDROID_TARGET_SDK@
android.bundle.enableUncompressedNativeLibs=@ANDROID_NEW_LOADER@
buildDir=build
qt5AndroidDir=@Qt5_ROOT@/src/android/java
DEBUG_STORE_FILE=@__ANDROID_DEBUG_KEYSTORE__@
RELEASE_STORE_FILE=@ANDROID_STORE_FILE@
RELEASE_STORE_PASSWORD=@ANDROID_STORE_PASSWORD@
RELEASE_KEY_PASSWORD=@ANDROID_KEY_PASSWORD@
RELEASE_KEY_ALIAS=@ANDROID_KEY_ALIAS@

View File

@@ -47,21 +47,3 @@ while (!cs2.atEnd()) {
} }
piCout << i << str << f << s.i << s.f << s.s; piCout << i << str << f << s.i << s.f << s.s;
//! [read] //! [read]
//! [write_new]
PIByteArray & operator <<(PIByteArray & s, const S & value) {
PIChunkStream cs;
cs.add(1, value.i).add(2, value.f).add(3, value.s);
s << cs.data();
return s;
}
//! [write_new]
//! [read_new]
PIByteArray & operator >>(PIByteArray & s, S & value) {
PIChunkStream cs;
if (!cs.extract(s)) return s;
cs.readAll();
cs.get(1, value.i).get(2, value.f).get(3, value.s);
return b;
}
//! [read_new]

View File

@@ -49,9 +49,6 @@ PIVector<char> vec(4u, 'p');
piForeachC (char i, vec) piForeachC (char i, vec)
cout << i << ", "; cout << i << ", ";
// p, p, p, p, // p, p, p, p,
piCout << PIVector<int>({1, 2, 3});
// 1, 2, 3
//! [PIVector::PIVector] //! [PIVector::PIVector]
//! [PIVector::at_c] //! [PIVector::at_c]
PIVector<int> vec; PIVector<int> vec;

View File

@@ -1,49 +0,0 @@
set(COMPONENT_SRCS "main.cpp")
set(COMPONENT_ADD_INCLUDEDIRS "../libs/main")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/cloud")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/code")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/compress")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/console")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/containers")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/core")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/crypt")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/geo")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/io_devices")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/io_utils")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/math")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/resources")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/system")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/thread")
set(COMPONENT_PRIV_REQUIRES pthread lwip freertos vfs spi_flash libsodium)
register_component()
set(PIP_FREERTOS ON)
set(LIB OFF)
set(INCLUDE_DIRS ${IDF_INCLUDE_DIRECTORIES})
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/newlib/platform_include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/newlib/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/libsodium/libsodium/src/libsodium/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/libsodium/port_include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/heap/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/esp_rom/include/esp32)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/driver/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/spi_flash/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/spiffs/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/soc/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/soc/esp32/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/freertos/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/lwip/lwip/src/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/lwip/port/esp32/include)
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/vfs/include)
include_directories(${INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR}/pip)
#message("IDF_COMPILE_DEFINITIONS = ${IDF_COMPILE_DEFINITIONS}")
#message("IDF_INCLUDE_DIRECTORIES = ${IDF_INCLUDE_DIRECTORIES}")
add_compile_options(${IDF_COMPILE_OPTIONS})
add_compile_options(${IDF_CXX_COMPILE_OPTIONS})
add_definitions(-DESP_PLATFORM)
add_definitions(-DGCC_NOT_5_2_0=0)
add_definitions(-DHAVE_CONFIG_H)
add_subdirectory(.. pip)
find_package(PIP REQUIRED)
target_link_libraries(${COMPONENT_TARGET} PIP::Crypt PIP::IOUtils PIP::Compress)
target_compile_definitions(${COMPONENT_TARGET} PRIVATE ESP_PLATFORM PIP_FREERTOS)

View File

@@ -0,0 +1,49 @@
set(COMPONENT_SRCS "main.cpp")
set(COMPONENT_ADD_INCLUDEDIRS "pip/lib/main")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/auxiliary")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/code")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/console")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/containers")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/core")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/crypt")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/geo")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/io_devices")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/io_utils")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/math")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/opencl")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/resources")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/system")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/thread")
list(APPEND COMPONENT_ADD_INCLUDEDIRS "pip/lib/main/introspection")
set(COMPONENT_PRIV_REQUIRES pthread lwip freertos vfs spiffs)
register_component()
set(PIP_FREERTOS ON)
set(LIB OFF)
set(INCLUDE_DIRS ${IDF_INCLUDE_DIRECTORIES})
list(APPEND INCLUDE_DIRS "../newlib/platform_include")
list(APPEND INCLUDE_DIRS "../newlib/include")
list(APPEND INCLUDE_DIRS "../libsodium/libsodium/src/libsodium/include")
list(APPEND INCLUDE_DIRS "../libsodium/port_include")
list(APPEND INCLUDE_DIRS "../heap/include")
list(APPEND INCLUDE_DIRS "../esp_rom/include/esp32")
list(APPEND INCLUDE_DIRS "../driver/include")
list(APPEND INCLUDE_DIRS "../spi_flash/include")
list(APPEND INCLUDE_DIRS "../spiffs/include")
list(APPEND INCLUDE_DIRS "../soc/include")
list(APPEND INCLUDE_DIRS "../soc/esp32/include")
list(APPEND INCLUDE_DIRS "../freertos/include")
list(APPEND INCLUDE_DIRS "../lwip/lwip/src/include")
list(APPEND INCLUDE_DIRS "../lwip/port/esp32/include")
list(APPEND INCLUDE_DIRS "../vfs/include")
include_directories(${INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR}/pip)
#message("IDF_COMPILE_DEFINITIONS = ${IDF_COMPILE_DEFINITIONS}")
#message("IDF_INCLUDE_DIRECTORIES = ${IDF_INCLUDE_DIRECTORIES}")
add_compile_options(${IDF_COMPILE_OPTIONS})
add_compile_options(${IDF_CXX_COMPILE_OPTIONS})
add_definitions(-DESP_PLATFORM)
add_definitions(-DGCC_NOT_5_2_0=0)
add_definitions(-DHAVE_CONFIG_H)
add_subdirectory(pip)
target_link_libraries(${COMPONENT_TARGET} pip pip_crypt pip_io_utils pip_compress)

View File

@@ -17,33 +17,24 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "picloudclient.h" #include "piccloudclient.h"
PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode) : PIIODevice(path, mode), eth(PIEthernet::TCP_Client) { PICloudClient::PICloudClient() {
} }
PICloudClient::~PICloudClient() { PICloudClient::~PICloudClient() {
stop();
close();
} }
bool PICloudClient::openDevice() { bool PICloudClient::openDevice() {
return false;
} }
bool PICloudClient::closeDevice() { bool PICloudClient::closeDevice() {
return false;
} }
int PICloudClient::readDevice(void * read_to, int max_size) {
return eth.read(read_to, max_size);
}
int PICloudClient::writeDevice(const void * data, int max_size) {
return eth.write(data, max_size);
}

View File

@@ -1,30 +1,25 @@
/* /*
PIP - Platform Independent Primitives PIP - Platform Independent Primitives
PISpinlock PICloud Server
Ivan Pelipenko peri4ko@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** \class PISpinlock #include "piccloudserver.h"
* \brief Spinlock
* \details
* \section PISpinlock_sec0 Synopsis PICloudServer::PICloudServer() {
* %PISpinlock provides synchronization blocks between several threads. }
* PISpinlock functionality similar to PIMutex, but working on atomic
* type and \a lock() method wait with 100% CPU load.
* \note
* Use this type instead of PIMutex when less waiting time is more
* important than CPU load!
* */

View File

@@ -17,26 +17,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "picloudtcp.h" #include "piccloudtcp.h"
#include "picrypt.h" #include "picrypt.h"
#include "pichunkstream.h"
const char hash_def_key[] = "_picrypt_"; const char hash_def_key[] = "_picrypt_";
PIByteArray & operator <<(PIByteArray & s, const PICloud::Header & v) { PICloudTCP::PICloudTCP() {
s << v.version << v.type << v.sname;
return s;
}
PIByteArray & operator >>(PIByteArray & s, PICloud::Header & v) {
s >> v.version >> v.type >> v.sname;
return s;
}
PICloud::TCP::TCP() {
} }

View File

@@ -20,7 +20,7 @@
#include "picompress.h" #include "picompress.h"
#ifdef PIP_COMPRESS #ifdef PIP_COMPRESS
# ifdef FREERTOS # ifdef FREERTOS
# include "esp32/rom/miniz.h" # include "rom/miniz.h"
# define compress2 mz_compress2 # define compress2 mz_compress2
# define Z_OK MZ_OK # define Z_OK MZ_OK
# define uncompress mz_uncompress # define uncompress mz_uncompress

View File

@@ -409,8 +409,6 @@ bool PICrypt::init() {
if (inited) return true; if (inited) return true;
//piCout << "[PICrypt]" << "init ..."; //piCout << "[PICrypt]" << "init ...";
inited = sodium_init(); inited = sodium_init();
if (!inited)
inited = sodium_init();
//piCout << "[PICrypt]" << "init" << inited; //piCout << "[PICrypt]" << "init" << inited;
return inited; return inited;
#else #else

View File

@@ -1,4 +1,4 @@
/*! \file picloudclient.h /*! \file piccloudclient.h
* \brief PICloud Client * \brief PICloud Client
*/ */
/* /*
@@ -20,11 +20,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PICLOUDCLIENT_H #ifndef PICCLOUDCLIENT_H
#define PICLOUDCLIENT_H #define PICCLOUDCLIENT_H
#include "pip_cloud_export.h" #include "pip_cloud_export.h"
#include "piethernet.h" #include "piiodevice.h"
class PIEthernet;
class PIP_CLOUD_EXPORT PICloudClient : public PIIODevice class PIP_CLOUD_EXPORT PICloudClient : public PIIODevice
@@ -32,7 +34,7 @@ class PIP_CLOUD_EXPORT PICloudClient : public PIIODevice
PIIODEVICE(PICloudClient) PIIODEVICE(PICloudClient)
public: public:
//! //!
explicit PICloudClient(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite); explicit PICloudClient();
virtual ~PICloudClient(); virtual ~PICloudClient();
protected: protected:
@@ -40,10 +42,7 @@ protected:
bool closeDevice(); bool closeDevice();
private: private:
int readDevice(void * read_to, int max_size); PIEthernet * eth;
int writeDevice(const void * data, int max_size);
PIEthernet eth;
}; };
#endif // PICLOUDCLIENT_H #endif // PICCLOUDCLIENT_H

View File

@@ -20,8 +20,8 @@
#ifndef PICLOUDMODULE_H #ifndef PICLOUDMODULE_H
#define PICLOUDMODULE_H #define PICLOUDMODULE_H
#include "picloudtcp.h" #include "piccloudtcp.h"
#include "picloudclient.h" #include "piccloudclient.h"
#include "picloudserver.h" #include "piccloudserver.h"
#endif // PICLOUDMODULE_H #endif // PICLOUDMODULE_H

View File

@@ -0,0 +1,40 @@
/*! \file piccloudserver.h
* \brief PICloud Server
*/
/*
PIP - Platform Independent Primitives
PICloud Server
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PICCLOUDSERVER_H
#define PICCLOUDSERVER_H
#include "pip_cloud_export.h"
#include "piiodevice.h"
class PIP_CLOUD_EXPORT PICloudServer {
public:
//!
explicit PICloudServer();
private:
};
#endif // PICCLOUDSERVER_H

View File

@@ -1,4 +1,4 @@
/*! \file picloudtcp.h /*! \file piccloudtcp.h
* \brief PICloud TCP transport * \brief PICloud TCP transport
*/ */
/* /*
@@ -20,45 +20,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PICLOUDTCP_H #ifndef PICCLOUDTCP_H
#define PICLOUDTCP_H #define PICCLOUDTCP_H
#include "pip_cloud_export.h" #include "pip_cloud_export.h"
#include "pistring.h" #include "pistring.h"
class PIP_CLOUD_EXPORT PICloudTCP {
namespace PICloud {
enum Version {
Version_1 = 1,
};
enum HeaderType {
Server = 1,
Client = 2,
};
struct PIP_CLOUD_EXPORT Header {
Header() {
version = Version_1;
}
uchar version; // PICloud::Version
uchar type; // PICloud::HeaderType
PIString sname; // server name
};
class PIP_CLOUD_EXPORT TCP {
public: public:
TCP(); //!
PICloudTCP();
private: private:
}; };
} #endif // PICCLOUDTCP_H
PIP_CLOUD_EXPORT PIByteArray & operator <<(PIByteArray & s, const PICloud::Header & v);
PIP_CLOUD_EXPORT PIByteArray & operator >>(PIByteArray & s, PICloud::Header & v);
#endif // PICLOUDTCP_H

View File

@@ -174,13 +174,6 @@ inline const char * getMemberType(const char * class_name, const char * member_n
PIP_EXPORT PIVariant getMemberAsVariant(const void * p, const char * class_name, const char * member_name); PIP_EXPORT PIVariant getMemberAsVariant(const void * p, const char * class_name, const char * member_name);
template<typename T, typename std::enable_if< std::is_assignable<T&, const T&>::value, int>::type = 0>
void serialize(PIByteArray & ret, const T & v) {ret << v;}
template<typename T, typename std::enable_if<!std::is_assignable<T&, const T&>::value, int>::type = 0>
void serialize(PIByteArray & ret, const T & v) {}
} }
class PIP_EXPORT __PICodeInfoInitializer__ { class PIP_EXPORT __PICodeInfoInitializer__ {

View File

@@ -252,8 +252,5 @@ inline PIByteArray & operator >>(PIByteArray & s, PIKbdListener::KeyEvent & v) {
inline PIByteArray & operator >>(PIByteArray & s, PIKbdListener::MouseEvent & v) {int a(0); s >> v.x >> v.y >> a >> v.buttons >> v.modifiers; v.action = (PIKbdListener::MouseAction)a; return s;} inline PIByteArray & operator >>(PIByteArray & s, PIKbdListener::MouseEvent & v) {int a(0); s >> v.x >> v.y >> a >> v.buttons >> v.modifiers; v.action = (PIKbdListener::MouseAction)a; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIKbdListener::WheelEvent & v) {uchar d(0); s >> (*(PIKbdListener::MouseEvent*)&v) >> d; v.direction = d; return s;} inline PIByteArray & operator >>(PIByteArray & s, PIKbdListener::WheelEvent & v) {uchar d(0); s >> (*(PIKbdListener::MouseEvent*)&v) >> d; v.direction = d; return s;}
REGISTER_PIVARIANTSIMPLE(PIKbdListener::KeyEvent)
REGISTER_PIVARIANTSIMPLE(PIKbdListener::MouseEvent)
REGISTER_PIVARIANTSIMPLE(PIKbdListener::WheelEvent)
#endif // PIKBDLISTENER_H #endif // PIKBDLISTENER_H

View File

@@ -25,7 +25,6 @@
#include "pip_console_export.h" #include "pip_console_export.h"
#include "pivariant.h" #include "pivariant.h"
#include "pivariantsimple.h"
class PIScreenTile; class PIScreenTile;
@@ -141,11 +140,8 @@ namespace PIScreenTypes {
inline PIByteArray & operator <<(PIByteArray & s, const PIScreenTypes::Cell & v) {s << v.format.raw_format << v.symbol; return s;} inline PIByteArray & operator <<(PIByteArray & s, const PIScreenTypes::Cell & v) {s << v.format.raw_format << v.symbol; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIScreenTypes::Cell & v) {s >> v.format.raw_format >> v.symbol; return s;} inline PIByteArray & operator >>(PIByteArray & s, PIScreenTypes::Cell & v) {s >> v.format.raw_format >> v.symbol; return s;}
inline PIByteArray & operator <<(PIByteArray & s, const PIScreenTypes::TileEvent & v) {s << v.type << v.data; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIScreenTypes::TileEvent & v) {s >> v.type >> v.data; return s;}
REGISTER_PIVARIANTSIMPLE(PIScreenTypes::TileEvent)
#endif // PISCREENTYPES_H #endif // PISCREENTYPES_H

View File

@@ -32,10 +32,6 @@
* \brief Contructs vector with size "size" filled elements "value" * \brief Contructs vector with size "size" filled elements "value"
* \details Example: \snippet picontainers.cpp PIVector::PIVector * \details Example: \snippet picontainers.cpp PIVector::PIVector
* \fn PIVector::PIVector(std::initializer_list list);
* \brief Contructs vector from C++11 initializer list
* \details Example: \snippet picontainers.cpp PIVector::PIVector
* \fn const T & PIVector::at(size_t index) const; * \fn const T & PIVector::at(size_t index) const;
* \brief Read-only access to element by index "index" * \brief Read-only access to element by index "index"
* \details Example: \snippet picontainers.cpp PIVector::at_c * \details Example: \snippet picontainers.cpp PIVector::at_c
@@ -375,7 +371,4 @@
* \fn bool PIMapIterator::next() * \fn bool PIMapIterator::next()
* \brief Jump to next entry and return if new position is valid. * \brief Jump to next entry and return if new position is valid.
* \fn void PIMapIterator::reset()
* \brief Reset iterator to initial position.
* */ * */

View File

@@ -28,13 +28,20 @@
#include "picout.h" #include "picout.h"
#include "piintrospection_containers.h" #include "piintrospection_containers.h"
#ifdef PIP_DEBUG
# ifdef NDEBUG
# undef NDEBUG
# endif
# include <cassert>
#endif
#ifndef assert
# define assert(x)
#endif
#ifdef MAC_OS #ifdef MAC_OS
# include <stdlib.h> # include <stdlib.h>
#else #else
# include <malloc.h> # include <malloc.h>
#endif #endif
#include <initializer_list>
#include <type_traits>
#include <string.h> #include <string.h>
#include <new> #include <new>
#ifndef PIP_MEMALIGN_BYTES #ifndef PIP_MEMALIGN_BYTES

View File

@@ -39,11 +39,6 @@ public:
alloc(other.pid_size, true); alloc(other.pid_size, true);
newT(pid_data + pid_start, other.pid_data + other.pid_start, pid_size); newT(pid_data + pid_start, other.pid_data + other.pid_start, pid_size);
} }
inline PIDeque(std::initializer_list<T> init_list): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
alloc(init_list.size(), true);
newT(pid_data, init_list.begin(), init_list.size());
}
inline PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { inline PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T)) PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
alloc(size, true); alloc(size, true);
@@ -54,7 +49,6 @@ public:
resize(pid_size, f); resize(pid_size, f);
} }
inline PIDeque(PIDeque<T> && other): pid_data(other.pid_data), pid_size(other.pid_size), pid_rsize(other.pid_rsize), pid_start(other.pid_start) { inline PIDeque(PIDeque<T> && other): pid_data(other.pid_data), pid_size(other.pid_size), pid_rsize(other.pid_rsize), pid_start(other.pid_start) {
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
other._reset(); other._reset();
} }
inline virtual ~PIDeque() { inline virtual ~PIDeque() {
@@ -167,6 +161,7 @@ public:
inline bool isEmpty() const {return (pid_size == 0);} inline bool isEmpty() const {return (pid_size == 0);}
inline T & operator [](size_t index) {return pid_data[pid_start + index];} inline T & operator [](size_t index) {return pid_data[pid_start + index];}
inline T & at(size_t index) {return pid_data[pid_start + index];}
inline const T & operator [](size_t index) const {return pid_data[pid_start + index];} inline const T & operator [](size_t index) const {return pid_data[pid_start + index];}
inline const T & at(size_t index) const {return pid_data[pid_start + index];} inline const T & at(size_t index) const {return pid_data[pid_start + index];}
inline T & back() {return pid_data[pid_start + pid_size - 1];} inline T & back() {return pid_data[pid_start + pid_size - 1];}
@@ -209,22 +204,7 @@ public:
inline T * data(size_t index = 0) {return &(pid_data[pid_start + index]);} inline T * data(size_t index = 0) {return &(pid_data[pid_start + index]);}
inline const T * data(size_t index = 0) const {return &(pid_data[pid_start + index]);} inline const T * data(size_t index = 0) const {return &(pid_data[pid_start + index]);}
template<typename T1 = T, typename std::enable_if< inline PIDeque<T> & clear() {resize(0); return *this;}
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIDeque<T> & clear() {
resize(0);
return *this;
}
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIDeque<T> & clear() {
PIINTROSPECTION_CONTAINER_UNUSED(T, pid_size)
pid_size = 0;
return *this;
}
inline PIDeque<T> & fill(const T & f = T()) { inline PIDeque<T> & fill(const T & f = T()) {
deleteT(pid_data + pid_start, pid_size); deleteT(pid_data + pid_start, pid_size);
PIINTROSPECTION_CONTAINER_USED(T, pid_size) PIINTROSPECTION_CONTAINER_USED(T, pid_size)
@@ -233,20 +213,10 @@ public:
return *this; return *this;
} }
inline PIDeque<T> & assign(const T & f = T()) {return fill(f);} inline PIDeque<T> & assign(const T & f = T()) {return fill(f);}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIDeque<T> & assign(size_t new_size, const T & f) { inline PIDeque<T> & assign(size_t new_size, const T & f) {
resize(new_size); resize(new_size);
return fill(f); return fill(f);
} }
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIDeque<T> & assign(size_t new_size, const T & f) {
_resizeRaw(new_size);
return fill(f);
}
inline PIDeque<T> & resize(size_t new_size, const T & f = T()) { inline PIDeque<T> & resize(size_t new_size, const T & f = T()) {
if (new_size < pid_size) { if (new_size < pid_size) {
@@ -261,18 +231,9 @@ public:
} }
return *this; return *this;
} }
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIDeque<T> & _resizeRaw(size_t new_size) { inline PIDeque<T> & _resizeRaw(size_t new_size) {
if (new_size > pid_size) { piCout << "Error, \"resizeRaw()\" only allowed for simple type declared with __PIDEQUE_SIMPLE_TYPE__ macro!";
PIINTROSPECTION_CONTAINER_USED(T, (new_size-pid_size)); assert(0);
}
if (new_size < pid_size) {
PIINTROSPECTION_CONTAINER_UNUSED(T, (pid_size-new_size));
}
alloc(new_size, true);
return *this; return *this;
} }
@@ -471,24 +432,11 @@ private:
++t; ++t;
return (1 << t); return (1 << t);
} }
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void newT(T * dst, const T * src, size_t s) { inline void newT(T * dst, const T * src, size_t s) {
PIINTROSPECTION_CONTAINER_USED(T, s) PIINTROSPECTION_CONTAINER_USED(T, s)
for (size_t i = 0; i < s; ++i) for (size_t i = 0; i < s; ++i)
elementNew(dst + i, src[i]); elementNew(dst + i, src[i]);
} }
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void newT(T * dst, const T * src, size_t s) {
PIINTROSPECTION_CONTAINER_USED(T, s)
memcpy((void*)(dst), (const void*)(src), s * sizeof(T));
}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void deleteT(T * d, size_t sz) { inline void deleteT(T * d, size_t sz) {
PIINTROSPECTION_CONTAINER_UNUSED(T, sz) PIINTROSPECTION_CONTAINER_UNUSED(T, sz)
if ((uchar*)d != 0) { if ((uchar*)d != 0) {
@@ -496,36 +444,9 @@ private:
elementDelete(d[i]); elementDelete(d[i]);
} }
} }
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void deleteT(T * d, size_t sz) {
PIINTROSPECTION_CONTAINER_UNUSED(T, sz)
}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementNew(T * to, const T & from) {new(to)T(from);} inline void elementNew(T * to, const T & from) {new(to)T(from);}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementNew(T * to, T && from) {new(to)T(std::move(from));} inline void elementNew(T * to, T && from) {new(to)T(std::move(from));}
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementNew(T1 * to, const T & from) {(*to) = from;}
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementNew(T * to, T && from) {(*to) = std::move(from);}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementDelete(T & from) {from.~T();} inline void elementDelete(T & from) {from.~T();}
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementDelete(T & from) {}
inline void dealloc() { inline void dealloc() {
if ((uchar*)pid_data != 0) free((uchar*)pid_data); if ((uchar*)pid_data != 0) free((uchar*)pid_data);
pid_data = 0; pid_data = 0;
@@ -594,6 +515,41 @@ private:
ssize_t pid_start; ssize_t pid_start;
}; };
#define __PIDEQUE_SIMPLE_TYPE__(T) \
template<> inline void PIDeque<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
template<> inline void PIDeque<T>::deleteT(T *, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz);} \
template<> inline void PIDeque<T>::elementNew(T * to, const T & from) {(*to) = from;} \
template<> inline void PIDeque<T>::elementNew(T * to, T && from) {(*to) = std::move(from);} \
template<> inline void PIDeque<T>::elementDelete(T &) {;} \
template<> inline PIDeque<T> & PIDeque<T>::_resizeRaw(size_t new_size) { \
if (new_size > pid_size) { \
PIINTROSPECTION_CONTAINER_USED(T, (new_size-pid_size)); \
} \
if (new_size < pid_size) { \
PIINTROSPECTION_CONTAINER_UNUSED(T, (pid_size-new_size)); \
} \
alloc(new_size, true); \
return *this; \
} \
template<> inline PIDeque<T> & PIDeque<T>::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, pid_size); pid_size = 0; return *this;} \
template<> inline PIDeque<T> & PIDeque<T>::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);}
__PIDEQUE_SIMPLE_TYPE__(bool)
__PIDEQUE_SIMPLE_TYPE__(char)
__PIDEQUE_SIMPLE_TYPE__(uchar)
__PIDEQUE_SIMPLE_TYPE__(short)
__PIDEQUE_SIMPLE_TYPE__(ushort)
__PIDEQUE_SIMPLE_TYPE__(int)
__PIDEQUE_SIMPLE_TYPE__(uint)
__PIDEQUE_SIMPLE_TYPE__(long)
__PIDEQUE_SIMPLE_TYPE__(ulong)
__PIDEQUE_SIMPLE_TYPE__(llong)
__PIDEQUE_SIMPLE_TYPE__(ullong)
__PIDEQUE_SIMPLE_TYPE__(float)
__PIDEQUE_SIMPLE_TYPE__(double)
__PIDEQUE_SIMPLE_TYPE__(ldouble)
#ifdef PIP_STD_IOSTREAM #ifdef PIP_STD_IOSTREAM
template<typename T> template<typename T>

View File

@@ -28,6 +28,9 @@
#include "pivector.h" #include "pivector.h"
#include "pideque.h" #include "pideque.h"
#include "pipair.h" #include "pipair.h"
# define __PICONTAINERS_SIMPLE_TYPE__(T) \
__PIDEQUE_SIMPLE_TYPE__(T)\
__PIVECTOR_SIMPLE_TYPE__(T)
template<class T> template<class T>
@@ -203,6 +206,7 @@ public:
return pim_content.back(); return pim_content.back();
} }
const T operator [](const Key & key) const {bool f(false); ssize_t i = _find(key, f); if (f) return pim_content[pim_index[i].index]; return T();} const T operator [](const Key & key) const {bool f(false); ssize_t i = _find(key, f); if (f) return pim_content[pim_index[i].index]; return T();}
T & at(const Key & key) {return (*this)[key];}
const T at(const Key & key) const {return (*this)[key];} const T at(const Key & key) const {return (*this)[key];}
PIMap<Key, T> & operator <<(const PIMap<Key, T> & other) { PIMap<Key, T> & operator <<(const PIMap<Key, T> & other) {
@@ -360,13 +364,6 @@ public:
} }
return false; return false;
} }
inline void reset() {
if (rev) {
pos = m.size_s();
} else {
pos = -1;
}
}
private: private:
const MapType & m; const MapType & m;
ssize_t pos; ssize_t pos;

View File

@@ -44,17 +44,11 @@ public:
alloc(other.piv_size); alloc(other.piv_size);
newT(piv_data, other.piv_data, piv_size); newT(piv_data, other.piv_data, piv_size);
} }
inline PIVector(std::initializer_list<T> init_list): piv_data(0), piv_size(0), piv_rsize(0) {
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
alloc(init_list.size());
newT(piv_data, init_list.begin(), init_list.size());
}
inline PIVector(size_t piv_size, const T & f = T()): piv_data(0), piv_size(0), piv_rsize(0) { inline PIVector(size_t piv_size, const T & f = T()): piv_data(0), piv_size(0), piv_rsize(0) {
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T)) PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
resize(piv_size, f); resize(piv_size, f);
} }
inline PIVector(PIVector<T> && other): piv_data(other.piv_data), piv_size(other.piv_size), piv_rsize(other.piv_rsize) { inline PIVector(PIVector<T> && other): piv_data(other.piv_data), piv_size(other.piv_size), piv_rsize(other.piv_rsize) {
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
other._reset(); other._reset();
} }
inline virtual ~PIVector() { inline virtual ~PIVector() {
@@ -167,6 +161,7 @@ public:
inline bool isEmpty() const {return (piv_size == 0);} inline bool isEmpty() const {return (piv_size == 0);}
inline T & operator [](size_t index) {return piv_data[index];} inline T & operator [](size_t index) {return piv_data[index];}
inline T & at(size_t index) {return piv_data[index];}
inline const T & operator [](size_t index) const {return piv_data[index];} inline const T & operator [](size_t index) const {return piv_data[index];}
inline const T & at(size_t index) const {return piv_data[index];} inline const T & at(size_t index) const {return piv_data[index];}
inline T & back() {return piv_data[piv_size - 1];} inline T & back() {return piv_data[piv_size - 1];}
@@ -210,22 +205,7 @@ public:
inline T * data(size_t index = 0) {return &(piv_data[index]);} inline T * data(size_t index = 0) {return &(piv_data[index]);}
inline const T * data(size_t index = 0) const {return &(piv_data[index]);} inline const T * data(size_t index = 0) const {return &(piv_data[index]);}
template<typename T1 = T, typename std::enable_if< inline PIVector<T> & clear() {resize(0); return *this;}
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIVector<T> & clear() {
resize(0);
return *this;
}
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIVector<T> & clear() {
PIINTROSPECTION_CONTAINER_UNUSED(T, piv_size)
piv_size = 0;
return *this;
}
inline PIVector<T> & fill(const T & f = T()) { inline PIVector<T> & fill(const T & f = T()) {
deleteT(piv_data, piv_size); deleteT(piv_data, piv_size);
PIINTROSPECTION_CONTAINER_USED(T, piv_size) PIINTROSPECTION_CONTAINER_USED(T, piv_size)
@@ -234,20 +214,10 @@ public:
return *this; return *this;
} }
inline PIVector<T> & assign(const T & f = T()) {return fill(f);} inline PIVector<T> & assign(const T & f = T()) {return fill(f);}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIVector<T> & assign(size_t new_size, const T & f) { inline PIVector<T> & assign(size_t new_size, const T & f) {
resize(new_size); resize(new_size);
return fill(f); return fill(f);
} }
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIVector<T> & assign(size_t new_size, const T & f) {
_resizeRaw(new_size);
return fill(f);
}
inline PIVector<T> & resize(size_t new_size, const T & f = T()) { inline PIVector<T> & resize(size_t new_size, const T & f = T()) {
if (new_size < piv_size) { if (new_size < piv_size) {
@@ -264,17 +234,9 @@ public:
} }
return *this; return *this;
} }
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIVector<T> & _resizeRaw(size_t new_size) { inline PIVector<T> & _resizeRaw(size_t new_size) {
if (new_size > piv_size) { piCout << "Error, \"resizeRaw()\" only allowed for simple type declared with __PIVECTOR_SIMPLE_TYPE__ macro!";
PIINTROSPECTION_CONTAINER_USED(T, (new_size-piv_size)); assert(0);
}
if (new_size < piv_size) {
PIINTROSPECTION_CONTAINER_UNUSED(T, (piv_size-new_size));
}
alloc(new_size);
return *this; return *this;
} }
inline void _copyRaw(T * dst, const T * src, size_t size) { inline void _copyRaw(T * dst, const T * src, size_t size) {
@@ -458,24 +420,11 @@ private:
while (s_ >> t) ++t; while (s_ >> t) ++t;
return (1 << t); return (1 << t);
} }
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void newT(T * dst, const T * src, size_t s) { inline void newT(T * dst, const T * src, size_t s) {
PIINTROSPECTION_CONTAINER_USED(T, s) PIINTROSPECTION_CONTAINER_USED(T, s)
for (size_t i = 0; i < s; ++i) for (size_t i = 0; i < s; ++i)
elementNew(dst + i, src[i]); elementNew(dst + i, src[i]);
} }
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void newT(T * dst, const T * src, size_t s) {
PIINTROSPECTION_CONTAINER_USED(T, s)
memcpy((void*)(dst), (const void*)(src), s * sizeof(T));
}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void deleteT(T * d, size_t sz) { inline void deleteT(T * d, size_t sz) {
PIINTROSPECTION_CONTAINER_UNUSED(T, sz) PIINTROSPECTION_CONTAINER_UNUSED(T, sz)
if ((uchar*)d != 0) { if ((uchar*)d != 0) {
@@ -483,36 +432,9 @@ private:
elementDelete(d[i]); elementDelete(d[i]);
} }
} }
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void deleteT(T * d, size_t sz) {
PIINTROSPECTION_CONTAINER_UNUSED(T, sz)
}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementNew(T * to, const T & from) {new(to)T(from);} inline void elementNew(T * to, const T & from) {new(to)T(from);}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementNew(T * to, T && from) {new(to)T(std::move(from));} inline void elementNew(T * to, T && from) {new(to)T(std::move(from));}
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementNew(T1 * to, const T & from) {(*to) = from;}
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementNew(T * to, T && from) {(*to) = std::move(from);}
template<typename T1 = T, typename std::enable_if<
!std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementDelete(T & from) {from.~T();} inline void elementDelete(T & from) {from.~T();}
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline void elementDelete(T & from) {}
inline void dealloc() { inline void dealloc() {
if ((uchar*)piv_data != 0) free((uchar*)piv_data); if ((uchar*)piv_data != 0) free((uchar*)piv_data);
piv_data = 0; piv_data = 0;
@@ -537,6 +459,41 @@ private:
}; };
#define __PIVECTOR_SIMPLE_TYPE__(T) \
template<> inline void PIVector<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
template<> inline void PIVector<T>::deleteT(T *, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz);} \
template<> inline void PIVector<T>::elementNew(T * to, const T & from) {(*to) = from;} \
template<> inline void PIVector<T>::elementNew(T * to, T && from) {(*to) = std::move(from);} \
template<> inline void PIVector<T>::elementDelete(T &) {;} \
template<> inline PIVector<T> & PIVector<T>::_resizeRaw(size_t new_size) { \
if (new_size > piv_size) { \
PIINTROSPECTION_CONTAINER_USED(T, (new_size-piv_size)); \
} \
if (new_size < piv_size) { \
PIINTROSPECTION_CONTAINER_UNUSED(T, (piv_size-new_size)); \
} \
alloc(new_size); \
return *this; \
} \
template<> inline PIVector<T> & PIVector<T>::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, piv_size); piv_size = 0; return *this;} \
template<> inline PIVector<T> & PIVector<T>::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);}
__PIVECTOR_SIMPLE_TYPE__(bool)
__PIVECTOR_SIMPLE_TYPE__(char)
__PIVECTOR_SIMPLE_TYPE__(uchar)
__PIVECTOR_SIMPLE_TYPE__(short)
__PIVECTOR_SIMPLE_TYPE__(ushort)
__PIVECTOR_SIMPLE_TYPE__(int)
__PIVECTOR_SIMPLE_TYPE__(uint)
__PIVECTOR_SIMPLE_TYPE__(long)
__PIVECTOR_SIMPLE_TYPE__(ulong)
__PIVECTOR_SIMPLE_TYPE__(llong)
__PIVECTOR_SIMPLE_TYPE__(ullong)
__PIVECTOR_SIMPLE_TYPE__(float)
__PIVECTOR_SIMPLE_TYPE__(double)
__PIVECTOR_SIMPLE_TYPE__(ldouble)
#ifdef PIP_STD_IOSTREAM #ifdef PIP_STD_IOSTREAM
template<typename T> template<typename T>

View File

@@ -160,7 +160,6 @@ public:
inline T & element(size_t row, size_t col) {return mat[row * cols_ + col];} inline T & element(size_t row, size_t col) {return mat[row * cols_ + col];}
inline const T & element(size_t row, size_t col) const {return mat[row * cols_ + col];} inline const T & element(size_t row, size_t col) const {return mat[row * cols_ + col];}
inline const T & at(size_t row, size_t col) const {return mat[row * cols_ + col];}
inline Row operator[](size_t index) {return Row(this, index);} inline Row operator[](size_t index) {return Row(this, index);}
inline RowConst operator[](size_t index) const {return RowConst(this, index);} inline RowConst operator[](size_t index) const {return RowConst(this, index);}
inline T * data(size_t index = 0) {return mat.data(index);} inline T * data(size_t index = 0) {return mat.data(index);}
@@ -219,7 +218,7 @@ public:
int cs = (cols - cols_); int cs = (cols - cols_);
if (cs < 0) { if (cs < 0) {
for (size_t r=0; r<rows; ++r) { for (size_t r=0; r<rows; ++r) {
mat.remove(r*cols + cols, -cs); mat.remove(r*cols_ + cols_, -cs);
} }
} }
mat.resize(rows*cols, f); mat.resize(rows*cols, f);
@@ -235,13 +234,6 @@ public:
return *this; return *this;
} }
inline bool operator ==(const PIVector2D<T> & t) const {
if (cols_ != t.cols_ || rows_ != t.rows_)
return false;
return mat == t.mat;
}
inline bool operator !=(const PIVector2D<T> & t) const {return !(*this == t);}
PIVector<PIVector<T> > toVectors() const { PIVector<PIVector<T> > toVectors() const {
PIVector<PIVector<T> > ret; PIVector<PIVector<T> > ret;
ret.reserve(rows_); ret.reserve(rows_);
@@ -259,13 +251,9 @@ public:
piSwap<size_t>(cols_, other.cols_); piSwap<size_t>(cols_, other.cols_);
} }
template<typename T1 = T, typename std::enable_if<
std::is_trivially_copyable<T1>::value
, int>::type = 0>
inline PIVector2D<T> & _resizeRaw(size_t r, size_t c) { inline PIVector2D<T> & _resizeRaw(size_t r, size_t c) {
rows_ = r; piCout << "Error, \"resizeRaw()\" only allowed for simple type declared with __PIVECTOR_SIMPLE_TYPE__ macro!";
cols_ = c; assert(0);
mat._resizeRaw(r*c);
return *this; return *this;
} }
@@ -299,5 +287,22 @@ inline PICout operator <<(PICout s, const PIVector2D<T> & v) {
return s; return s;
} }
#define __PIVECTOR2D_SIMPLE_TYPE__(T) \
template<> inline PIVector2D<T> & PIVector2D<T>::_resizeRaw(size_t r, size_t c) {rows_ = r; cols_ = c; mat._resizeRaw(r*c); return *this;}
__PIVECTOR2D_SIMPLE_TYPE__(bool)
__PIVECTOR2D_SIMPLE_TYPE__(char)
__PIVECTOR2D_SIMPLE_TYPE__(uchar)
__PIVECTOR2D_SIMPLE_TYPE__(short)
__PIVECTOR2D_SIMPLE_TYPE__(ushort)
__PIVECTOR2D_SIMPLE_TYPE__(int)
__PIVECTOR2D_SIMPLE_TYPE__(uint)
__PIVECTOR2D_SIMPLE_TYPE__(long)
__PIVECTOR2D_SIMPLE_TYPE__(ulong)
__PIVECTOR2D_SIMPLE_TYPE__(llong)
__PIVECTOR2D_SIMPLE_TYPE__(ullong)
__PIVECTOR2D_SIMPLE_TYPE__(float)
__PIVECTOR2D_SIMPLE_TYPE__(double)
__PIVECTOR2D_SIMPLE_TYPE__(ldouble)
#endif // PIVECTOR2D_H #endif // PIVECTOR2D_H

View File

@@ -26,7 +26,7 @@
#ifndef PIBASE_H #ifndef PIBASE_H
#define PIBASE_H #define PIBASE_H
#include "pip_version.h" #include "piversion.h"
#include "piplatform.h" #include "piplatform.h"
#include "pip_export.h" #include "pip_export.h"
#include "pip_defs.h" #include "pip_defs.h"
@@ -94,25 +94,6 @@
//! Macro is defined when PIP can use "rt" library for "PITimer::ThreadRT" timers implementation //! Macro is defined when PIP can use "rt" library for "PITimer::ThreadRT" timers implementation
# define PIP_TIMER_RT # define PIP_TIMER_RT
//! Macro to declare private section, export is optional
# define PRIVATE_DECLARATION(export)
//! Macro to start definition of private section
# define PRIVATE_DEFINITION_START(Class)
//! Macro to end definition of private section
# define PRIVATE_DEFINITION_END(Class)
//! Macro to access private section by pointer
# define PRIVATE
//! Macro to start static initializer
# define STATIC_INITIALIZER_BEGIN
//! Macro to end static initializer
# define STATIC_INITIALIZER_END
#endif #endif
#include <functional> #include <functional>
@@ -155,16 +136,6 @@
extern char ** environ; extern char ** environ;
#endif #endif
#ifdef NDEBUG
# undef NDEBUG
#endif
#include <cassert>
#ifndef assert
# define assert(x)
# define assertm(exp, msg)
#else
# define assertm(exp, msg) assert(((void)msg, exp))
#endif
#ifdef CC_GCC #ifdef CC_GCC
# undef DEPRECATED # undef DEPRECATED
@@ -246,29 +217,10 @@
#define PRIVATE (__privateinitializer__.p) #define PRIVATE (__privateinitializer__.p)
#define PRIVATEWB __privateinitializer__.p #define PRIVATEWB __privateinitializer__.p
#define NO_COPY_CLASS(name) \ #define NO_COPY_CLASS(name) \
name(const name&) = delete; \ name(const name&) = delete; \
name& operator=(const name&) = delete; name& operator=(const name&) = delete;
#define _PIP_ADD_COUNTER_WS(a, cnt) a##cnt
#define _PIP_ADD_COUNTER_WF(a, cnt) _PIP_ADD_COUNTER_WS(a, cnt)
#define _PIP_ADD_COUNTER(a) _PIP_ADD_COUNTER_WF(a, __COUNTER__)
#define STATIC_INITIALIZER_BEGIN \
class { \
class _Initializer_ { \
public: \
_Initializer_() {
#define STATIC_INITIALIZER_END \
} \
} _initializer_; \
} _PIP_ADD_COUNTER(_pip_initializer_);
#ifdef FREERTOS #ifdef FREERTOS
# define PIP_MIN_MSLEEP 10. # define PIP_MIN_MSLEEP 10.
#else #else
@@ -340,6 +292,13 @@ template<> inline void piSwapBinary(const void *& f, const void *& s) {
} }
} }
template<> inline void piSwap(double & f, double & s) {piSwapBinary<double>(f, s);}
template<> inline void piSwap(ldouble & f, ldouble & s) {piSwapBinary<ldouble>(f, s);}
#ifdef ARCH_BITS_32
template<> inline void piSwap(float & f, float & s) {piSwapBinary<float>(f, s);}
template<> inline void piSwap(llong & f, llong & s) {piSwapBinary<llong>(f, s);}
template<> inline void piSwap(ullong & f, ullong & s) {piSwapBinary<ullong>(f, s);}
#endif
/*! \brief Function for compare two values without "=" by raw content /*! \brief Function for compare two values without "=" by raw content
* \details Example:\n \snippet piincludes.cpp compareBinary */ * \details Example:\n \snippet piincludes.cpp compareBinary */
@@ -358,7 +317,7 @@ inline bool piCompareBinary(const void * f, const void * s, size_t size) {
* *
* Example: * Example:
* \snippet piincludes.cpp round */ * \snippet piincludes.cpp round */
template<typename T> inline constexpr int piRound(const T & v) {return int(v >= T(0.) ? v + T(0.5) : v - T(0.5));} template<typename T> inline int piRound(const T & v) {return int(v >= T(0.) ? v + T(0.5) : v - T(0.5));}
/*! \brief Templated function return floor of float falue /*! \brief Templated function return floor of float falue
* \details Floor is the largest integer that is not greater than value \n * \details Floor is the largest integer that is not greater than value \n
@@ -368,7 +327,7 @@ template<typename T> inline constexpr int piRound(const T & v) {return int(v >=
* *
* Example: * Example:
* \snippet piincludes.cpp floor */ * \snippet piincludes.cpp floor */
template<typename T> inline constexpr int piFloor(const T & v) {return v < T(0) ? int(v) - 1 : int(v);} template<typename T> inline int piFloor(const T & v) {return v < T(0) ? int(v) - 1 : int(v);}
/*! \brief Templated function return ceil of float falue /*! \brief Templated function return ceil of float falue
* \details Ceil is the smallest integer that is not less than value \n * \details Ceil is the smallest integer that is not less than value \n
@@ -378,7 +337,7 @@ template<typename T> inline constexpr int piFloor(const T & v) {return v < T(0)
* *
* Example: * Example:
* \snippet piincludes.cpp ceil */ * \snippet piincludes.cpp ceil */
template<typename T> inline constexpr int piCeil(const T & v) {return v < T(0) ? int(v) : int(v) + 1;} template<typename T> inline int piCeil(const T & v) {return v < T(0) ? int(v) : int(v) + 1;}
/*! \brief Templated function return absolute of numeric falue /*! \brief Templated function return absolute of numeric falue
* \details Absolute is the positive or equal 0 value \n * \details Absolute is the positive or equal 0 value \n
@@ -392,7 +351,7 @@ template<typename T> inline constexpr int piCeil(const T & v) {return v < T(0) ?
* *
* Example: * Example:
* \snippet piincludes.cpp abs */ * \snippet piincludes.cpp abs */
template<typename T> inline constexpr T piAbs(const T & v) {return (v >= T(0) ? v : -v);} template<typename T> inline T piAbs(const T & v) {return (v >= T(0) ? v : -v);}
/*! \brief Templated function return minimum of two values /*! \brief Templated function return minimum of two values
* \details There are some macros: * \details There are some macros:
@@ -405,7 +364,7 @@ template<typename T> inline constexpr T piAbs(const T & v) {return (v >= T(0) ?
* *
* Example: * Example:
* \snippet piincludes.cpp min2 */ * \snippet piincludes.cpp min2 */
template<typename T> inline constexpr T piMin(const T & f, const T & s) {return ((f > s) ? s : f);} template<typename T> inline T piMin(const T & f, const T & s) {return ((f > s) ? s : f);}
/*! \brief Templated function return minimum of tree values /*! \brief Templated function return minimum of tree values
* \details There are some macros: * \details There are some macros:
@@ -418,7 +377,7 @@ template<typename T> inline constexpr T piMin(const T & f, const T & s) {return
* *
* Example: * Example:
* \snippet piincludes.cpp min3 */ * \snippet piincludes.cpp min3 */
template<typename T> inline constexpr T piMin(const T & f, const T & s, const T & t) {return ((f < s && f < t) ? f : ((s < t) ? s : t));} template<typename T> inline T piMin(const T & f, const T & s, const T & t) {return ((f < s && f < t) ? f : ((s < t) ? s : t));}
/*! \brief Templated function return maximum of two values /*! \brief Templated function return maximum of two values
* \details There are some macros: * \details There are some macros:
@@ -431,7 +390,7 @@ template<typename T> inline constexpr T piMin(const T & f, const T & s, const T
* *
* Example: * Example:
* \snippet piincludes.cpp max2 */ * \snippet piincludes.cpp max2 */
template<typename T> inline constexpr T piMax(const T & f, const T & s) {return ((f < s) ? s : f);} template<typename T> inline T piMax(const T & f, const T & s) {return ((f < s) ? s : f);}
/*! \brief Templated function return maximum of tree values /*! \brief Templated function return maximum of tree values
* \details There are some macros: * \details There are some macros:
@@ -444,7 +403,7 @@ template<typename T> inline constexpr T piMax(const T & f, const T & s) {return
* *
* Example: * Example:
* \snippet piincludes.cpp max3 */ * \snippet piincludes.cpp max3 */
template<typename T> inline constexpr T piMax(const T & f, const T & s, const T & t) {return ((f > s && f > t) ? f : ((s > t) ? s : t));} template<typename T> inline T piMax(const T & f, const T & s, const T & t) {return ((f > s && f > t) ? f : ((s > t) ? s : t));}
/*! \brief Templated function return clamped value /*! \brief Templated function return clamped value
* \details Clamped is the not greater than "max" and not lesser than "min" value \n * \details Clamped is the not greater than "max" and not lesser than "min" value \n
@@ -458,7 +417,7 @@ template<typename T> inline constexpr T piMax(const T & f, const T & s, const T
* *
* Example: * Example:
* \snippet piincludes.cpp clamp */ * \snippet piincludes.cpp clamp */
template<typename T> inline constexpr T piClamp(const T & v, const T & min, const T & max) {return (v > max ? max : (v < min ? min : v));} template<typename T> inline T piClamp(const T & v, const T & min, const T & max) {return (v > max ? max : (v < min ? min : v));}
/// Function inverse byte order in memory block /// Function inverse byte order in memory block
inline void piLetobe(void * data, int size) { inline void piLetobe(void * data, int size) {
@@ -495,7 +454,20 @@ template<> inline float piLetobe(const float & v) {
return a.f; return a.f;
} }
/// \brief Generic hash function, implements murmur3/32 algorithm DEPRECATED inline ushort letobe_s(const ushort & v) {return (v << 8) | (v >> 8);}
DEPRECATED inline uint letobe_i(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
#ifdef DOXYGEN
/// \deprecated \brief Use \a piLetobe() instead of this function
ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);}
/// \deprecated \brief Use \a piLetobe() instead of this function
uint letobe_i(uint v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
#endif
/// \brief Generic hash function, impements murmur3/32 algorithm
inline uint piHashData(const uchar * data, uint len, uint seed = 0) { inline uint piHashData(const uchar * data, uint len, uint seed = 0) {
if (!data || len <= 0) return 0u; if (!data || len <= 0) return 0u;
uint h = seed; uint h = seed;

View File

@@ -396,19 +396,8 @@ PIByteArray & operator >>(PIByteArray & s, PIByteArray & v) {
} }
v.resize(sz); v.resize(sz);
if (sz > 0) { if (sz > 0) {
memcpy(v.data(), s.data(), sz); memcpy(v.data(), s.data(), v.size());
s.remove(0, sz); s.remove(0, v.size());
}
return s;
}
PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) {
s << int(v.size_s());
int os = s.size_s();
if (v.size_s() > 0) {
s.enlarge(v.size_s());
memcpy(s.data(os), v.data(), v.size());
} }
return s; return s;
} }

330
lib/main/core/pibytearray.h Normal file
View File

@@ -0,0 +1,330 @@
/*! \file pibytearray.h
* \brief Byte array
*/
/*
PIP - Platform Independent Primitives
Byte array
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIBYTEARRAY_H
#define PIBYTEARRAY_H
#include "pichar.h"
#include "pibitarray.h"
#include "pimap.h"
#include "pivector2d.h"
__PICONTAINERS_SIMPLE_TYPE__(PIChar)
#define __PIBYTEARRAY_SIMPLE_TYPE__(T) \
template<> \
inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \
template<> \
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \
template<> \
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \
template<> \
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \
template<> \
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {s << int(v.rows()) << int(v.cols()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \
template<> \
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {assert(s.size_s() >= 8); int r, c; s >> r >> c; v._resizeRaw(r, c); int sz = r*c; if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;}
class PIString;
class PIByteArray;
class PIP_EXPORT PIByteArray: public PIDeque<uchar>
{
public:
//! Constructs an empty byte array
PIByteArray() {;}
PIByteArray(const PIByteArray & o): PIDeque<uchar>(o) {}
PIByteArray(PIByteArray && o): PIDeque<uchar>(std::move(o)) {}
//! Constructs 0-filled byte array with size "size"
PIByteArray(const uint size) {resize(size);}
//! Constructs byte array from data "data" and size "size"
PIByteArray(const void * data, const uint size): PIDeque<uchar>((const uchar*)data, size_t(size)) {}
//! Constructs byte array with size "size" filled by "t"
PIByteArray(const uint size, uchar t): PIDeque<uchar>(size, t) {}
//! Help struct to store/restore custom blocks of data to/from PIByteArray
struct RawData {
friend PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v);
friend PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v);
public:
//! Constructs data block
RawData(void * data = 0, int size = 0) {d = data; s = size;}
RawData(const RawData & o) {d = o.d; s = o.s;}
//! Constructs data block
RawData(const void * data, const int size) {d = const_cast<void * >(data); s = size;}
RawData & operator =(const RawData & o) {d = o.d; s = o.s; return *this;}
private:
void * d;
int s;
};
//! Return resized byte array
PIByteArray resized(uint new_size) const {PIByteArray ret(new_size); memcpy(ret.data(), data(), new_size); return ret;}
//! Convert data to Base 64 and return this byte array
PIByteArray & convertToBase64();
//! Convert data from Base 64 and return this byte array
PIByteArray & convertFromBase64();
//! Return converted to Base 64 data
PIByteArray toBase64() const;
//! Return converted from Base 64 data
PIByteArray & compressRLE(uchar threshold = 192);
PIByteArray & decompressRLE(uchar threshold = 192);
PIByteArray compressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.compressRLE(threshold); return ba;}
PIByteArray decompressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.decompressRLE(threshold); return ba;}
PIString toString(int base = 16) const;
PIString toHex() const;
//! Add to the end data "data" with size "size"
PIByteArray & append(const void * data_, int size_) {uint ps = size(); enlarge(size_); memcpy(data(ps), data_, size_); return *this;}
//! Add to the end byte array "data"
PIByteArray & append(const PIByteArray & data_) {uint ps = size(); enlarge(data_.size_s()); memcpy(data(ps), data_.data(), data_.size()); return *this;}
//! Add to the end "t"
PIByteArray & append(uchar t) {push_back(t); return *this;}
//! Returns plain 8-bit checksum
uchar checksumPlain8() const;
//! Returns plain 32-bit checksum
uint checksumPlain32() const;
//! Returns hash
uint hash() const;
void operator =(const PIDeque<uchar> & d) {resize(d.size()); memcpy(data(), d.data(), d.size());}
PIByteArray & operator =(const PIByteArray & o) {if (this == &o) return *this; clear(); append(o); return *this;}
PIByteArray & operator =(PIByteArray && o) {swap(o); return *this;}
static PIByteArray fromUserInput(PIString str);
static PIByteArray fromHex(PIString str);
static PIByteArray fromBase64(const PIByteArray & base64);
static PIByteArray fromBase64(const PIString & base64);
};
inline bool operator <(const PIByteArray & v0, const PIByteArray & v1) {if (v0.size() == v1.size()) {for (uint i = 0; i < v0.size(); ++i) if (v0[i] != v1[i]) return v0[i] < v1[i]; return false;} return v0.size() < v1.size();}
#ifdef PIP_STD_IOSTREAM
//! \relatesalso PIByteArray \brief Output to std::ostream operator
inline std::ostream & operator <<(std::ostream & s, const PIByteArray & ba);
#endif
//! \relatesalso PIByteArray \brief Output to PICout operator
PIP_EXPORT PICout operator <<(PICout s, const PIByteArray & ba);
#define PBA_OPERATOR_TO int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v));
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, bool v) {s.push_back(v); return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, char v) {s.push_back(v); return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, uchar v) {s.push_back(v); return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const short v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const int v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const long & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const llong & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const ushort v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const uint v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const ulong & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const ullong & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const float v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const double & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const ldouble & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
template<typename T> inline PIByteArray & operator <<(PIByteArray & s, const PIFlags<T> & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details
inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()); if (v.size_s() > 0) memcpy(s.data(os), v.data(), v.size()); return s;}
//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details
inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v) {int os = s.size_s(); s.enlarge(v.s); if (v.s > 0) memcpy(s.data(os), v.d, v.s); return s;}
#undef PBA_OPERATOR_TO
#define PBA_OPERATOR_FROM memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v));
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, bool & v) {assert(s.size() >= 1u); v = s.take_front(); return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, char & v) {assert(s.size() >= 1u); v = s.take_front(); return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, uchar & v) {assert(s.size() >= 1u); v = s.take_front(); return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, short & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, int & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, long & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, llong & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, ushort & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, uint & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, ulong & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, ullong & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, float & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, double & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, ldouble & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
template<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIFlags<T> & v) {PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIByteArray & v);
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {assert(s.size_s() >= v.s); if (v.s > 0) memcpy((void*)(v.d), s.data(), v.s); s.remove(0, v.s); return s;}
#undef PBA_OPERATOR_FROM
template<typename Type0, typename Type1> inline PIByteArray & operator <<(PIByteArray & s, const PIPair<Type0, Type1> & v);
//! \relatesalso PIByteArray \brief Store operator
template<typename T> inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v);
//! \relatesalso PIByteArray \brief Store operator
template<typename T> inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v);
//! \relatesalso PIByteArray \brief Store operator
template <typename Key, typename T> inline PIByteArray & operator <<(PIByteArray & s, const PIMap<Key, T> & v);
//! Write operator to \c PIByteArray
inline PIByteArray & operator <<(PIByteArray & s, const PIChar & v) {s << v.ch; return s;}
//! \relatesalso PIByteArray \brief Restore operator
template<typename Type0, typename Type1> inline PIByteArray & operator >>(PIByteArray & s, PIPair<Type0, Type1> & v);
//! \relatesalso PIByteArray \brief Restore operator
template<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v);
//! \relatesalso PIByteArray \brief Restore operator
template<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v);
//! \relatesalso PIByteArray \brief Restore operator
template <typename Key, typename T> inline PIByteArray & operator >>(PIByteArray & s, PIMap<Key, T> & v);
//! Read operator from \c PIByteArray
inline PIByteArray & operator >>(PIByteArray & s, PIChar & v) {s >> v.ch; return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const PIBitArray & v) {s << v.size_ << v.data_; return s;}
template<typename Type0, typename Type1>
inline PIByteArray & operator <<(PIByteArray & s, const PIPair<Type0, Type1> & v) {s << v.first << v.second; return s;}
template<typename T>
inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;}
template<typename T>
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;}
template <typename Key, typename T>
inline PIByteArray & operator <<(PIByteArray & s, const PIMap<Key, T> & v) {
s << int(v.pim_index.size_s());
for (uint i = 0; i < v.size(); ++i)
s << int(v.pim_index[i].index) << v.pim_index[i].key;
s << v.pim_content;
return s;
}
template<typename T>
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {s << int(v.rows()) << int(v.cols()) << v.toPlainVector(); return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, PIBitArray & v) {assert(s.size_s() >= 8); s >> v.size_ >> v.data_; return s;}
template<typename Type0, typename Type1>
inline PIByteArray & operator >>(PIByteArray & s, PIPair<Type0, Type1> & v) {s >> v.first >> v.second; return s;}
template<typename T>
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;}
template<typename T>
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;}
template <typename Key, typename T>
inline PIByteArray & operator >>(PIByteArray & s, PIMap<Key, T> & v) {
assert(s.size_s() >= 4);
int sz; s >> sz; v.pim_index.resize(sz);
int ind = 0;
for (int i = 0; i < sz; ++i) {
s >> ind >> v.pim_index[i].key;
v.pim_index[i].index = ind;
}
s >> v.pim_content;
if (v.pim_content.size_s() != v.pim_index.size_s()) {
piCout << "Warning: loaded invalid PIMap, clear";
v.clear();
}
return s;
}
template<typename T>
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {assert(s.size_s() >= 8); int r,c; PIVector<T> tmp; s >> r >> c >> tmp; v = PIVector2D<T>(r, c, tmp); return s;}
template<typename T>
inline PIByteArray & operator <<(PIByteArray & s, const T & ) {piCout << "[PIByteArray] Warning: using undeclared operator <<!"; return s;}
template<typename T>
inline PIByteArray & operator >>(PIByteArray & s, T & ) {piCout << "[PIByteArray] Warning: using undeclared operator >>!"; return s;}
//! \relatesalso PIByteArray \brief Byte arrays compare operator
inline bool operator ==(PIByteArray & f, PIByteArray & s) {if (f.size_s() != s.size_s()) return false; for (int i = 0; i < f.size_s(); ++i) if (f[i] != s[i]) return false; return true;}
//! \relatesalso PIByteArray \brief Byte arrays compare operator
inline bool operator !=(PIByteArray & f, PIByteArray & s) {if (f.size_s() != s.size_s()) return true; for (int i = 0; i < f.size_s(); ++i) if (f[i] != s[i]) return true; return false;}
__PIBYTEARRAY_SIMPLE_TYPE__(bool)
__PIBYTEARRAY_SIMPLE_TYPE__(char)
__PIBYTEARRAY_SIMPLE_TYPE__(short)
__PIBYTEARRAY_SIMPLE_TYPE__(ushort)
__PIBYTEARRAY_SIMPLE_TYPE__(int)
__PIBYTEARRAY_SIMPLE_TYPE__(uint)
__PIBYTEARRAY_SIMPLE_TYPE__(long)
__PIBYTEARRAY_SIMPLE_TYPE__(ulong)
__PIBYTEARRAY_SIMPLE_TYPE__(llong)
__PIBYTEARRAY_SIMPLE_TYPE__(ullong)
__PIBYTEARRAY_SIMPLE_TYPE__(float)
__PIBYTEARRAY_SIMPLE_TYPE__(double)
__PIBYTEARRAY_SIMPLE_TYPE__(ldouble)
__PIBYTEARRAY_SIMPLE_TYPE__(PIChar)
template<> inline uint piHash(const PIByteArray & ba) {return ba.hash();}
template<> inline void piSwap(PIByteArray & f, PIByteArray & s) {f.swap(s);}
#endif // PIBYTEARRAY_H

View File

@@ -32,7 +32,9 @@ extern PIP_EXPORT char * __utf8name__;
class PIP_EXPORT PIChar class PIP_EXPORT PIChar
{ {
friend class PIString; friend class PIString;
friend PICout PIP_EXPORT operator <<(PICout s, const PIChar & v); friend PIByteArray & operator <<(PIByteArray & s, const PIChar & v);
friend PIByteArray & operator >>(PIByteArray & s, PIChar & v);
friend PICout operator <<(PICout s, const PIChar & v);
public: public:
//! Contructs ascii symbol //! Contructs ascii symbol
PIChar(const char c) {ch = c; ch &= 0xFF;} PIChar(const char c) {ch = c; ch &= 0xFF;}
@@ -133,7 +135,7 @@ private:
}; };
//! Output operator to \a PICout //! Output operator to \a PICout
PICout PIP_EXPORT operator <<(PICout s, const PIChar & v); PICout operator <<(PICout s, const PIChar & v);
//! Compare operator //! Compare operator
inline bool operator ==(const char v, const PIChar & c) {return (PIChar(v) == c);} inline bool operator ==(const char v, const PIChar & c) {return (PIChar(v) == c);}

View File

@@ -41,22 +41,13 @@
* but you should definitely know type of this value. You can read from byte array * but you should definitely know type of this value. You can read from byte array
* while \a atEnd() if false. * while \a atEnd() if false.
* *
* \section PIChunkStream_sec2 Examples * \section PIChunkStream_ex0 Example
* * Prepare your structs to work with %PIChunkStream
* Using simple operator and cascade serialization:
*
* Prepare your structs to work with %PIChunkStream:
* \snippet pichunkstream.cpp struct * \snippet pichunkstream.cpp struct
* Old-style writing to %PIChunkStream: * Writing to %PIChunkStream
* \snippet pichunkstream.cpp write * \snippet pichunkstream.cpp write
* Fastest reading from %PIChunkStream: * Reading from %PIChunkStream
* \snippet pichunkstream.cpp read * \snippet pichunkstream.cpp read
*
* And next code show how to serialize your struct with %PIChunkStream:
* \snippet pichunkstream.cpp write_new
*
* ... and deserialize:
* \snippet pichunkstream.cpp read_new
*/ */
@@ -89,53 +80,17 @@ int PIChunkStream::read() {
} }
int PIChunkStream::peekVInt(Version version_, PIByteArray * data_, int pos, PIByteArray & hdr, uint & ret) {
switch (version_) {
case Version_1:
memcpy(&ret, data_->data(pos), 4);
return 4;
case Version_2: {
hdr.resize(4);
hdr.fill(uchar(0));
memcpy(hdr.data(), data_->data(pos), piMini(4, data_->size_s() - pos));
uchar hsz = 0;
ret = readVInt(hdr, &hsz);
return hsz;
}
default: break;
}
return 0;
}
void PIChunkStream::readAll() { void PIChunkStream::readAll() {
data_map.clear(); data_map.clear();
if (!data_) return; while (!atEnd()) {
int pos = 0, sz = data_->size_s(); read();
uint csz = 0, cid = 0; data_map[last_id] = last_data;
PIByteArray hdr;
while (pos < sz) {
pos += peekVInt((Version)version_, data_, pos, hdr, cid);
pos += peekVInt((Version)version_, data_, pos, hdr, csz);
data_map[cid] = PIPair<int, int>(pos, csz);
pos += csz;
} }
} }
PIChunkStream::~PIChunkStream() { PIChunkStream::~PIChunkStream() {
}
bool PIChunkStream::extract(PIByteArray & data, bool read_all) {
if (data.size_s() < 4) return false;
data >> tmp_data;
if (tmp_data.size_s() < 4) return false;
data_ = &tmp_data;
_init();
if (read_all)
readAll();
return true;
} }
@@ -156,7 +111,7 @@ void PIChunkStream::_init() {
} }
uint PIChunkStream::readVInt(PIByteArray & s, uchar * bytes_cnt) { uint PIChunkStream::readVInt(PIByteArray & s) {
if (s.isEmpty()) return 0; if (s.isEmpty()) return 0;
uchar bytes[4]; s >> bytes[0]; uchar bytes[4]; s >> bytes[0];
uchar abc = 0; uchar abc = 0;
@@ -167,7 +122,6 @@ uint PIChunkStream::readVInt(PIByteArray & s, uchar * bytes_cnt) {
s >> bytes[abc + 1]; s >> bytes[abc + 1];
} else break; } else break;
} }
if (bytes_cnt) *bytes_cnt = (abc + 1);
uint ret = 0; uint ret = 0;
for (int i = 0; i <= abc; ++i) { for (int i = 0; i <= abc; ++i) {
ret += (bytes[i] << (8 * ((int)abc - i))); ret += (bytes[i] << (8 * ((int)abc - i)));

View File

@@ -67,11 +67,6 @@ public:
//! Add data to this chunk strean with ID "id" and value "data" //! Add data to this chunk strean with ID "id" and value "data"
template <typename T> PIChunkStream & add(int id, const T & data) {*this << ChunkConst<T>(id, data); return *this;} template <typename T> PIChunkStream & add(int id, const T & data) {*this << ChunkConst<T>(id, data); return *this;}
//! Extract %PIByteArray from "data" and set it current stream.
//! If "read_all" then call \a readAll() after extract.
//! Returns if has data to read.
bool extract(PIByteArray & data, bool read_all = false);
void setSource(const PIByteArray & data); void setSource(const PIByteArray & data);
void setSource(PIByteArray * data); void setSource(PIByteArray * data);
@@ -84,11 +79,11 @@ public:
//! Returns stream version //! Returns stream version
Version version() const {return (Version)version_;} Version version() const {return (Version)version_;}
//! Read one chunk from stream and returns its ID //! Read one chunk from stream and returns its ID
int read(); int read();
//! Read all chunks from stream. This function just index input data //! Read all chunks from stream
void readAll(); void readAll();
//! Returns last readed chunk ID //! Returns last readed chunk ID
@@ -105,9 +100,7 @@ public:
//! Place value of chunk with id \"id\" into \"v\". You should call \a readAll() before using this function! //! Place value of chunk with id \"id\" into \"v\". You should call \a readAll() before using this function!
template <typename T> template <typename T>
const PIChunkStream & get(int id, T & v) const { const PIChunkStream & get(int id, T & v) const {
PIPair<int, int> pos = data_map.value(id); PIByteArray ba = data_map.value(id);
if (pos.first < 0 || pos.second == 0) return *this;
PIByteArray ba(data_->data(pos.first), pos.second);
if (!ba.isEmpty()) if (!ba.isEmpty())
ba >> v; ba >> v;
return *this; return *this;
@@ -116,14 +109,13 @@ public:
private: private:
void _init(); void _init();
static uint readVInt(PIByteArray & s, uchar * bytes = 0); static uint readVInt(PIByteArray & s);
static void writeVInt(PIByteArray & s, uint val); static void writeVInt(PIByteArray & s, uint val);
static int peekVInt(Version version_, PIByteArray * data_, int pos, PIByteArray & hdr, uint & ret);
int last_id; int last_id;
uchar version_; uchar version_;
PIByteArray * data_, last_data, tmp_data; PIByteArray * data_, last_data, tmp_data;
PIMap<int, PIPair<int, int>> data_map; PIMap<int, PIByteArray> data_map;
template <typename T> friend PIChunkStream & operator <<(PIChunkStream & s, const PIChunkStream::Chunk<T> & c); template <typename T> friend PIChunkStream & operator <<(PIChunkStream & s, const PIChunkStream::Chunk<T> & c);
template <typename T> friend PIChunkStream & operator <<(PIChunkStream & s, const PIChunkStream::ChunkConst<T> & c); template <typename T> friend PIChunkStream & operator <<(PIChunkStream & s, const PIChunkStream::ChunkConst<T> & c);

Some files were not shown because too many files have changed in this diff Show More