aboutsummaryrefslogtreecommitdiff
path: root/xW/CMakeLists.txt
blob: 7af0e316bb438bdc02c57facfbe6fc6d8b54b51c (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
# The last version with Windows XP support is 3.13, we want to keep that
cmake_minimum_required (VERSION 3.10)

file (READ ../xK-version project_version)
configure_file (../xK-version xK-version.tag COPYONLY)
string (STRIP "${project_version}" project_version)

# This is an entirely separate CMake project--the main executables only build
# on Windows within Cygwin, and this Windows executable only builds on Linux
# cross-compiled, so you'd want to build them independently anyway.
project (xW VERSION "${project_version}"
	DESCRIPTION "Win32 frontend for xC" LANGUAGES CXX)

set (CMAKE_CXX_STANDARD 17)

add_definitions (-DUNICODE -D_UNICODE)
add_compile_options ("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options ("$<$<CXX_COMPILER_ID:GNU>:-Wall;-Wextra>")
add_compile_options ("$<$<CXX_COMPILER_ID:Clang>:-Wall;-Wextra>")
add_link_options ("$<$<CXX_COMPILER_ID:GNU>:-static;-municode>")
add_link_options ("$<$<CXX_COMPILER_ID:Clang>:-static;-municode>")

set (project_config ${PROJECT_BINARY_DIR}/config.h)
configure_file (${PROJECT_SOURCE_DIR}/config.h.in ${project_config})
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})

# Icon generation utilities
# TODO: Shove this into liberty as a CMake module, similar to AddThreads,
# and remove the copies in the parent CMakeLists.txt as well as in tdv.
if (NOT ${CMAKE_VERSION} VERSION_LESS 3.18.0)
	set (find_program_REQUIRE REQUIRED)
endif ()

function (icon_to_png name svg size output_dir output)
	set (_dimensions ${size}x${size})
	set (_png_path ${output_dir}/hicolor/${_dimensions}/apps)
	set (_png ${_png_path}/${name}.png)
	set (${output} ${_png} PARENT_SCOPE)

	find_program (rsvg_convert_EXECUTABLE rsvg-convert ${find_program_REQUIRE})
	add_custom_command (OUTPUT ${_png}
		COMMAND ${CMAKE_COMMAND} -E make_directory ${_png_path}
		COMMAND ${rsvg_convert_EXECUTABLE} --output=${_png}
			--width=${size} --height=${size} ${svg}
		DEPENDS ${svg}
		COMMENT "Generating ${name} ${_dimensions} application icon" VERBATIM)
endfunction ()

function (icon_for_win32 ico pngs pngs_raw)
	set (_raws)
	foreach (png ${pngs_raw})
		list (APPEND _raws "--raw=${png}")
	endforeach ()

	find_program (icotool_EXECUTABLE icotool ${find_program_REQUIRE})
	add_custom_command (OUTPUT ${ico}
		COMMAND ${icotool_EXECUTABLE} -c -o ${ico} ${_raws} -- ${pngs}
		DEPENDS ${pngs} ${pngs_raw}
		COMMENT "Generating Windows program icon" VERBATIM)
endfunction ()

# Rasterize SVG icons
set (icon_ico_list)
foreach (icon xW xW-highlighted)
	set (icon_png_list)
	foreach (icon_size 16 32 48)
		icon_to_png (${icon} ${PROJECT_SOURCE_DIR}/${icon}.svg
			${icon_size} ${PROJECT_BINARY_DIR}/icons icon_png)
		list (APPEND icon_png_list ${icon_png})
	endforeach ()
	icon_to_png (${icon} ${PROJECT_SOURCE_DIR}/${icon}.svg
		256 ${PROJECT_BINARY_DIR}/icons icon_png)

	set (icon_ico ${PROJECT_BINARY_DIR}/${icon}.ico)
	icon_for_win32 (${icon_ico} "${icon_png_list}" "${icon_png}")
	list (APPEND icon_ico_list ${icon_ico})
endforeach ()

set_property (SOURCE xW.rc APPEND PROPERTY OBJECT_DEPENDS ${icon_ico_list})

# Build the main executable and link it
set (root "${PROJECT_SOURCE_DIR}/..")

find_program (awk_EXECUTABLE awk ${find_program_REQUIRE})
add_custom_command (OUTPUT xC-proto.cpp
	COMMAND ${CMAKE_COMMAND} -E env LC_ALL=C ${awk_EXECUTABLE}
		-f ${root}/liberty/tools/lxdrgen.awk
		-f ${root}/liberty/tools/lxdrgen-cpp.awk
		-v PrefixCamel=Relay
		${root}/xC.lxdr > xC-proto.cpp
	DEPENDS
		${root}/liberty/tools/lxdrgen.awk
		${root}/liberty/tools/lxdrgen-cpp.awk
		${root}/xC.lxdr
	COMMENT "Generating xC relay protocol code" VERBATIM)
add_custom_target (xC-proto DEPENDS ${PROJECT_BINARY_DIR}/xC-proto.cpp)

add_executable (xW WIN32 xW.cpp xW.rc xW.manifest ${project_config}
	${root}/liberty/tools/lxdrgen-cpp-win32.cpp)
target_link_libraries (xW comctl32 ws2_32)
add_dependencies (xW xC-proto)

# At least with MinGW, this is a fully independent portable executable
install (TARGETS xW DESTINATION .)
set (CPACK_GENERATOR ZIP)
include (CPack)