adapt for macos.

This commit is contained in:
amass 2025-01-23 10:29:45 +08:00
parent 9af561dc10
commit 688f5da3e3
11 changed files with 62 additions and 24 deletions

View File

@ -25,6 +25,12 @@ if(INDEPENDENT_BUILD)
set(OPENSSL_INCLUDE_DIR ${OpenSSL_ROOT}/include) set(OPENSSL_INCLUDE_DIR ${OpenSSL_ROOT}/include)
set(OpenSSL_LIBRARY_DIRS ${OpenSSL_ROOT}/lib) set(OpenSSL_LIBRARY_DIRS ${OpenSSL_ROOT}/lib)
set(OpenSSL_LIBRARIES libssl libcrypto) set(OpenSSL_LIBRARIES libssl libcrypto)
elseif(APPLE)
set(Libraries_ROOT /opt/Libraries)
set(MbedTLS_DIR ${Libraries_ROOT}/mbedtls-3.6.2/lib/cmake/MbedTLS)
set(nng_DIR ${Libraries_ROOT}/nng-1.10/lib/cmake/nng)
set(OpenSSL_ROOT /opt/homebrew/Cellar/openssl@3/3.4.0)
set(OPENSSL_INCLUDE_DIR ${OpenSSL_ROOT}/include)
else() else()
execute_process( execute_process(
COMMAND sh -c "echo $HOME" COMMAND sh -c "echo $HOME"
@ -36,13 +42,8 @@ if(INDEPENDENT_BUILD)
set(BOOST_ROOT ${Libraries_ROOT}/boost_1_86_0) set(BOOST_ROOT ${Libraries_ROOT}/boost_1_86_0)
set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include) set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include)
set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2) set(MbedTLS_DIR ${Libraries_ROOT}/mbedtls-3.6.2/lib/cmake/MbedTLS)
set(MBEDTLS_INCLUDE_DIR ${MBEDTLS_ROOT}/include) set(nng_DIR ${Libraries_ROOT}/nng-1.10/lib/cmake/nng)
set(MBEDTLS_LIBRARY_DIRS ${MBEDTLS_ROOT}/lib)
set(NNG_ROOT ${Libraries_ROOT}/nng-1.9.0)
set(NNG_INCLUDE_DIR ${NNG_ROOT}/include)
set(NNG_LIBRARY_DIRS ${NNG_ROOT}/lib)
endif() endif()
option(Boost_USE_STATIC_LIBS OFF) option(Boost_USE_STATIC_LIBS OFF)

View File

@ -1,9 +1,14 @@
if(APPLE)
find_library(CARBON_LIBRARY Carbon)
mark_as_advanced(CARBON_LIBRARY)
endif()
add_library(QHotkey add_library(QHotkey
qhotkey.h qhotkey.cpp qhotkey.h qhotkey.cpp
qhotkey_p.h qhotkey_p.h
$<$<PLATFORM_ID:Windows>:qhotkey_win.cpp> $<$<PLATFORM_ID:Windows>:qhotkey_win.cpp>
$<$<PLATFORM_ID:Linux>:qhotkey_x11.cpp> $<$<PLATFORM_ID:Linux>:qhotkey_x11.cpp>
$<$<PLATFORM_ID:Darwin>:qhotkey_mac.cpp>
) )
target_include_directories(QHotkey target_include_directories(QHotkey
@ -13,4 +18,5 @@ target_include_directories(QHotkey
target_link_libraries(QHotkey target_link_libraries(QHotkey
PUBLIC Qt${QT_VERSION_MAJOR}::Gui PUBLIC Qt${QT_VERSION_MAJOR}::Gui
$<$<PLATFORM_ID:Linux>:X11> $<$<PLATFORM_ID:Linux>:X11>
$<$<PLATFORM_ID:Darwin>:${CARBON_LIBRARY}>
) )

View File

@ -29,6 +29,7 @@ std::string Https::put(boost::asio::io_context &ioContext, const std::string &ho
return client.put(host, port, url, body, error); return client.put(host, port, url, body, error);
} }
#ifndef __APPLE__
uint64_t Network::htonll(uint64_t val) { uint64_t Network::htonll(uint64_t val) {
return (static_cast<uint64_t>(htonl(static_cast<uint32_t>(val))) << 32) + htonl(val >> 32); return (static_cast<uint64_t>(htonl(static_cast<uint32_t>(val))) << 32) + htonl(val >> 32);
} }
@ -36,6 +37,7 @@ uint64_t Network::htonll(uint64_t val) {
uint64_t Network::ntohll(uint64_t val) { uint64_t Network::ntohll(uint64_t val) {
return (static_cast<uint64_t>(ntohl(static_cast<uint32_t>(val))) << 32) + ntohl(val >> 32); return (static_cast<uint64_t>(ntohl(static_cast<uint32_t>(val))) << 32) + ntohl(val >> 32);
} }
#endif
bool Network::isConnected(const std::string_view &host, size_t size) { bool Network::isConnected(const std::string_view &host, size_t size) {
std::ostringstream oss; std::ostringstream oss;

View File

@ -21,8 +21,10 @@ class Network {
public: public:
static bool isConnected(const std::string_view &host, size_t size); static bool isConnected(const std::string_view &host, size_t size);
#ifndef __APPLE__
static uint64_t htonll(uint64_t val); static uint64_t htonll(uint64_t val);
static uint64_t ntohll(uint64_t val); static uint64_t ntohll(uint64_t val);
#endif
protected: protected:
Network(int argc, char *argv[]); Network(int argc, char *argv[]);

View File

@ -3,6 +3,7 @@
#include <cstdint> #include <cstdint>
#include <nng/nng.h> #include <nng/nng.h>
#include <cstddef>
namespace Nng { namespace Nng {

View File

@ -10,7 +10,8 @@ BOOST_AUTO_TEST_CASE(HelloWorld) {
reply.listen("tcp://localhost:8000"); reply.listen("tcp://localhost:8000");
Socket request(Request); Socket request(Request);
request.dial("tcp://localhost:8000"); std::error_code error;
request.dial("tcp://localhost:8000", error);
request.send((void *)"hello", strlen("hello") + 1); request.send((void *)"hello", strlen("hello") + 1);
auto buffer = reply.recv(); auto buffer = reply.recv();
@ -35,7 +36,8 @@ BOOST_AUTO_TEST_CASE(AisoHelloWorld) {
request.asyncReceive([&request](const boost::system::error_code &error, const Buffer &buffer) { request.asyncReceive([&request](const boost::system::error_code &error, const Buffer &buffer) {
BOOST_CHECK_EQUAL(buffer.data<char>(), std::string_view("world")); BOOST_CHECK_EQUAL(buffer.data<char>(), std::string_view("world"));
}); });
request.dial("tcp://localhost:8000"); std::error_code error;
request.dial("tcp://localhost:8000", error);
request.send((void *)"hello", strlen("hello") + 1); request.send((void *)"hello", strlen("hello") + 1);
ioContext.run(); ioContext.run();
} }

View File

@ -30,11 +30,13 @@ BOOST_AUTO_TEST_CASE(FunctionTraitsNormalFunctionTest) {
m.registerTopic("123", [&t](int a, int b) { return t.test(a, b); }); m.registerTopic("123", [&t](int a, int b) { return t.test(a, b); });
BOOST_CHECK_EQUAL(m.topicCount<int(int, int)>("123"), 1); BOOST_CHECK_EQUAL(m.topicCount<int(int, int)>("123"), 1);
#ifndef __APPLE__
m.registerTopic("123", std::bind(&Test::test, &t, _1, _2)); m.registerTopic("123", std::bind(&Test::test, &t, _1, _2));
BOOST_CHECK_EQUAL(m.topicCount<int(int, int)>("123"), 2); BOOST_CHECK_EQUAL(m.topicCount<int(int, int)>("123"), 2);
m.registerTopic("123", &test); m.registerTopic("123", &test);
BOOST_CHECK_EQUAL(m.topicCount<int(int, int)>("123"), 3); BOOST_CHECK_EQUAL(m.topicCount<int(int, int)>("123"), 3);
#endif
m.removeTopic<int(int, int)>("123"); m.removeTopic<int(int, int)>("123");
BOOST_CHECK_EQUAL(m.topicCount<int(int, int)>("123"), 0); BOOST_CHECK_EQUAL(m.topicCount<int(int, int)>("123"), 0);
@ -70,10 +72,12 @@ BOOST_AUTO_TEST_CASE(SyncMessage) {
return 0; return 0;
}); });
Test t; Test t;
#ifndef __APPLE__
manager.registerTopic("123", std::bind(&Test::test, &t, _1, _2)); manager.registerTopic("123", std::bind(&Test::test, &t, _1, _2));
manager.sendMessage("123", 12, 13); manager.sendMessage("123", 12, 13);
BOOST_CHECK_EQUAL(result3, 25); BOOST_CHECK_EQUAL(result3, 25);
BOOST_CHECK_EQUAL(t.result, 28); BOOST_CHECK_EQUAL(t.result, 28);
#endif
int result4 = 0; int result4 = 0;
manager.registerTopic("123", [&result4]() { manager.registerTopic("123", [&result4]() {

View File

@ -30,6 +30,12 @@ else()
cmake_path(GET CMAKE_CURRENT_SOURCE_DIR PARENT_PATH KYLIN_CORE_INCLUDE_PATH) cmake_path(GET CMAKE_CURRENT_SOURCE_DIR PARENT_PATH KYLIN_CORE_INCLUDE_PATH)
endif() endif()
if(APPLE)
target_compile_definitions(Universal
PUBLIC BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED
)
endif()
if(DISABLE_LOG) if(DISABLE_LOG)
target_compile_definitions(Universal target_compile_definitions(Universal
PUBLIC DISABLE_LOG PUBLIC DISABLE_LOG

View File

@ -56,7 +56,7 @@ bool DockerUtility::running(std::string_view container, std::error_code &error)
std::string NativeUtility::currentExecutable() { std::string NativeUtility::currentExecutable() {
// win32 GetModuleFileNameA // win32 GetModuleFileNameA
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
char buffer[512] = {0}; char buffer[512] = {0};
auto status = readlink("/proc/self/exe", buffer, sizeof(buffer)); auto status = readlink("/proc/self/exe", buffer, sizeof(buffer));
return status == -1 ? std::string() : std::string(buffer); return status == -1 ? std::string() : std::string(buffer);
@ -69,7 +69,7 @@ std::string NativeUtility::currentExecutable() {
std::string NativeUtility::executableDirectory() { std::string NativeUtility::executableDirectory() {
auto path = currentExecutable(); auto path = currentExecutable();
#ifdef __linux__ #if defined(__linux__) || defined(__APPLE__)
auto slashPos = path.find_last_of("/"); auto slashPos = path.find_last_of("/");
#else #else
auto slashPos = path.find_last_of("\\"); auto slashPos = path.find_last_of("\\");

View File

@ -5,10 +5,12 @@
#include "ProcessUtility.h" #include "ProcessUtility.h"
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <boost/process.hpp> #include <boost/process.hpp>
#if (defined __arm__) || (defined __aarch64__) #if __cplusplus >= 201703L
#include <filesystem>
#elif __cplusplus >= 201402L && defined(__GNUC__)
#include <experimental/filesystem> #include <experimental/filesystem>
#else #else
#include <filesystem> #error "C++14 or later is required"
#endif #endif
template <typename... Args> template <typename... Args>
@ -23,10 +25,12 @@ void DockerUtility::runScript(std::string_view container, const std::string &scr
template <typename... Args> template <typename... Args>
void NativeUtility::runScript(const std::string &script, Args &&...scriptArgs) { void NativeUtility::runScript(const std::string &script, Args &&...scriptArgs) {
#if (defined __arm__) || (defined __aarch64__) #if __cplusplus >= 201703L
using namespace std::experimental; using namespace std;
#elif __cplusplus >= 201402L && defined(__GNUC__)
using namespace std::experimental;
#else #else
using namespace std; #error "C++14 or later is required"
#endif #endif
#if defined(WIN32) || defined(ANDROID) #if defined(WIN32) || defined(ANDROID)

View File

@ -1,15 +1,25 @@
#!/bin/bash #!/bin/bash
base_path=$(pwd) base_path=$(pwd)
qt_prefix_path="/opt/Qt/6.8.0/gcc_64" build_path=${base_path}/build
libraries_root="/opt/Libraries" qt_prefix_path="/opt/Qt/6.8.1/gcc_64"
if [ $base_path == /home/* ]; then if [[ $(uname) == "Darwin" ]]; then
build_path=${base_path}/build qt_prefix_path="/Users/amass/Qt/6.8.1/macos"
else else
build_path=/tmp/build if [[ "$base_path" != /home/* ]]; then
build_path=/tmp/build
fi
fi fi
libraries_root="/opt/Libraries"
echo "build directory: $build_path" echo "build directory: $build_path"
if command -v cmake >/dev/null 2>&1; then
cmake_exe=cmake
else
cmake_exe=/opt/Qt/Tools/CMake/bin/cmake
fi
if [ -d ${qt_prefix_path} ]; then # 先找Qt6 if [ -d ${qt_prefix_path} ]; then # 先找Qt6
cmake_qt_parameters="-DCMAKE_PREFIX_PATH=${qt_prefix_path} \ cmake_qt_parameters="-DCMAKE_PREFIX_PATH=${qt_prefix_path} \
-DQT_QMAKE_EXECUTABLE=${qt_prefix_path}/bin/qmake \ -DQT_QMAKE_EXECUTABLE=${qt_prefix_path}/bin/qmake \
@ -42,7 +52,7 @@ function cmake_scan() {
if [ ! -d ${build_path} ]; then if [ ! -d ${build_path} ]; then
mkdir ${build_path} mkdir ${build_path}
fi fi
/opt/Qt/Tools/CMake/bin/cmake \ ${cmake_exe} \
-G Ninja \ -G Ninja \
-S ${base_path} \ -S ${base_path} \
-B ${build_path} \ -B ${build_path} \
@ -62,7 +72,7 @@ function build() {
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
/opt/Qt/Tools/CMake/bin/cmake \ ${cmake_exe} \
--build ${build_path} \ --build ${build_path} \
--target all --target all
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then