2020-01-10 17:58:41 +01:00
|
|
|
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
|
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
# generates and adds a Windows rc file for the application/library also attaches the application icon if ffmpeg is available
|
2016-04-16 00:50:16 +02:00
|
|
|
# does nothing if not building with mingw-w64
|
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
if (NOT BASIC_PROJECT_CONFIG_DONE)
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"Before including the WindowsResources module, the LibraryConfig/ApplicationConfig module must be included.")
|
|
|
|
endif ()
|
2016-04-16 00:50:16 +02:00
|
|
|
|
2018-02-21 23:00:32 +01:00
|
|
|
option(WINDOWS_RESOURCES_ENABLED "controls whether Windows resources are enabled" ON)
|
|
|
|
option(WINDOWS_ICON_ENABLED "controls whether Windows icon is enabled" ON)
|
2016-11-19 22:33:03 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
if (NOT MINGW OR NOT WINDOWS_RESOURCES_ENABLED)
|
2018-02-21 23:00:32 +01:00
|
|
|
return()
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2018-12-22 00:40:38 +01:00
|
|
|
# find rc template, define path of output rc file
|
2018-02-21 23:00:32 +01:00
|
|
|
include(TemplateFinder)
|
|
|
|
find_template_file("windows.rc" CPP_UTILITIES RC_TEMPLATE_FILE)
|
2023-05-06 22:48:27 +02:00
|
|
|
find_template_file("windows-cli-wrapper.rc" CPP_UTILITIES RC_CLI_TEMPLATE_FILE)
|
2020-07-04 15:21:20 +02:00
|
|
|
set(WINDOWS_RC_FILE "${CMAKE_CURRENT_BINARY_DIR}/resources/windows")
|
2023-05-06 22:48:27 +02:00
|
|
|
set(WINDOWS_CLI_RC_FILE "${CMAKE_CURRENT_BINARY_DIR}/resources/windows-cli-wrapper")
|
2016-04-16 00:50:16 +02:00
|
|
|
|
2018-02-21 23:00:32 +01:00
|
|
|
# create Windows icon from png with ffmpeg if available
|
|
|
|
unset(WINDOWS_ICON_RC_ENTRY)
|
2022-12-22 23:28:05 +01:00
|
|
|
if (WINDOWS_ICON_ENABLED)
|
|
|
|
if (NOT WINDOWS_ICON_PATH AND PNG_ICON_PATH)
|
|
|
|
find_program(FFMPEG_BIN ffmpeg avconv)
|
|
|
|
if (FFMPEG_BIN)
|
|
|
|
set(WINDOWS_ICON_PATH "${CMAKE_CURRENT_BINARY_DIR}/resources/${META_PROJECT_NAME}.ico")
|
|
|
|
add_custom_command(
|
|
|
|
COMMENT "Generating icon for Windows executable"
|
|
|
|
OUTPUT "${WINDOWS_ICON_PATH}"
|
|
|
|
COMMAND ${FFMPEG_BIN} -y -i "${PNG_ICON_PATH}" "${WINDOWS_ICON_PATH}"
|
|
|
|
DEPENDS "${PNG_ICON_PATH}")
|
|
|
|
message(STATUS "Generating Windows icon from \"${PNG_ICON_PATH}\" via ${FFMPEG_BIN}.")
|
|
|
|
else ()
|
|
|
|
message(STATUS "Unable to find ffmpeg, not creating a Windows icon")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
if (WINDOWS_ICON_PATH)
|
2020-08-11 23:12:17 +02:00
|
|
|
set(WINDOWS_ICON_RC_ENTRY "IDI_ICON1 ICON DISCARDABLE \"${WINDOWS_ICON_PATH}\"")
|
|
|
|
set_source_files_properties("${WINDOWS_RC_FILE}" PROPERTIES OBJECT_DEPENDS "${WINDOWS_ICON_PATH}")
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
|
|
|
# create Windows rc file from template
|
2020-07-04 15:21:20 +02:00
|
|
|
configure_file("${RC_TEMPLATE_FILE}" "${WINDOWS_RC_FILE}-configured.rc")
|
2020-07-07 12:14:05 +02:00
|
|
|
file(
|
|
|
|
GENERATE
|
|
|
|
OUTPUT "${WINDOWS_RC_FILE}-$<CONFIG>.rc"
|
|
|
|
INPUT "${WINDOWS_RC_FILE}-configured.rc")
|
2023-05-06 22:48:27 +02:00
|
|
|
if (BUILD_CLI_WRAPPER AND META_PROJECT_TYPE STREQUAL "application")
|
|
|
|
configure_file("${RC_CLI_TEMPLATE_FILE}" "${WINDOWS_CLI_RC_FILE}-configured.rc")
|
|
|
|
file(
|
|
|
|
GENERATE
|
|
|
|
OUTPUT "${WINDOWS_CLI_RC_FILE}-$<CONFIG>.rc"
|
|
|
|
INPUT "${WINDOWS_CLI_RC_FILE}-configured.rc")
|
|
|
|
endif ()
|
2018-12-22 00:40:38 +01:00
|
|
|
|
2018-02-21 23:00:32 +01:00
|
|
|
# set windres as resource compiler
|
2020-07-04 15:21:20 +02:00
|
|
|
list(APPEND RES_FILES "${WINDOWS_RC_FILE}-${CMAKE_BUILD_TYPE}.rc")
|
2021-08-25 19:38:52 +02:00
|
|
|
set_property(SOURCE "${WINDOWS_RC_FILE}-${CMAKE_BUILD_TYPE}.rc" PROPERTY GENERATED ON)
|
2023-05-06 22:48:27 +02:00
|
|
|
if (BUILD_CLI_WRAPPER AND META_PROJECT_TYPE STREQUAL "application")
|
|
|
|
list(APPEND CLI_WRAPPER_RES_FILES "${WINDOWS_CLI_RC_FILE}-${CMAKE_BUILD_TYPE}.rc")
|
|
|
|
set_property(SOURCE "${WINDOWS_CLI_RC_FILE}-${CMAKE_BUILD_TYPE}.rc" PROPERTY GENERATED ON)
|
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
set(CMAKE_RC_COMPILER_INIT windres)
|
|
|
|
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
|
|
|
|
enable_language(RC)
|