Skip to content

Commit

Permalink
fixes #292 - fix android termux build of whatsapp
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Sep 7, 2024
1 parent f55d9a4 commit 71fc941
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/common/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#pragma once

#define NCHAT_VERSION "5.2.7"
#define NCHAT_VERSION "5.2.8"
38 changes: 24 additions & 14 deletions lib/wmchat/go/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
9 changes: 5 additions & 4 deletions lib/wmchat/go/gowm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/nchat.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 71fc941

Please sign in to comment.