blob: 2a8b2b9f97b1615050b3c7750009683258da2215 (
plain)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
cmake_minimum_required(VERSION 3.0)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.15")
# this is for MSVC_RUNTIME_LIBRARY property below
cmake_policy(SET CMP0091 NEW)
endif()
project(vdagent-win)
# configure
file(WRITE "${CMAKE_BINARY_DIR}/config.h.in" "/* Automatic generated by CMake */\n\n")
macro(config_write str)
file(APPEND "${CMAKE_BINARY_DIR}/config.h.in" "${str}")
endmacro()
string(TIMESTAMP BUILD_YEAR "%Y")
config_write("#define BUILD_YEAR \"${BUILD_YEAR}\"\n")
if(EXISTS "${CMAKE_SOURCE_DIR}/.tarball-version")
file(STRINGS "${CMAKE_SOURCE_DIR}/.tarball-version" VER)
list(GET VER 0 VER)
set(VER "v${VER}")
else()
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --abbrev=4 --match=v* HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE VER
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
message(FATAL_ERROR "GIT not found")
endif()
endif()
if("${VER}" MATCHES "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)")
set(RC_PRODUCTVERSION "${CMAKE_MATCH_1}, ${CMAKE_MATCH_2}, ${CMAKE_MATCH_3}, 0")
else()
message(FATAL_ERROR "wrong VERSION format ${VER}")
endif()
config_write("#define RC_PRODUCTVERSION ${RC_PRODUCTVERSION}\n")
config_write("#define RC_PRODUCTVERSION_STR \"${RC_PRODUCTVERSION}\"\n")
configure_file(${CMAKE_BINARY_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
if(MSVC)
if(${CMAKE_VERSION} VERSION_LESS "3.15")
# compile MSVCRT into executable (link it statically)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif()
# generate PDB files
# see https://stackoverflow.com/questions/28178978/how-to-generate-pdb-files-for-release-build-with-cmake-flags/31264946
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF" CACHE STRING "" FORCE)
# find using vcpkg packages
find_package(libpng CONFIG REQUIRED)
find_path(PNG_INCLUDE_DIR NAMES png.h)
set(PNG_LIBRARY png_static)
set(ZLIB_LIBRARY)
set(COMMSUPPW_LIBRARY comsuppw)
else(MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -s")
find_package(PNG REQUIRED)
set(COMMSUPPW_LIBRARY)
endif(MSVC)
include_directories(common ${CMAKE_BINARY_DIR} spice-protocol spice-common ${PNG_INCLUDE_DIR})
add_definitions(-DUNICODE -D_UNICODE -DOLDMSVCRT -DWINVER=0x0601)
add_executable(vdagent WIN32
common/vdcommon.cpp
common/vdcommon.h
common/vdlog.cpp
common/vdlog.h
vdagent/display_configuration.cpp
vdagent/display_configuration.h
vdagent/desktop_layout.cpp
vdagent/desktop_layout.h
vdagent/display_setting.cpp
vdagent/display_setting.h
vdagent/file_xfer.cpp
vdagent/file_xfer.h
vdagent/vdagent.cpp
spice-common/common/agent.c
vdagent/as_user.cpp
vdagent/as_user.h
vdagent/image.cpp
vdagent/image.h
vdagent/imagepng.cpp
vdagent/imagepng.h
vdagent/shell.cpp
vdagent/shell.h
vdagent/vdagent.rc
)
target_link_libraries(vdagent
${PNG_LIBRARY}
${ZLIB_LIBRARY}
wtsapi32
uuid
ole32
oleaut32
${COMMSUPPW_LIBRARY}
)
add_executable(vdservice
common/stdint.h
common/vdcommon.cpp
common/vdcommon.h
common/vdlog.cpp
common/vdlog.h
vdservice/vdservice.cpp
vdservice/vdservice.rc
)
target_link_libraries(vdservice
wtsapi32
)
enable_testing()
add_custom_target(check COMMAND ctest -C $<CONFIG>)
if(CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING_EMULATOR wine)
endif()
add_executable(imagetest EXCLUDE_FROM_ALL
common/vdcommon.cpp
common/vdcommon.h
common/vdlog.cpp
common/vdlog.h
vdagent/imagetest.cpp
vdagent/image.cpp
vdagent/image.h
vdagent/imagepng.cpp
vdagent/imagepng.h
)
target_link_libraries(imagetest
${PNG_LIBRARY}
${ZLIB_LIBRARY}
wtsapi32
)
add_test(NAME test-png COMMAND bash "${CMAKE_SOURCE_DIR}/test-png")
add_executable(test-log EXCLUDE_FROM_ALL
common/vdcommon.cpp
common/vdcommon.h
common/vdlog.cpp
common/vdlog.h
common/test-log.cpp
)
add_test(NAME test-log COMMAND test-log)
add_executable(test-shell EXCLUDE_FROM_ALL
vdagent/test-shell.cpp
)
target_link_libraries(test-shell
uuid
ole32
oleaut32
${COMMSUPPW_LIBRARY}
)
add_test(NAME test-shell COMMAND test-shell)
add_dependencies(check test-log test-shell imagetest)
if(MSVC)
# select static CRT without debugging (/MT option)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.15")
set_property(TARGET vdagent vdservice imagetest
PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded")
endif()
endif()
install(TARGETS vdagent vdservice)
|