2020-10-26 15:05:26 +01:00
|
|
|
cmake_minimum_required (VERSION 3.0)
|
|
|
|
project (sdtui VERSION 0.1.0 LANGUAGES C)
|
2013-05-17 18:26:08 +02:00
|
|
|
|
|
|
|
# Moar warnings
|
2018-06-24 05:22:51 +02:00
|
|
|
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
|
2016-03-14 21:28:44 +01:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
2013-05-17 18:26:08 +02:00
|
|
|
set (CMAKE_C_FLAGS_DEBUG
|
|
|
|
"${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -Wno-missing-field-initializers")
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2013-05-17 18:26:08 +02:00
|
|
|
|
2016-01-14 20:32:04 +01:00
|
|
|
# For custom modules
|
|
|
|
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
|
|
|
|
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)
|
2016-01-14 20:32:04 +01:00
|
|
|
pkg_check_modules (dependencies REQUIRED glib-2.0 gio-2.0 pango)
|
2015-02-24 20:33:51 +01:00
|
|
|
|
|
|
|
pkg_check_modules (icu icu-uc icu-i18n)
|
|
|
|
if (NOT icu_FOUND)
|
|
|
|
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 ()
|
|
|
|
else ()
|
2017-06-20 06:26:10 +02:00
|
|
|
# We don't want the library to install, even though EXCLUDE_FROM_ALL
|
|
|
|
# sabotages CTest -- those unbuilt tests need to be excluded in CTest runs
|
2014-10-14 22:53:53 +02:00
|
|
|
add_subdirectory (termo EXCLUDE_FROM_ALL)
|
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
|
|
|
|
|
|
|
list (APPEND dependencies_INCLUDE_DIRS ${xcb_INCLUDE_DIRS})
|
|
|
|
list (APPEND dependencies_LIBRARY_DIRS ${xcb_LIBRARY_DIRS})
|
|
|
|
list (APPEND dependencies_LIBRARIES ${xcb_LIBRARIES})
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2015-02-07 21:05:32 +01:00
|
|
|
|
|
|
|
link_directories (${dependencies_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)
|
2016-03-15 21:56:07 +01:00
|
|
|
file (GLOB project_PO_FILES ${PROJECT_SOURCE_DIR}/po/*.po)
|
2013-05-19 02:46:05 +02:00
|
|
|
GETTEXT_CREATE_TRANSLATIONS (
|
2016-03-15 21:56:07 +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)
|
|
|
|
if (NOT ASCIIDOCTOR_EXECUTABLE)
|
|
|
|
message (FATAL_ERROR "asciidoctor not found")
|
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}")
|
2013-05-19 07:49:47 +02:00
|
|
|
add_custom_command (OUTPUT ${page_output}
|
2020-10-26 17:01:43 +01:00
|
|
|
COMMAND ${ASCIIDOCTOR_EXECUTABLE} -b manpage
|
|
|
|
-a release-version=${PROJECT_VERSION}
|
|
|
|
"${PROJECT_SOURCE_DIR}/docs/${page}.adoc"
|
|
|
|
-o "${page_output}"
|
|
|
|
DEPENDS "docs/${page}.adoc"
|
2013-05-19 07:49:47 +02:00
|
|
|
COMMENT "Generating man page for ${page}" VERBATIM)
|
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}
|
|
|
|
${dependencies_LIBRARIES} ${Ncursesw_LIBRARIES} termo-static)
|
|
|
|
|
2013-05-17 18:26:08 +02:00
|
|
|
set (project_common_headers
|
2016-03-15 21:56:07 +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
|
2016-03-15 21:56:07 +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
|
|
|
|
|
|
|
# Primary target source files
|
|
|
|
set (project_sources
|
2016-03-15 21:56:07 +01:00
|
|
|
src/${PROJECT_NAME}.c)
|
2013-05-17 18:26:08 +02:00
|
|
|
set (project_headers
|
|
|
|
${project_common_headers})
|
|
|
|
|
|
|
|
# Build the main executable and link it
|
2020-04-15 07:07:47 +02:00
|
|
|
add_definitions (-DGLIB_DISABLE_DEPRECATION_WARNINGS)
|
2016-03-15 21:56:07 +01:00
|
|
|
add_executable (${PROJECT_NAME}
|
2013-05-17 18:26:08 +02:00
|
|
|
${project_sources} ${project_headers} ${project_common_sources})
|
2016-03-15 21:56:07 +01:00
|
|
|
target_link_libraries (${PROJECT_NAME} ${project_common_libraries})
|
2013-05-17 18:26:08 +02:00
|
|
|
|
2020-09-07 19:08:04 +02:00
|
|
|
# Experimental GTK+ frontend, we link it with ncurses but we don't care
|
|
|
|
pkg_check_modules (gtk gtk+-3.0)
|
|
|
|
if (gtk_FOUND)
|
|
|
|
add_executable (sdgtk EXCLUDE_FROM_ALL
|
|
|
|
src/sdgtk.c ${project_common_sources})
|
|
|
|
target_include_directories (sdgtk PUBLIC ${gtk_INCLUDE_DIRS})
|
|
|
|
target_link_libraries (sdgtk ${gtk_LIBRARIES} ${project_common_libraries})
|
2020-10-29 15:43:05 +01:00
|
|
|
endif ()
|
2020-09-07 19:08:04 +02:00
|
|
|
|
2013-05-17 18:26:08 +02:00
|
|
|
# Tools
|
2020-09-03 23:17:17 +02:00
|
|
|
set (tools add-pronunciation query-tool transform)
|
|
|
|
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
|
|
|
|
|
|
|
add_custom_target (tools DEPENDS ${tools})
|
2013-10-02 02:17:38 +02:00
|
|
|
|
2013-05-17 18:26:08 +02:00
|
|
|
# The files to be installed
|
2013-05-19 07:49:47 +02:00
|
|
|
include (GNUInstallDirs)
|
2016-03-15 21:56:07 +01:00
|
|
|
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2013-05-19 07:49:47 +02:00
|
|
|
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
|
|
|
|
2020-10-26 17:01:43 +01:00
|
|
|
foreach (page ${project_MAN_PAGES})
|
2016-03-15 21:53:52 +01:00
|
|
|
string (REGEX MATCH "\\.([0-9])$" manpage_suffix "${page}")
|
2013-05-19 07:49:47 +02:00
|
|
|
install (FILES "${page}"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
|
2020-10-29 15:43:05 +01:00
|
|
|
endforeach ()
|
2013-05-17 18:26:08 +02:00
|
|
|
|
|
|
|
# Do some unit tests
|
|
|
|
option (BUILD_TESTING "Build tests" OFF)
|
|
|
|
set (project_tests stardict)
|
|
|
|
|
|
|
|
if (BUILD_TESTING)
|
|
|
|
enable_testing ()
|
|
|
|
|
|
|
|
foreach (name ${project_tests})
|
|
|
|
add_executable (test-${name}
|
|
|
|
src/test-${name}.c ${project_common_sources})
|
|
|
|
target_link_libraries (test-${name} ${project_common_libraries})
|
|
|
|
add_test (test-${name} test-${name})
|
2020-10-29 15:43:05 +01:00
|
|
|
endforeach ()
|
|
|
|
endif ()
|
2013-05-17 18:26:08 +02:00
|
|
|
|
|
|
|
# CPack
|
|
|
|
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "StarDict terminal UI")
|
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}")
|
|
|
|
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
|
|
|
|
|
|
|
include (CPack)
|
|
|
|
|