-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
140 lines (111 loc) · 5.27 KB
/
CMakeLists.txt
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
cmake_policy(SET CMP0063 NEW)
# Project properties
PROJECT(qtspell)
SET(QTSPELL_VERSION 1.0.1)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
# Soname
# MAJOR is incremented when symbols are removed or changed in an incompatible way
# MINOR is incremented when new symbols are added
SET(QTSPELL_MAJOR 1)
SET(QTSPELL_MINOR 0)
# Variables
SET(LIB_INSTALL_DIR lib${LIB_SUFFIX} CACHE PATH "Library installation dir")
SET(INCLUDE_INSTALL_DIR include CACHE PATH "Header installation dir")
SET(ISO_CODES_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Prefix for the iso-codes package")
SET(BUILD_STATIC_LIBS OFF CACHE BOOL "Whether to also build static libs")
SET(QT_VER 5 CACHE STRING "Qt version, either 5 or 6")
STRING(REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}/" "" PC_INCLUDE_DIR ${INCLUDE_INSTALL_DIR})
STRING(REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}/" "" PC_LIB_DIR ${LIB_INSTALL_DIR} )
# Dependencies
FIND_PACKAGE(PkgConfig)
PKG_CHECK_MODULES(ENCHANT enchant-2)
IF(ENCHANT_FOUND)
ADD_DEFINITIONS(-DQTSPELL_ENCHANT2)
ELSE(ENCHANT_FOUND)
PKG_CHECK_MODULES(ENCHANT REQUIRED enchant)
IF(ENCHANT_VERSION VERSION_GREATER_EQUAL 2)
ADD_DEFINITIONS(-DQTSPELL_ENCHANT2)
ENDIF()
ENDIF(ENCHANT_FOUND)
INCLUDE_DIRECTORIES(${ENCHANT_INCLUDE_DIRS})
FIND_PACKAGE(Qt${QT_VER}Widgets REQUIRED)
FIND_PACKAGE(Qt${QT_VER}LinguistTools REQUIRED)
FIND_PACKAGE(Doxygen)
# Library
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")
INCLUDE(GenerateExportHeader)
SET(qtspell_SRCS src/Checker.cpp src/Codetable.cpp src/TextEditChecker.cpp src/UndoRedoStack.cpp)
SET(qtspell_HDRS src/TextEditChecker_p.hpp src/QtSpell.hpp src/UndoRedoStack.hpp)
FILE(GLOB qtspell_TS locale/*.ts)
STRING(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_TOLOWER)
IF(NOT CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")
ADD_DEFINITIONS(-DQT_NO_DEBUG_OUTPUT)
ENDIF()
SET(CMAKE_AUTOMOC ON)
SET(QTSPELL_LIB_VERSION ${QTSPELL_MAJOR}.${QTSPELL_MINOR}.0)
SET(QTSPELL_SO_VERSION ${QTSPELL_MAJOR})
QT_ADD_TRANSLATION(qtspell_QM ${qtspell_TS})
ADD_LIBRARY(qtspell SHARED ${qtspell_SRCS} ${qtspell_HDRS} ${qtspell_QM})
GENERATE_EXPORT_HEADER(qtspell
BASE_NAME QTSPELL
EXPORT_MACRO_NAME QTSPELL_API
EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/QtSpellExport.hpp"
)
TARGET_LINK_LIBRARIES(qtspell Qt${QT_VER}::Core Qt${QT_VER}::Widgets)
SET_TARGET_PROPERTIES(qtspell PROPERTIES COMPILE_DEFINITIONS "ISO_CODES_PREFIX=\"${ISO_CODES_PREFIX}\"")
SET_TARGET_PROPERTIES(qtspell PROPERTIES VERSION ${QTSPELL_LIB_VERSION} SOVERSION ${QTSPELL_SO_VERSION})
SET_TARGET_PROPERTIES(qtspell PROPERTIES OUTPUT_NAME qtspell-qt${QT_VER})
IF(WIN32)
SET_TARGET_PROPERTIES(qtspell PROPERTIES SUFFIX "-${QTSPELL_SO_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}")
ENDIF(WIN32)
IF(WIN32)
SET(INTL_LDFLAGS -lintl)
ENDIF(WIN32)
TARGET_LINK_LIBRARIES(qtspell ${ENCHANT_LDFLAGS} ${INTL_LDFLAGS})
IF(${BUILD_STATIC_LIBS})
ADD_LIBRARY(qtspell-static STATIC ${qtspell_SRCS} ${qtspell_MOC} ${qtspell_HDRS} ${qtspell_HDRS} ${qtspell_QM})
TARGET_LINK_LIBRARIES(qtspell-static Qt${QT_VER}::Core Qt${QT_VER}::Widgets)
SET_TARGET_PROPERTIES(qtspell-static PROPERTIES COMPILE_DEFINITIONS "ISO_CODES_PREFIX=\"${ISO_CODES_PREFIX}\"")
SET_TARGET_PROPERTIES(qtspell-static PROPERTIES VERSION ${QTSPELL_LIB_VERSION} SOVERSION ${QTSPELL_SO_VERSION})
SET_TARGET_PROPERTIES(qtspell-static PROPERTIES OUTPUT_NAME qtspell-qt${QT_VER})
ENDIF(${BUILD_STATIC_LIBS})
CONFIGURE_FILE(QtSpell.pc.in QtSpell-qt${QT_VER}.pc @ONLY)
INSTALL(TARGETS qtspell
RUNTIME DESTINATION bin COMPONENT libraries
ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries
LIBRARY DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries
)
IF(${BUILD_STATIC_LIBS})
INSTALL(TARGETS qtspell-static ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries)
ENDIF(${BUILD_STATIC_LIBS})
INSTALL(FILES src/QtSpell.hpp "${CMAKE_CURRENT_BINARY_DIR}/QtSpellExport.hpp" DESTINATION ${INCLUDE_INSTALL_DIR}/QtSpell-qt${QT_VER})
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/QtSpell-qt${QT_VER}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
INSTALL(FILES ${qtspell_QM} DESTINATION share/qt${QT_VER}/translations)
# Example
ADD_EXECUTABLE(example examples/example.cpp examples/example.hpp)
TARGET_LINK_LIBRARIES(example Qt${QT_VER}::Core Qt${QT_VER}::Widgets)
INCLUDE_DIRECTORIES(src/)
TARGET_LINK_LIBRARIES(example qtspell)
# Documentation
IF(DOXYGEN_FOUND)
CONFIGURE_FILE(doc/Doxyfile.in doc/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
ENDIF(DOXYGEN_FOUND)
# spec and debian changelog
set(ENV{LC_ALL} "C")
EXECUTE_PROCESS(COMMAND date +%a\ %b\ %d\ %Y OUTPUT_VARIABLE SPEC_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
EXECUTE_PROCESS(COMMAND date -R OUTPUT_VARIABLE RFC_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
CONFIGURE_FILE(packaging/qtspell.spec.in qtspell.spec @ONLY)
CONFIGURE_FILE(packaging/debian/changelog.in debian/changelog @ONLY)
# Dist
ADD_CUSTOM_TARGET(dist
COMMAND git archive --format=tar --prefix=${CMAKE_PROJECT_NAME}-${QTSPELL_VERSION}/ HEAD | xz > ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}-${QTSPELL_VERSION}.tar.xz
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)