2023-08-01 03:09:31 +02:00
|
|
|
cmake_minimum_required (VERSION 3.0...3.27)
|
2023-06-11 16:18:21 +02:00
|
|
|
project (tdv VERSION 0.1.0 LANGUAGES C)
|
2013-05-17 18:26:08 +02:00
|
|
|
|
2023-06-11 16:18:21 +02:00
|
|
|
# Adjust warnings
|
2018-06-24 05:22:51 +02:00
|
|
|
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
|
2022-08-02 03:04:46 +02:00
|
|
|
set (ignores "-Wno-missing-field-initializers -Wno-cast-function-type")
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 ${ignores}")
|
|
|
|
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra")
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2013-05-17 18:26:08 +02:00
|
|
|
|
2023-06-11 16:18:21 +02:00
|
|
|
add_definitions (-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_38)
|
|
|
|
|
2016-01-14 20:32:04 +01:00
|
|
|
# For custom modules
|
2023-07-24 11:47:33 +02:00
|
|
|
set (CMAKE_MODULE_PATH
|
|
|
|
"${PROJECT_SOURCE_DIR}/cmake;${PROJECT_SOURCE_DIR}/liberty/cmake")
|
2016-01-14 20:32:04 +01:00
|
|
|
|
2021-10-22 01:59:09 +02:00
|
|
|
# Cross-compilation for Windows, as a proof-of-concept pulled in from logdiag
|
|
|
|
if (WIN32)
|
|
|
|
if (NOT CMAKE_CROSSCOMPILING)
|
|
|
|
message (FATAL_ERROR "Win32 must be cross-compiled to build sensibly")
|
|
|
|
endif ()
|
|
|
|
|
2022-08-10 16:04:10 +02:00
|
|
|
set (win32_deps_root "${PROJECT_SOURCE_DIR}")
|
|
|
|
set (win32_deps_prefix "${win32_deps_root}/mingw64")
|
|
|
|
list (APPEND CMAKE_PREFIX_PATH "${win32_deps_prefix}")
|
|
|
|
list (APPEND CMAKE_INCLUDE_PATH "${win32_deps_prefix}/lib")
|
2021-10-22 01:59:09 +02:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mms-bitfields")
|
|
|
|
|
|
|
|
if (CMAKE_CROSSCOMPILING)
|
2022-08-10 16:04:10 +02:00
|
|
|
list (APPEND CMAKE_FIND_ROOT_PATH ${win32_deps_prefix})
|
|
|
|
endif ()
|
2021-10-22 01:59:09 +02:00
|
|
|
|
2022-08-10 16:04:10 +02:00
|
|
|
# Relativize prefixes, and bar pkg-config from looking up host libraries
|
|
|
|
set (ENV{PKG_CONFIG_SYSROOT_DIR} "${win32_deps_root}")
|
|
|
|
set (win32_deps_pcpath
|
|
|
|
"${win32_deps_prefix}/share/pkgconfig:${win32_deps_prefix}/lib/pkgconfig")
|
|
|
|
set (ENV{PKG_CONFIG_PATH} "${win32_deps_pcpath}")
|
|
|
|
set (ENV{PKG_CONFIG_LIBDIR} "${win32_deps_pcpath}")
|
|
|
|
endif ()
|
2021-10-22 01:59:09 +02:00
|
|
|
|
2014-10-14 22:53:53 +02:00
|
|
|
# Dependencies
|
2013-07-14 20:40:58 +02:00
|
|
|
find_package (ZLIB REQUIRED)
|
2016-01-14 20:32:04 +01:00
|
|
|
find_package (Ncursesw REQUIRED)
|
2013-05-17 18:26:08 +02:00
|
|
|
find_package (PkgConfig REQUIRED)
|
2021-10-06 16:09:35 +02:00
|
|
|
pkg_check_modules (dependencies REQUIRED glib-2.0>=2.38 gio-2.0 pango)
|
2015-02-24 20:33:51 +01:00
|
|
|
|
|
|
|
pkg_check_modules (icu icu-uc icu-i18n)
|
2021-10-22 01:59:09 +02:00
|
|
|
if (NOT icu_FOUND AND NOT WIN32)
|
2015-02-24 20:33:51 +01:00
|
|
|
find_program (icu_CONFIG_EXECUTABLE icu-config)
|
|
|
|
if (NOT icu_CONFIG_EXECUTABLE)
|
|
|
|
message (FATAL_ERROR "ICU not found")
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2015-02-24 20:33:51 +01:00
|
|
|
|
|
|
|
execute_process (COMMAND ${icu_CONFIG_EXECUTABLE} --cppflags
|
|
|
|
OUTPUT_VARIABLE icu_CPPFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
separate_arguments (icu_CPPFLAGS)
|
|
|
|
|
|
|
|
# target_link_libraries() handles linker flags as well
|
|
|
|
execute_process (COMMAND ${icu_CONFIG_EXECUTABLE} --ldflags
|
|
|
|
OUTPUT_VARIABLE icu_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
separate_arguments (icu_LIBRARIES)
|
|
|
|
|
|
|
|
# Filter out include directories from the preprocessor flags
|
|
|
|
set (icu_INCLUDE_DIRS)
|
|
|
|
foreach (flag ${icu_CPPFLAGS})
|
|
|
|
if (flag MATCHES "^-I(.*)")
|
|
|
|
list (APPEND icu_INCLUDE_DIRS "${CMAKE_MATCH_1}")
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
|
|
|
endforeach ()
|
2015-02-24 20:33:51 +01:00
|
|
|
|
|
|
|
# This should suffice most of the time, don't care about the rest
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2013-05-17 18:26:08 +02:00
|
|
|
|
2015-10-01 22:27:35 +02:00
|
|
|
find_package (Termo QUIET NO_MODULE)
|
|
|
|
option (USE_SYSTEM_TERMO
|
|
|
|
"Don't compile our own termo library, use the system one" ${Termo_FOUND})
|
2014-10-14 22:53:53 +02:00
|
|
|
if (USE_SYSTEM_TERMO)
|
2015-10-01 22:27:35 +02:00
|
|
|
if (NOT Termo_FOUND)
|
|
|
|
message (FATAL_ERROR "System termo library not found")
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2024-04-10 12:48:05 +02:00
|
|
|
elseif (NOT WIN32)
|
2021-10-27 00:16:42 +02:00
|
|
|
# We don't want the library to install, but EXCLUDE_FROM_ALL ignores tests
|
2014-10-14 22:53:53 +02:00
|
|
|
add_subdirectory (termo EXCLUDE_FROM_ALL)
|
2021-10-27 00:16:42 +02:00
|
|
|
file (WRITE ${PROJECT_BINARY_DIR}/CTestCustom.cmake
|
|
|
|
"execute_process (COMMAND ${CMAKE_COMMAND} --build termo)")
|
|
|
|
|
2017-06-20 06:26:10 +02:00
|
|
|
# We don't have many good choices; this is a relatively clean approach
|
|
|
|
# (other possibilities: setting a variable in the parent scope, using
|
|
|
|
# a cache variable, writing a special config file with build paths in it
|
|
|
|
# and including it here, or setting a custom property on the targets)
|
2014-10-14 22:53:53 +02:00
|
|
|
get_directory_property (Termo_INCLUDE_DIRS
|
|
|
|
DIRECTORY termo INCLUDE_DIRECTORIES)
|
|
|
|
set (Termo_LIBRARIES termo-static)
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2014-10-14 22:53:53 +02:00
|
|
|
|
2018-09-22 14:09:42 +02:00
|
|
|
pkg_check_modules (xcb xcb xcb-xfixes)
|
|
|
|
option (WITH_X11 "Compile with X11 selection support using XCB" ${xcb_FOUND})
|
|
|
|
if (WITH_X11)
|
|
|
|
if (NOT xcb_FOUND)
|
|
|
|
message (FATAL_ERROR "XCB not found")
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2018-09-22 14:09:42 +02:00
|
|
|
|
2021-10-22 01:59:09 +02:00
|
|
|
include_directories (${xcb_INCLUDE_DIRS})
|
|
|
|
link_directories (${xcb_LIBRARY_DIRS})
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2015-02-07 21:05:32 +01:00
|
|
|
|
2021-10-15 12:08:44 +02:00
|
|
|
pkg_check_modules (gtk gtk+-3.0)
|
2021-10-17 11:25:32 +02:00
|
|
|
option (WITH_GUI "Build an alternative GTK+ UI" ${gtk_FOUND})
|
2021-11-02 16:57:18 +01:00
|
|
|
if (WITH_GUI)
|
|
|
|
if (NOT gtk_FOUND)
|
|
|
|
message (FATAL_ERROR "GTK+ not found")
|
|
|
|
endif ()
|
|
|
|
|
2023-06-11 16:18:21 +02:00
|
|
|
include_directories (${gtk_INCLUDE_DIRS})
|
2021-11-02 16:57:18 +01:00
|
|
|
link_directories (${gtk_LIBRARY_DIRS})
|
|
|
|
endif ()
|
2021-10-15 12:08:44 +02:00
|
|
|
|
2021-11-02 16:57:18 +01:00
|
|
|
link_directories (${dependencies_LIBRARY_DIRS} ${icu_LIBRARY_DIRS})
|
2015-02-24 20:33:51 +01:00
|
|
|
include_directories (${ZLIB_INCLUDE_DIRS} ${icu_INCLUDE_DIRS}
|
2020-09-07 18:39:59 +02:00
|
|
|
${dependencies_INCLUDE_DIRS} ${Ncursesw_INCLUDE_DIRS}
|
2016-01-14 20:32:04 +01:00
|
|
|
${Termo_INCLUDE_DIRS})
|
2013-05-17 18:26:08 +02:00
|
|
|
|
2014-10-15 00:51:05 +02:00
|
|
|
# Configuration
|
|
|
|
include (CheckFunctionExists)
|
2020-09-07 18:39:59 +02:00
|
|
|
set (CMAKE_REQUIRED_LIBRARIES ${Ncursesw_LIBRARIES})
|
2015-01-20 23:56:29 +01:00
|
|
|
CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM)
|
2014-10-15 00:51:05 +02:00
|
|
|
|
2013-05-19 02:46:05 +02:00
|
|
|
# Localization
|
|
|
|
find_package (Gettext REQUIRED)
|
2024-12-07 22:48:35 +01:00
|
|
|
file (GLOB project_PO_FILES "${PROJECT_SOURCE_DIR}/po/*.po")
|
2013-05-19 02:46:05 +02:00
|
|
|
GETTEXT_CREATE_TRANSLATIONS (
|
2024-12-07 22:48:35 +01:00
|
|
|
"${PROJECT_SOURCE_DIR}/po/${PROJECT_NAME}.pot"
|
2013-05-19 02:46:05 +02:00
|
|
|
ALL ${project_PO_FILES})
|
|
|
|
|
2013-05-19 07:49:47 +02:00
|
|
|
# Documentation
|
2020-10-26 17:01:43 +01:00
|
|
|
find_program (ASCIIDOCTOR_EXECUTABLE asciidoctor)
|
2022-08-24 00:43:14 +02:00
|
|
|
find_program (A2X_EXECUTABLE a2x)
|
|
|
|
if (NOT ASCIIDOCTOR_EXECUTABLE AND NOT A2X_EXECUTABLE)
|
2023-06-10 12:06:52 +02:00
|
|
|
message (WARNING "Neither asciidoctor nor a2x were found, "
|
|
|
|
"falling back to a substandard manual page generator")
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2013-05-19 07:49:47 +02:00
|
|
|
|
2020-10-26 17:01:43 +01:00
|
|
|
foreach (page "${PROJECT_NAME}.1")
|
2016-03-15 21:56:07 +01:00
|
|
|
set (page_output "${PROJECT_BINARY_DIR}/${page}")
|
2020-10-26 17:01:43 +01:00
|
|
|
list (APPEND project_MAN_PAGES "${page_output}")
|
2022-08-24 00:43:14 +02:00
|
|
|
if (ASCIIDOCTOR_EXECUTABLE)
|
2024-12-07 22:48:35 +01:00
|
|
|
add_custom_command (OUTPUT "${page_output}"
|
2022-08-24 00:43:14 +02:00
|
|
|
COMMAND ${ASCIIDOCTOR_EXECUTABLE} -b manpage
|
|
|
|
-a release-version=${PROJECT_VERSION}
|
|
|
|
-o "${page_output}"
|
|
|
|
"${PROJECT_SOURCE_DIR}/docs/${page}.adoc"
|
|
|
|
DEPENDS "docs/${page}.adoc"
|
|
|
|
COMMENT "Generating man page for ${page}" VERBATIM)
|
|
|
|
elseif (A2X_EXECUTABLE)
|
2024-12-07 22:48:35 +01:00
|
|
|
add_custom_command (OUTPUT "${page_output}"
|
2022-08-24 00:43:14 +02:00
|
|
|
COMMAND ${A2X_EXECUTABLE} --doctype manpage --format manpage
|
|
|
|
-a release-version=${PROJECT_VERSION}
|
|
|
|
-D "${PROJECT_BINARY_DIR}"
|
|
|
|
"${PROJECT_SOURCE_DIR}/docs/${page}.adoc"
|
|
|
|
DEPENDS "docs/${page}.adoc"
|
|
|
|
COMMENT "Generating man page for ${page}" VERBATIM)
|
2023-06-10 12:06:52 +02:00
|
|
|
else ()
|
|
|
|
set (ASCIIMAN ${PROJECT_SOURCE_DIR}/liberty/tools/asciiman.awk)
|
2024-12-07 22:48:35 +01:00
|
|
|
add_custom_command (OUTPUT "${page_output}"
|
2023-06-10 12:06:52 +02:00
|
|
|
COMMAND env LC_ALL=C asciidoc-release-version=${PROJECT_VERSION}
|
|
|
|
awk -f ${ASCIIMAN} "${PROJECT_SOURCE_DIR}/docs/${page}.adoc"
|
2024-12-07 22:48:35 +01:00
|
|
|
> "${page_output}"
|
2023-06-10 12:06:52 +02:00
|
|
|
DEPENDS "docs/${page}.adoc" ${ASCIIMAN}
|
|
|
|
COMMENT "Generating man page for ${page}" VERBATIM)
|
2022-08-24 00:43:14 +02:00
|
|
|
endif ()
|
2020-10-29 15:43:05 +01:00
|
|
|
endforeach ()
|
2013-05-19 07:49:47 +02:00
|
|
|
|
2020-10-26 17:01:43 +01:00
|
|
|
add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES})
|
2013-05-19 07:49:47 +02:00
|
|
|
|
2020-10-26 15:05:26 +01:00
|
|
|
# Project libraries
|
|
|
|
set (project_common_libraries ${ZLIB_LIBRARIES} ${icu_LIBRARIES}
|
2021-10-15 12:08:44 +02:00
|
|
|
${dependencies_LIBRARIES})
|
2021-10-22 01:59:09 +02:00
|
|
|
if (WIN32)
|
|
|
|
find_package (LibIntl REQUIRED)
|
|
|
|
list (APPEND project_common_libraries ${LibIntl_LIBRARIES})
|
|
|
|
endif (WIN32)
|
2020-10-26 15:05:26 +01:00
|
|
|
|
2013-05-17 18:26:08 +02:00
|
|
|
set (project_common_headers
|
2024-12-07 22:48:35 +01:00
|
|
|
"${PROJECT_BINARY_DIR}/config.h"
|
2013-07-14 20:40:58 +02:00
|
|
|
src/dictzip-input-stream.h
|
2013-05-17 18:26:08 +02:00
|
|
|
src/stardict.h
|
|
|
|
src/stardict-private.h
|
2013-07-14 20:40:58 +02:00
|
|
|
src/generator.h
|
|
|
|
src/utils.h)
|
2013-05-17 18:26:08 +02:00
|
|
|
|
|
|
|
# Create a common project library so that source files are only compiled once
|
2020-10-26 15:05:26 +01:00
|
|
|
add_library (stardict OBJECT
|
|
|
|
${project_common_headers}
|
|
|
|
src/dictzip-input-stream.c
|
|
|
|
src/generator.c
|
|
|
|
src/stardict.c
|
|
|
|
src/utils.c)
|
|
|
|
set (project_common_sources $<TARGET_OBJECTS:stardict>)
|
2013-05-17 18:26:08 +02:00
|
|
|
|
|
|
|
# Generate a configuration file
|
2024-12-07 22:48:35 +01:00
|
|
|
configure_file ("${PROJECT_SOURCE_DIR}/config.h.in"
|
|
|
|
"${PROJECT_BINARY_DIR}/config.h")
|
|
|
|
include_directories ("${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
|
2013-05-17 18:26:08 +02:00
|
|
|
|
2023-06-11 16:18:21 +02:00
|
|
|
# Build the main executable and link it
|
|
|
|
set (project_libraries
|
|
|
|
${project_common_libraries})
|
|
|
|
set (project_sources
|
|
|
|
${project_common_sources}
|
|
|
|
src/${PROJECT_NAME}.c)
|
|
|
|
set (project_headers
|
|
|
|
${project_common_headers})
|
|
|
|
|
2021-10-27 19:23:47 +02:00
|
|
|
if (WITH_GUI)
|
2024-02-10 05:46:13 +01:00
|
|
|
include (IconUtils)
|
2021-10-27 09:48:57 +02:00
|
|
|
|
|
|
|
# The largest size is mainly for an appropriately sized Windows icon
|
2024-12-07 22:48:35 +01:00
|
|
|
set (icon_base "${PROJECT_BINARY_DIR}/icons")
|
2021-10-27 19:23:47 +02:00
|
|
|
set (icon_png_list)
|
|
|
|
foreach (icon_size 16 32 48 256)
|
2024-12-07 22:48:35 +01:00
|
|
|
icon_to_png (${PROJECT_NAME} "${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.svg"
|
|
|
|
${icon_size} "${icon_base}" icon_png)
|
|
|
|
list (APPEND icon_png_list "${icon_png}")
|
2021-10-27 19:23:47 +02:00
|
|
|
endforeach ()
|
2024-02-10 05:46:13 +01:00
|
|
|
|
2023-06-11 16:18:21 +02:00
|
|
|
add_custom_target (icons ALL DEPENDS ${icon_png_list})
|
|
|
|
endif ()
|
2021-10-27 09:48:57 +02:00
|
|
|
|
2023-06-11 16:18:21 +02:00
|
|
|
if (WIN32)
|
2024-12-07 22:48:35 +01:00
|
|
|
list (REMOVE_ITEM icon_png_list "${icon_png}")
|
|
|
|
set (icon_ico "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.ico")
|
|
|
|
icon_for_win32 ("${icon_ico}" "${icon_png_list}" "${icon_png}")
|
2023-06-11 16:18:21 +02:00
|
|
|
|
2024-12-07 22:48:35 +01:00
|
|
|
set (resource_file "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.rc")
|
|
|
|
list (APPEND project_sources "${resource_file}")
|
|
|
|
add_custom_command (OUTPUT "${resource_file}"
|
2023-06-11 16:18:21 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "1 ICON \"${PROJECT_NAME}.ico\""
|
2024-12-07 22:48:35 +01:00
|
|
|
> "${resource_file}" VERBATIM)
|
|
|
|
set_property (SOURCE "${resource_file}"
|
|
|
|
APPEND PROPERTY OBJECT_DEPENDS "${icon_ico}")
|
2023-06-11 16:18:21 +02:00
|
|
|
else ()
|
2024-04-10 12:48:05 +02:00
|
|
|
list (APPEND project_libraries ${Ncursesw_LIBRARIES} ${Termo_LIBRARIES})
|
2023-06-11 16:18:21 +02:00
|
|
|
list (APPEND project_sources
|
|
|
|
src/${PROJECT_NAME}-tui.c)
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2020-09-07 19:08:04 +02:00
|
|
|
|
2023-06-11 16:18:21 +02:00
|
|
|
if (WITH_X11)
|
|
|
|
list (APPEND project_libraries ${xcb_LIBRARIES})
|
|
|
|
endif ()
|
|
|
|
if (WITH_GUI)
|
|
|
|
list (APPEND project_libraries ${gtk_LIBRARIES})
|
|
|
|
list (APPEND project_sources
|
|
|
|
src/${PROJECT_NAME}-gui.c
|
|
|
|
src/stardict-view.c)
|
|
|
|
|
|
|
|
add_executable (${PROJECT_NAME} WIN32 ${project_sources} ${project_headers})
|
|
|
|
else ()
|
|
|
|
add_executable (${PROJECT_NAME} ${project_sources} ${project_headers})
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
target_link_libraries (${PROJECT_NAME} ${project_libraries})
|
|
|
|
|
2013-05-17 18:26:08 +02:00
|
|
|
# Tools
|
2023-06-11 17:45:38 +02:00
|
|
|
set (tools tdv-tabfile tdv-add-pronunciation tdv-query-tool tdv-transform)
|
2020-09-03 23:17:17 +02:00
|
|
|
foreach (tool ${tools})
|
|
|
|
add_executable (${tool} EXCLUDE_FROM_ALL
|
|
|
|
src/${tool}.c ${project_common_sources})
|
|
|
|
target_link_libraries (${tool} ${project_common_libraries})
|
2020-10-29 15:43:05 +01:00
|
|
|
endforeach ()
|
2020-09-03 23:17:17 +02:00
|
|
|
|
2023-06-11 17:45:38 +02:00
|
|
|
option (WITH_TOOLS "Build and install some StarDict tools" ${UNIX})
|
|
|
|
if (WITH_TOOLS)
|
|
|
|
add_custom_target (tools ALL DEPENDS ${tools})
|
|
|
|
endif ()
|
2013-10-02 02:17:38 +02:00
|
|
|
|
2021-10-07 03:37:12 +02:00
|
|
|
# Example dictionaries
|
2021-10-10 00:36:12 +02:00
|
|
|
file (GLOB dicts_scripts "${PROJECT_SOURCE_DIR}/dicts/*.*")
|
2021-10-07 03:37:12 +02:00
|
|
|
set (dicts_targets)
|
|
|
|
foreach (dict_script ${dicts_scripts})
|
|
|
|
get_filename_component (dict_name "${dict_script}" NAME_WE)
|
|
|
|
list (APPEND dicts_targets "dicts-${dict_name}")
|
|
|
|
add_custom_target (dicts-${dict_name}
|
|
|
|
COMMAND sh -c "PATH=.:$PATH \"$0\"" "${dict_script}"
|
2023-06-22 00:23:29 +02:00
|
|
|
DEPENDS tdv-tabfile
|
2021-10-07 03:37:12 +02:00
|
|
|
COMMENT "Generating sample dictionary ${dict_name}"
|
|
|
|
VERBATIM)
|
|
|
|
endforeach ()
|
|
|
|
|
|
|
|
add_custom_target (dicts DEPENDS ${dicts_targets})
|
|
|
|
|
2013-05-17 18:26:08 +02:00
|
|
|
# The files to be installed
|
2021-10-22 01:59:09 +02:00
|
|
|
if (NOT WIN32)
|
|
|
|
include (GNUInstallDirs)
|
|
|
|
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
|
|
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
|
|
|
|
2023-06-11 17:45:38 +02:00
|
|
|
if (WITH_TOOLS)
|
|
|
|
install (TARGETS ${tools} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
|
|
endif ()
|
2021-10-22 01:59:09 +02:00
|
|
|
if (WITH_GUI)
|
2023-06-11 16:18:21 +02:00
|
|
|
install (FILES ${PROJECT_NAME}.svg
|
2021-10-27 07:45:43 +02:00
|
|
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
|
2024-02-10 05:46:13 +01:00
|
|
|
install (DIRECTORY ${icon_base}
|
2021-10-27 09:48:57 +02:00
|
|
|
DESTINATION ${CMAKE_INSTALL_DATADIR})
|
2023-06-11 16:18:21 +02:00
|
|
|
install (FILES ${PROJECT_NAME}.desktop
|
2021-10-22 01:59:09 +02:00
|
|
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
|
2023-06-11 16:18:21 +02:00
|
|
|
install (FILES ${PROJECT_NAME}.xml
|
2021-10-22 01:59:09 +02:00
|
|
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages)
|
|
|
|
endif ()
|
2013-05-19 07:49:47 +02:00
|
|
|
|
2021-10-22 01:59:09 +02:00
|
|
|
foreach (page ${project_MAN_PAGES})
|
|
|
|
string (REGEX MATCH "\\.([0-9])$" manpage_suffix "${page}")
|
|
|
|
install (FILES "${page}"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
|
|
|
|
endforeach ()
|
|
|
|
elseif (WITH_GUI)
|
|
|
|
# This rather crude filter has been mostly copied over from logdiag
|
2023-06-11 16:18:21 +02:00
|
|
|
install (TARGETS ${PROJECT_NAME} DESTINATION .)
|
2021-10-22 01:59:09 +02:00
|
|
|
install (DIRECTORY
|
2022-08-10 16:04:10 +02:00
|
|
|
${win32_deps_prefix}/bin/
|
2021-10-22 01:59:09 +02:00
|
|
|
DESTINATION .
|
2021-10-23 18:09:18 +02:00
|
|
|
FILES_MATCHING PATTERN "*.dll")
|
2021-10-22 01:59:09 +02:00
|
|
|
install (DIRECTORY
|
2022-08-10 16:04:10 +02:00
|
|
|
${win32_deps_prefix}/etc/
|
2021-10-22 01:59:09 +02:00
|
|
|
DESTINATION etc)
|
|
|
|
install (DIRECTORY
|
2022-08-10 16:04:10 +02:00
|
|
|
${win32_deps_prefix}/lib/gdk-pixbuf-2.0
|
2021-10-22 01:59:09 +02:00
|
|
|
DESTINATION lib
|
|
|
|
FILES_MATCHING PATTERN "*" PATTERN "*.a" EXCLUDE)
|
|
|
|
install (DIRECTORY
|
2022-08-10 16:04:10 +02:00
|
|
|
${win32_deps_prefix}/share/glib-2.0/schemas
|
2021-10-22 01:59:09 +02:00
|
|
|
DESTINATION share/glib-2.0)
|
|
|
|
|
|
|
|
install (DIRECTORY
|
2022-08-10 16:04:10 +02:00
|
|
|
${win32_deps_prefix}/share/icons/Adwaita
|
2021-10-22 01:59:09 +02:00
|
|
|
DESTINATION share/icons OPTIONAL)
|
|
|
|
install (FILES
|
2022-08-10 16:04:10 +02:00
|
|
|
${win32_deps_prefix}/share/icons/hicolor/index.theme
|
2021-10-22 01:59:09 +02:00
|
|
|
DESTINATION share/icons/hicolor)
|
2024-12-07 22:48:35 +01:00
|
|
|
install (DIRECTORY "${icon_base}" DESTINATION share)
|
2021-10-23 18:09:18 +02:00
|
|
|
|
|
|
|
install (SCRIPT cmake/Win32Cleanup.cmake)
|
2021-11-01 08:40:07 +01:00
|
|
|
|
|
|
|
find_program (GTK_UPDATE_ICON_CACHE_EXECUTABLE gtk-update-icon-cache)
|
|
|
|
if (NOT GTK_UPDATE_ICON_CACHE_EXECUTABLE)
|
|
|
|
message (FATAL_ERROR "gtk-update-icon-cache not found")
|
|
|
|
endif ()
|
|
|
|
|
2021-10-26 11:26:39 +02:00
|
|
|
install (CODE "execute_process (COMMAND
|
|
|
|
sh \"${PROJECT_SOURCE_DIR}/cmake/Win32CleanupAdwaita.sh\"
|
|
|
|
WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX})")
|
2021-11-01 08:40:07 +01:00
|
|
|
install (CODE " # This may speed up program start-up a little bit
|
|
|
|
execute_process (COMMAND \"${GTK_UPDATE_ICON_CACHE_EXECUTABLE}\"
|
|
|
|
\"\${CMAKE_INSTALL_PREFIX}/share/icons/Adwaita\")")
|
2021-10-22 01:59:09 +02:00
|
|
|
endif ()
|
2013-05-17 18:26:08 +02:00
|
|
|
|
|
|
|
# Do some unit tests
|
|
|
|
option (BUILD_TESTING "Build tests" OFF)
|
|
|
|
if (BUILD_TESTING)
|
|
|
|
enable_testing ()
|
|
|
|
|
2021-10-26 23:33:39 +02:00
|
|
|
find_program (xmlwf_EXECUTABLE xmlwf)
|
|
|
|
find_program (xmllint_EXECUTABLE xmllint)
|
2023-06-15 16:21:18 +02:00
|
|
|
foreach (xml ${PROJECT_NAME}.xml ${PROJECT_NAME}.svg)
|
2021-10-26 23:33:39 +02:00
|
|
|
if (xmlwf_EXECUTABLE)
|
|
|
|
add_test (test-xmlwf-${xml} ${xmlwf_EXECUTABLE}
|
2024-12-07 22:48:35 +01:00
|
|
|
"${PROJECT_SOURCE_DIR}/${xml}")
|
2021-10-26 23:33:39 +02:00
|
|
|
endif ()
|
|
|
|
if (xmllint_EXECUTABLE)
|
|
|
|
add_test (test-xmllint-${xml} ${xmllint_EXECUTABLE} --noout
|
2024-12-07 22:48:35 +01:00
|
|
|
"${PROJECT_SOURCE_DIR}/${xml}")
|
2021-10-26 23:33:39 +02:00
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
|
2023-06-15 16:21:18 +02:00
|
|
|
find_program (dfv_EXECUTABLE desktop-file-validate)
|
|
|
|
if (dfv_EXECUTABLE)
|
|
|
|
foreach (df ${PROJECT_NAME}.desktop)
|
|
|
|
add_test (test-dfv-${df} ${dfv_EXECUTABLE}
|
2024-12-07 22:48:35 +01:00
|
|
|
"${PROJECT_SOURCE_DIR}/${df}")
|
2023-06-15 16:21:18 +02:00
|
|
|
endforeach ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
foreach (name stardict)
|
2013-05-17 18:26:08 +02:00
|
|
|
add_executable (test-${name}
|
|
|
|
src/test-${name}.c ${project_common_sources})
|
|
|
|
target_link_libraries (test-${name} ${project_common_libraries})
|
2024-04-10 12:48:05 +02:00
|
|
|
add_test (NAME test-${name} COMMAND test-${name})
|
2020-10-29 15:43:05 +01:00
|
|
|
endforeach ()
|
|
|
|
endif ()
|
2013-05-17 18:26:08 +02:00
|
|
|
|
|
|
|
# CPack
|
2023-06-11 16:18:21 +02:00
|
|
|
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Translation dictionary viewer")
|
2020-09-02 16:27:45 +02:00
|
|
|
set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
|
|
|
|
set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
|
2016-03-15 21:56:07 +01:00
|
|
|
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
2013-05-17 18:26:08 +02:00
|
|
|
set (CPACK_GENERATOR "TGZ;ZIP")
|
|
|
|
set (CPACK_PACKAGE_FILE_NAME
|
2020-10-26 15:05:26 +01:00
|
|
|
"${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
2021-10-27 22:48:39 +02:00
|
|
|
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME} ${PROJECT_VERSION}")
|
2013-05-17 18:26:08 +02:00
|
|
|
set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
|
|
|
|
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
|
2020-10-26 15:05:26 +01:00
|
|
|
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
|
2013-05-17 18:26:08 +02:00
|
|
|
|
2021-10-27 22:48:39 +02:00
|
|
|
# XXX: It is still possible to install multiple copies, making commands collide.
|
|
|
|
set (CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
|
|
|
|
set (CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${PROJECT_NAME}")
|
|
|
|
|
2023-06-11 16:18:21 +02:00
|
|
|
set (CPACK_NSIS_INSTALLED_ICON_NAME ${PROJECT_NAME}.exe)
|
|
|
|
set (CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} ${PROJECT_NAME})
|
2021-10-27 22:48:39 +02:00
|
|
|
set (CPACK_NSIS_EXECUTABLES_DIRECTORY .)
|
|
|
|
set (CPACK_NSIS_EXTRA_INSTALL_COMMANDS [[
|
2023-06-11 16:18:21 +02:00
|
|
|
WriteRegStr HKCR '.ifo' '' 'tdv.Dictionary'
|
|
|
|
WriteRegStr HKCR 'tdv.Dictionary' '' 'StarDict Dictionary'
|
|
|
|
WriteRegStr HKCR 'tdv.Dictionary\\shell\\open\\command' '' '\"$INSTDIR\\tdv.exe\" \"%1\"'
|
2021-10-27 22:48:39 +02:00
|
|
|
System::Call 'shell32::SHChangeNotify(i,i,i,i) (0x08000000, 0x1000, 0, 0)'
|
|
|
|
]])
|
|
|
|
set (CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS [[
|
2023-06-11 16:18:21 +02:00
|
|
|
DeleteRegKey HKCR 'tdv.Dictionary'
|
2021-10-27 22:48:39 +02:00
|
|
|
System::Call 'shell32::SHChangeNotify(i,i,i,i) (0x08000000, 0x1000, 0, 0)'
|
|
|
|
]])
|
|
|
|
|
2013-05-17 18:26:08 +02:00
|
|
|
include (CPack)
|