Skip to content

Commit

Permalink
Improve ohos support
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Jul 26, 2024
1 parent 941f949 commit 54a0c13
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 64 deletions.
3 changes: 3 additions & 0 deletions 1k/platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "tvOS")
set(IOS TRUE)
set(TVOS TRUE)
set(PLATFORM_NAME tvos)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "OHOS")
set(OHOS TRUE)
set(PLATFORM_NAME ohos)
else()
message(AUTHOR_WARNING "Unhandled platform: ${CMAKE_SYSTEM_NAME}")
endif()
Expand Down
85 changes: 26 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ endif()

set (YASIO_USE_PREBUILT_LUA FALSE)

if (ANDROID)
if (NOT THIRDPART_LIB)
set(THIRDPART_LIB "-llog")
else()
set(THIRDPART_LIB "${THIRDPART_LIB} -llog")
if(WIN32)
set(YASIO_EXTERN_LIBS "ws2_32")
else()
set(YASIO_EXTERN_LIBS "m")
if (ANDROID)
list(APPEND YASIO_EXTERN_LIBS "log")
elseif(OHOS)
list(APPEND YASIO_EXTERN_LIBS "hilog_ndk.z")
endif()
endif()

Expand Down Expand Up @@ -206,44 +209,33 @@ if (YASIO_USE_CARES)
endif()

### The yasio core library project
file(GLOB YASIO_CORE yasio/*.hpp;yasio/*.cpp;yasio/compiler/*.hpp;yasio/impl/*.hpp;)
file(GLOB YASIO_SOURCES yasio/*.hpp;yasio/*.cpp;yasio/compiler/*.hpp;yasio/impl/*.hpp)

if (YASIO_ENABLE_KCP)
if (NOT kcp_SOURCE_DIR)
set(YASIO_CORE ${YASIO_CORE}
${PROJECT_SOURCE_DIR}/3rdparty/kcp/ikcp.c
)
list(APPEND YASIO_SOURCES ${PROJECT_SOURCE_DIR}/3rdparty/kcp/ikcp.c)
list(APPEND YASIO_INC_DIRS "${PROJECT_SOURCE_DIR}/3rdparty/kcp")
else()
list(APPEND THIRDPART_LIB "kcp")
list(APPEND YASIO_EXTERN_LIBS "kcp")
endif()
endif()
if (YASIO_ENABLE_NI)
set(YASIO_CORE ${YASIO_CORE}
yasio/bindings/yasio_ni.cpp
)
list(APPEND YASIO_SOURCES yasio/bindings/yasio_ni.cpp)
endif()

if (YASIO_ENABLE_LUA)
set(YASIO_CORE ${YASIO_CORE}
yasio/bindings/lyasio.cpp
)

if(YASIO_ENABLE_AXLUA)
set(YASIO_CORE ${YASIO_CORE}
yasio/bindings/yasio_axlua.cpp
)
endif()
list(APPEND YASIO_SOURCES yasio/bindings/lyasio.cpp)
if(YASIO_ENABLE_AXLUA)
list(APPEND YASIO_SOURCES yasio/bindings/yasio_axlua.cpp)
endif()
endif()

if(ANDROID AND CARES_INCLUDE_DIR)
set(YASIO_CORE ${YASIO_CORE}
yasio/platform/yasio_jni.cpp
)
list(APPEND YASIO_SOURCES yasio/platform/yasio_jni.cpp)
endif()

if(WIN32 AND YASIO_ENABLE_HPERF_IO)
set(THIRDPART_SRC 3rdparty/wepoll/wepoll.c)
list(APPEND YASIO_SOURCES 3rdparty/wepoll/wepoll.c)
endif()

if(YASIO_ENABLE_KCP)
Expand All @@ -267,55 +259,30 @@ macro(source_group_by_dir proj_dir source_files)
endif(MSVC OR APPLE)
endmacro(source_group_by_dir)

source_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} YASIO_CORE)
source_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} YASIO_SOURCES)

# --- add yasio core lib project
if (APPLE)
if (IOS)
# set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)")
add_library(${yasio_target_name} STATIC
${YASIO_CORE}
${THIRDPART_SRC}
)
add_library(${yasio_target_name} STATIC ${YASIO_SOURCES})
else ()
# set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_64_BIT)")
if (BUILD_SHARED_LIBS)
add_library(${yasio_target_name} MODULE
${YASIO_CORE}
${THIRDPART_SRC}
)
add_library(${yasio_target_name} MODULE ${YASIO_SOURCES})
set_target_properties (${yasio_target_name} PROPERTIES BUNDLE TRUE )
else()
add_library(${yasio_target_name} STATIC
${YASIO_CORE}
${THIRDPART_SRC}
)
add_library(${yasio_target_name} STATIC ${YASIO_SOURCES})
endif()
endif ()
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Switch")
add_library(${yasio_target_name} STATIC
${YASIO_CORE}
${THIRDPART_SRC}
)
add_library(${yasio_target_name} STATIC ${YASIO_SOURCES})
target_compile_options(${yasio_target_name} PRIVATE -m64 -mcpu=cortex-a57+fp+simd+crypto+crc -fno-common -fno-short-enums -ffunction-sections -fdata-sections -fPIC -fms-extensions)
else ( ) # linux/win32/android
add_library(${yasio_target_name}
${YASIO_CORE}
${THIRDPART_SRC}
)
add_library(${yasio_target_name} ${YASIO_SOURCES})
endif ( )

if ( WIN32 )
target_link_libraries(${yasio_target_name}
ws2_32
${THIRDPART_LIB}
)
else ( )
target_link_libraries(${yasio_target_name}
m
${THIRDPART_LIB}
)
endif ( )
target_link_libraries(${yasio_target_name} ${YASIO_EXTERN_LIBS})

message(STATUS "YASIO_INC_DIRS=${YASIO_INC_DIRS}")
target_include_directories(${yasio_target_name} PUBLIC ${YASIO_INC_DIRS})
Expand Down Expand Up @@ -426,7 +393,7 @@ if(YASIO_ENABLE_LUA)
endif()
endif()

# link libraries for yasio_core when BUILD_SHARED_LIBS=TRUE
# link libraries for yasio_SOURCES when BUILD_SHARED_LIBS=TRUE
yasio_link_ssl_libraries(${yasio_target_name})
if(BUILD_SHARED_LIBS)
if(NOT WIN32 AND (NOT ANDROID))
Expand Down
10 changes: 5 additions & 5 deletions yasio/impl/eventfd_select_interrupter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8)
# include <asm/unistd.h>
#else // __GLIBC__ == 2 && __GLIBC_MINOR__ < 8
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) && !defined(__UCLIBC__)
# include <asm/unistd.h> // for syscall without API: eventfd
#else
# include <sys/eventfd.h>
#endif // __GLIBC__ == 2 && __GLIBC_MINOR__ < 8
#endif

#include <unistd.h>

Expand Down Expand Up @@ -105,7 +105,7 @@ class eventfd_select_interrupter {
// Open the descriptors. Throws on error.
inline void open_descriptors()
{
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8)
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) && !defined(__UCLIBC__)
write_descriptor_ = read_descriptor_ = syscall(__NR_eventfd, 0);
if (read_descriptor_ != -1)
{
Expand Down
3 changes: 3 additions & 0 deletions yasio/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ inline void yasio__print(std::string&& message) { ::write(::fileno(stdout), mess
# include <android/log.h>
# include <jni.h>
# define YASIO_LOG_TAG(tag, format, ...) __android_log_print(ANDROID_LOG_INFO, "yasio", (tag format), ##__VA_ARGS__)
#elif defined(__OHOS__)
# include <hilog/log.h>
# define YASIO_LOG_TAG(tag, format, ...) OH_LOG_INFO(LOG_APP, (tag format "\n"), ##__VA_ARGS__)
#else
# define YASIO_LOG_TAG(tag, format, ...) printf((tag format "\n"), ##__VA_ARGS__)
#endif
Expand Down

0 comments on commit 54a0c13

Please sign in to comment.