From 71fc9418dc0de683e8038afab173bd0d866e1011 Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Sat, 7 Sep 2024 17:21:23 +0800 Subject: [PATCH] fixes #292 - fix android termux build of whatsapp --- CMakeLists.txt | 4 ++++ lib/common/src/version.h | 2 +- lib/wmchat/go/CMakeLists.txt | 38 +++++++++++++++++++++++------------- lib/wmchat/go/gowm.go | 9 +++++---- src/nchat.1 | 2 +- 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c648f231..acb44d98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,10 @@ message(STATUS "Multi Protocol: ${HAS_MULTIPROTOCOL}") option(HAS_COREDUMP "Core Dump" ON) message(STATUS "Core Dump: ${HAS_COREDUMP}") +# Feature - Static Go library +option(HAS_STATICGOLIB "Static Go" ON) +message(STATUS "Static Go: ${HAS_STATICGOLIB}") + # Check Golang version for whatsmeow minimum requirement set(GO_VERSION_MIN 1.21) execute_process(COMMAND bash "-c" "go version 2> /dev/null | cut -c14- | cut -d' ' -f1 | tr -d '\n'" OUTPUT_VARIABLE GO_VERSION) diff --git a/lib/common/src/version.h b/lib/common/src/version.h index 0c6b86c7..890b5622 100644 --- a/lib/common/src/version.h +++ b/lib/common/src/version.h @@ -7,4 +7,4 @@ #pragma once -#define NCHAT_VERSION "5.2.7" +#define NCHAT_VERSION "5.2.8" diff --git a/lib/wmchat/go/CMakeLists.txt b/lib/wmchat/go/CMakeLists.txt index de4d220c..170f1a8c 100644 --- a/lib/wmchat/go/CMakeLists.txt +++ b/lib/wmchat/go/CMakeLists.txt @@ -4,13 +4,8 @@ project(libcgowm) # Check Golang version execute_process(COMMAND bash "-c" "go version | cut -c14- | cut -d' ' -f1 | tr -d '\n'" OUTPUT_VARIABLE GO_VERSION) -if (GO_VERSION VERSION_GREATER_EQUAL 1.16.0) - message(STATUS "Go version ${GO_VERSION} (enable modcacherw).") - SET(CUSTOM_GO_FLAGS -modcacherw -mod=mod) # @todo: remove -mod=mod eventually, see https://github.com/golang/go/issues/44129 -else () - message(STATUS "Go version ${GO_VERSION}.") - SET(CUSTOM_GO_FLAGS "") -endif () +message(STATUS "Go version ${GO_VERSION}.") +set(CUSTOM_GO_FLAGS -modcacherw) # Check Go package execute_process(COMMAND bash "-c" "go version | grep -v -q gccgo" RESULT_VARIABLE GO_GCC) @@ -22,24 +17,39 @@ else () set(GO_LIBRARIES "" PARENT_SCOPE) endif () +# Config params +if (HAS_STATICGOLIB) + set(BUILDMODE c-archive) + set(OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) +else() + set(BUILDMODE c-shared) + set(OUTPUT_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) +endif() + # Build Go library / C archive set(TARGET cgowm) -set(GOPATH ${CMAKE_CURRENT_BINARY_DIR}) +set(GOPATH ${OUTPUT_DIR}) set(SRCS gowm.go cgowm.go) set(LIB "libcgowm${CMAKE_SHARED_LIBRARY_SUFFIX}") -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LIB} +add_custom_command(OUTPUT ${OUTPUT_DIR}/${LIB} DEPENDS ${SRCS} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND env GOPATH=${GOPATH} CGO_ENABLED=1 go build -buildmode=c-archive ${CUSTOM_GO_FLAGS} - -o "${CMAKE_CURRENT_BINARY_DIR}/${LIB}" + COMMAND env GOPATH=${GOPATH} CGO_ENABLED=1 go build -buildmode=${BUILDMODE} ${CUSTOM_GO_FLAGS} + -o "${OUTPUT_DIR}/${LIB}" ${CMAKE_GO_FLAGS} ./... COMMENT "Building Go library") -add_custom_target(${TARGET} DEPENDS ${LIB} ${HEADER}) +add_custom_target(${TARGET} DEPENDS ${OUTPUT_DIR}/${LIB} ${HEADER}) # Build shared library add_library(ref-cgowm SHARED IMPORTED GLOBAL) add_dependencies(ref-cgowm ${TARGET}) set_target_properties(ref-cgowm PROPERTIES - IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${LIB} - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) + IMPORTED_NO_SONAME TRUE + IMPORTED_LOCATION ${OUTPUT_DIR}/${LIB} + INTERFACE_INCLUDE_DIRECTORIES ${OUTPUT_DIR}) + +# Install +if (NOT HAS_STATICGOLIB) + install(FILES ${OUTPUT_DIR}/${LIB} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() diff --git a/lib/wmchat/go/gowm.go b/lib/wmchat/go/gowm.go index 2ce2b896..6bf494b9 100644 --- a/lib/wmchat/go/gowm.go +++ b/lib/wmchat/go/gowm.go @@ -327,7 +327,7 @@ func ShowImage(path string) { LOG_DEBUG("open " + path) exec.Command("open", path).Start() default: - LOG_WARNING("unsupported os") + LOG_WARNING(fmt.Sprintf("unsupported os \"%s\"", runtime.GOOS)) } } @@ -392,9 +392,9 @@ func HasGUI() bool { } default: - LOG_INFO(fmt.Sprintf("has gui")) - LOG_DEBUG(fmt.Sprintf("gui check: [other default true]")) - return true + LOG_INFO(fmt.Sprintf("no gui")) + LOG_DEBUG(fmt.Sprintf("gui check: [other \"%s\" default false]", runtime.GOOS)) + return false } } @@ -1745,6 +1745,7 @@ func WmInit(path string, proxy string, sendType int) int { case "darwin": store.DeviceProps.Os = proto.String("Mac OS") default: + store.DeviceProps.Os = proto.String("Linux") } // create new whatsapp connection diff --git a/src/nchat.1 b/src/nchat.1 index 01a39598..d64aefdc 100644 --- a/src/nchat.1 +++ b/src/nchat.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH NCHAT "1" "September 2024" "nchat 5.2.7" "User Commands" +.TH NCHAT "1" "September 2024" "nchat 5.2.8" "User Commands" .SH NAME nchat \- ncurses chat .SH SYNOPSIS