-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
135 lines (114 loc) · 3.69 KB
/
Copy pathCMakeLists.txt
File metadata and controls
135 lines (114 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
cmake_minimum_required(VERSION 3.16)
project(NanaonanApp VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Qt6 Configuration
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# Static Compilation Configuration
# For MSVC: Uses static runtime
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# For GCC/Clang: Static linking flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
# Full static link (requires static Qt build):
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
# Find Qt6
find_package(Qt6 REQUIRED COMPONENTS Widgets Gui Core Multimedia Quick Qml Sql)
# Include directories
include_directories(${CMAKE_SOURCE_DIR}/include)
# ============================================================================
# Go Whatsmeow Bridge Library
# ============================================================================
set(GO_BRIDGE_DIR ${CMAKE_SOURCE_DIR}/whatsmeow_bridge)
set(GO_BRIDGE_LIB ${CMAKE_BINARY_DIR}/libwabridge.so)
set(GO_BRIDGE_HEADER ${CMAKE_BINARY_DIR}/libwabridge.h)
# Custom command to build Go shared library
add_custom_command(
OUTPUT ${GO_BRIDGE_LIB} ${GO_BRIDGE_HEADER}
COMMAND ${CMAKE_COMMAND} -E env CGO_ENABLED=1
go build -buildmode=c-shared -o ${GO_BRIDGE_LIB} .
WORKING_DIRECTORY ${GO_BRIDGE_DIR}
DEPENDS ${GO_BRIDGE_DIR}/bridge.go ${GO_BRIDGE_DIR}/go.mod
COMMENT "Building Go whatsmeow bridge library..."
)
# Custom target for Go library
add_custom_target(wabridge_go
DEPENDS ${GO_BRIDGE_LIB}
)
# Import the Go shared library
add_library(wabridge SHARED IMPORTED)
set_target_properties(wabridge PROPERTIES
IMPORTED_LOCATION ${GO_BRIDGE_LIB}
)
add_dependencies(wabridge wabridge_go)
# Include the generated header directory
include_directories(${CMAKE_BINARY_DIR})
# ============================================================================
# Main Application
# ============================================================================
# Source files
set(SOURCES
src/main.cpp
src/wabridge.cpp
src/chatmodel.cpp
src/chatlistmodel.cpp
src/qmlbridge.cpp
src/messagedb.cpp
src/mediamanager.cpp
src/groupmodel.cpp
)
# Header files
set(HEADERS
include/types.h
include/wabridge.h
include/chatmodel.h
include/chatlistmodel.h
include/qmlbridge.h
include/qr_utils.h
include/messagedb.h
include/mediamanager.h
include/groupmodel.h
)
# Resource files (optional, for icons/media)
set(RESOURCES resources/resources.qrc)
# Create executable
add_executable(${PROJECT_NAME}
${SOURCES}
${HEADERS}
${RESOURCES}
)
# Ensure Go library is built before the main app
add_dependencies(${PROJECT_NAME} wabridge_go)
# Link Qt6 libraries and Go bridge
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt6::Widgets
Qt6::Gui
Qt6::Core
Qt6::Multimedia
Qt6::Quick
Qt6::Qml
Qt6::Sql
${GO_BRIDGE_LIB}
qrencode
)
# Set RPATH for the executable to find the Go library
set_target_properties(${PROJECT_NAME} PROPERTIES
BUILD_RPATH ${CMAKE_BINARY_DIR}
INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib
)
# Windows specific: hide console window for release builds
if(WIN32)
set_target_properties(${PROJECT_NAME} PROPERTIES
WIN32_EXECUTABLE TRUE
)
endif()
# ============================================================================
# Install targets
# ============================================================================
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES ${GO_BRIDGE_LIB} DESTINATION lib)