aboutsummaryrefslogtreecommitdiff
path: root/xW/CMakeLists.txt
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-07-09 07:06:19 +0200
committerPřemysl Eric Janouch <p@janouch.name>2023-07-15 17:00:21 +0200
commit0219dbd02615498f4a931e33ef2337e0bbf9b526 (patch)
treeb80e489614dcec83b8600534b5701b742d524ee4 /xW/CMakeLists.txt
parent1da4699a7afb0085c498196bf41fef6b69168a6f (diff)
downloadxK-0219dbd02615498f4a931e33ef2337e0bbf9b526.tar.gz
xK-0219dbd02615498f4a931e33ef2337e0bbf9b526.tar.xz
xK-0219dbd02615498f4a931e33ef2337e0bbf9b526.zip
Add a Win32 frontend for xC
This has been more of an exercise. The performance of Msftedit.dll is rather abysmal, and its interface isn't the most accomodating. That said, the frontend is quite usable, at least on Windows 10+.
Diffstat (limited to 'xW/CMakeLists.txt')
-rw-r--r--xW/CMakeLists.txt97
1 files changed, 97 insertions, 0 deletions
diff --git a/xW/CMakeLists.txt b/xW/CMakeLists.txt
new file mode 100644
index 0000000..eb374b9
--- /dev/null
+++ b/xW/CMakeLists.txt
@@ -0,0 +1,97 @@
+# 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>")
+
+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 pngs ico)
+ find_program (icotool_EXECUTABLE icotool ${find_program_REQUIRE})
+ add_custom_command (OUTPUT ${ico}
+ COMMAND ${icotool_EXECUTABLE} -c -o ${ico} ${pngs}
+ DEPENDS ${pngs}
+ 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 256)
+ 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 ()
+ set (icon_ico ${PROJECT_BINARY_DIR}/${icon}.ico)
+ icon_for_win32 ("${icon_png_list}" ${icon_ico})
+ 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)