CMakeLists.txt 7.48 KB
Newer Older
1 2 3 4 5 6
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
# CMP0000: Call the cmake_minimum_required() command at the beginning of the top-level
# CMakeLists.txt file even before calling the project() command.
# The cmake_minimum_required(VERSION) command implicitly invokes the cmake_policy(VERSION)
# command to specify that the current project code is written for the given range of CMake
# versions.
7 8
project(qterminal)

9
include(GNUInstallDirs)
10

11
# qterminal version
12
set(QTERMINAL_VERSION "0.14.1")
13

14
option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
15

16
# we need qpa/qplatformnativeinterface.h for global shortcut
17 18 19

# Minimum Versions
set(LXQTBT_MINIMUM_VERSION "0.6.0")
20
set(QTERMWIDGET_MINIMUM_VERSION "0.14.1")
21 22 23 24 25 26 27 28
set(QT_MINIMUM_VERSION "5.7.1")

find_package(Qt5Gui ${QT_MINIMUM_VERSION} REQUIRED)
find_package(Qt5LinguistTools ${QT_MINIMUM_VERSION} REQUIRED)
find_package(Qt5Widgets ${QT_MINIMUM_VERSION} REQUIRED)
if(UNIX)
    find_package(Qt5DBus ${QT_MINIMUM_VERSION} REQUIRED)
    find_package(Qt5X11Extras ${QT_MINIMUM_VERSION} REQUIRED)
29
endif()
30
find_package(QTermWidget5 ${QTERMWIDGET_MINIMUM_VERSION} REQUIRED)
31
find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
32 33

include(LXQtPreventInSourceBuilds)
34
include(LXQtTranslateTs)
35 36
include(LXQtCompilerSettings NO_POLICY_SCOPE)
message(STATUS "Qt version: ${Qt5Core_VERSION}")
37

38 39 40
# TODO remove Qxt
message(STATUS "Using bundled Qxt...")
set(QXT_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/third-party")
41 42 43 44 45 46 47 48


if(APPLE)
   find_library(CARBON_LIBRARY Carbon REQUIRED)
   message(STATUS "CARBON_LIBRARY: ${CARBON_LIBRARY}")
elseif(UNIX)
   find_package(X11 REQUIRED)
   message(STATUS "X11_X11_LIB: ${X11_X11_LIB}")
49
endif()
50

51
add_definitions(
52
    -DQTERMINAL_VERSION=\"${QTERMINAL_VERSION}\"
53
)
54 55 56 57 58 59

set(EXE_NAME qterminal)

set(QTERM_SRC
    src/main.cpp
    src/mainwindow.cpp
60
    src/tabbar.cpp
61 62 63
    src/tabwidget.cpp
    src/termwidget.cpp
    src/termwidgetholder.cpp
64
    src/terminalconfig.cpp
65 66 67 68
    src/properties.cpp
    src/propertiesdialog.cpp
    src/bookmarkswidget.cpp
    src/fontdialog.cpp
69
    src/dbusaddressable.cpp
70
    src/tab-switcher.cpp
71 72 73
)

set(QTERM_MOC_SRC
74
    src/qterminalapp.h
75
    src/mainwindow.h
76
    src/tabbar.h
77 78 79 80 81 82
    src/tabwidget.h
    src/termwidget.h
    src/termwidgetholder.h
    src/propertiesdialog.h
    src/bookmarkswidget.h
    src/fontdialog.h
83
    src/tab-switcher.h
84 85
)

86 87 88 89 90 91 92 93 94 95
if (Qt5DBus_FOUND)
    add_definitions(-DHAVE_QDBUS)
    QT5_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Window.xml mainwindow.h MainWindow)
    QT5_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Tab.xml termwidgetholder.h TermWidgetHolder)
    QT5_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Terminal.xml termwidget.h TermWidget)
    QT5_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Process.xml qterminalapp.h QTerminalApp)
    set(QTERM_MOC_SRC ${QTERM_MOC_SRC} src/dbusaddressable.h)
    message(STATUS "Building with Qt5DBus support")
endif()

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
if(NOT QXT_FOUND)
    set(QTERM_SRC ${QTERM_SRC} src/third-party/qxtglobalshortcut.cpp)
    set(QTERM_MOC_SRC ${QTERM_MOC_SRC} src/third-party/qxtglobalshortcut.h)

    if(WIN32)
        set(QTERM_SRC ${QTERM_SRC} src/third-party/qxtglobalshortcut_win.cpp)
    elseif(APPLE)
        set(QTERM_SRC ${QTERM_SRC} src/third-party/qxtglobalshortcut_mac.cpp)
    else()
        set(QTERM_SRC ${QTERM_SRC} src/third-party/qxtglobalshortcut_x11.cpp)
    endif()
endif()

set(QTERM_UI_SRC
    src/forms/qterminal.ui
    src/forms/propertiesdialog.ui
    src/forms/bookmarkswidget.ui
    src/forms/fontdialog.ui
)

set(QTERM_RCC_SRC
    src/icons.qrc
)

120 121 122
qt5_wrap_ui( QTERM_UI ${QTERM_UI_SRC} )
qt5_wrap_cpp( QTERM_MOC ${QTERM_MOC_SRC} )
qt5_add_resources( QTERM_RCC ${QTERM_RCC_SRC} )
123
lxqt_translate_ts(QTERM_QM
124 125 126 127 128 129
    UPDATE_TRANSLATIONS
        ${UPDATE_TRANSLATIONS}
    SOURCES
        ${QTERM_SRC}
        ${QTERM_UI_SRC}
        ${QTERM_MOC_SRC}
130 131
    TRANSLATION_DIR "src/translations"
)
132

133
include_directories(
134 135 136
    "${PROJECT_SOURCE_DIR}"
    "${PROJECT_SOURCE_DIR}/src"
    "${PROJECT_BINARY_DIR}"
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    ${QXT_INCLUDE_DIRS}
)
if(X11_FOUND)
    include_directories("${X11_INCLUDE_DIR}")
endif()


# TODO/FIXME: apple bundle
set(GUI_TYPE "")
set(APPLE_BUNDLE_SOURCES "")
if(APPLEBUNDLE)
    add_definitions(-DAPPLE_BUNDLE)
    set(GUI_TYPE MACOSX_BUNDLE)

    # create Info.plist file
    set(MACOSX_BUNDLE_ICON_FILE qterminal.icns)
153
    set(MACOSX_BUNDLE_INFO_STRING "QTerminal ${QTERMINAL_VERSION}")
154
    set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.qterminal")
155
    set(MACOSX_BUNDLE_LONG_VERSION_STRING "${QTERMINAL_VERSION}")
156
    set(MACOSX_BUNDLE_BUNDLE_NAME "${EXE_NAME}")
157 158
    set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${QTERMINAL_VERSION}")
    set(MACOSX_BUNDLE_BUNDLE_VERSION "${QTERMINAL_VERSION}")
159 160 161 162 163 164 165 166
    set(MACOSX_BUNDLE_COPYRIGHT "(c) Petr Vanek <petr@yarpen.cz>")

    set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/macosx/qterminal.icns"
        PROPERTIES MACOSX_PACKAGE_LOCATION Resources
    )
    # use icon for app bundle to be visible in finder
    set(APPLE_BUNDLE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/macosx/qterminal.icns")
else()
167
    set(TRANSLATIONS_DIR "${CMAKE_INSTALL_FULL_DATADIR}/qterminal/translations")
168 169 170 171 172 173 174 175 176 177 178
    add_definitions(-DTRANSLATIONS_DIR=\"${TRANSLATIONS_DIR}\")
endif()

add_executable(${EXE_NAME} ${GUI_TYPE}
    ${QTERM_SRC}
    ${QTERM_UI}
    ${QTERM_MOC}
    ${QTERM_RCC}
    ${APPLE_BUNDLE_SOURCES}
    ${QTERM_QM}
)
179 180 181 182 183 184 185 186 187 188

target_compile_definitions(${EXE_NAME}
    PRIVATE
        "QT_USE_QSTRINGBUILDER"
        "QT_NO_CAST_FROM_ASCII"
        "QT_NO_CAST_TO_ASCII"
        "QT_NO_URL_CAST_FROM_STRING"
        "QT_NO_CAST_FROM_BYTEARRAY"
)

189
target_link_libraries(${EXE_NAME}
190 191
    Qt5::Gui
    qtermwidget5
192 193 194 195 196 197
    util
)
if(QXT_FOUND)
    target_link_libraries(${EXE_NAME} ${QXT_CORE_LIB} ${QXT_GUI_LIB})
endif()

198 199 200 201
if (Qt5DBus_FOUND)
    target_link_libraries(${EXE_NAME} ${Qt5DBus_LIBRARIES})
endif()

202 203
if(APPLE)
    target_link_libraries(${EXE_NAME} ${CARBON_LIBRARY})
204 205
elseif(UNIX)
    target_link_libraries(${EXE_NAME} Qt5::X11Extras)
206 207 208 209 210 211 212
endif()

if(X11_FOUND)
    target_link_libraries(${EXE_NAME} ${X11_X11_LIB})
endif()


213 214 215 216 217
install(FILES
    qterminal.desktop
    qterminal_drop.desktop
    DESTINATION "${CMAKE_INSTALL_DATADIR}/applications"
)
218

219 220 221 222
install(FILES
    qterminal.appdata.xml
    DESTINATION "${CMAKE_INSTALL_DATADIR}/appdata"
)
223 224

if(NOT APPLEBUNDLE)
225
    install(TARGETS ${EXE_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
226
    install(FILES ${QTERM_QM} DESTINATION ${TRANSLATIONS_DIR})
227
    install(FILES src/icons/qterminal.png DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/64x64/apps")
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
else()
    message(STATUS "APPLEBUNDLE")

    install(CODE "message(STATUS \"Cleaning previously installed bundle (rm -r)\")")
    install(CODE "execute_process(COMMAND rm -r ${CMAKE_INSTALL_PREFIX}/${EXE_NAME}.app)")

    install(TARGETS ${EXE_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}")

    # helper stuff to create real apple bundle.
    # Black magic is summoned here...
    if(APPLEBUNDLE_STANDALONE)
        message(STATUS "APPLEBUNDLE_STANDALONE")
        configure_file("${CMAKE_SOURCE_DIR}/bundle.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/bundle.cmake" @ONLY)
        install(SCRIPT "${CMAKE_SOURCE_DIR}/bundle.cmake")
    endif()

    # bundle required keytabs from the qtermwidget package as well
    install(CODE "message(STATUS \"Bundling (cp) keytab files from ${QTERMWIDGET_SHARE}/qtermwidget/\")")
    install(CODE "execute_process(COMMAND cp -r ${QTERMWIDGET_SHARE}/qtermwidget/ ${CMAKE_INSTALL_PREFIX}/${EXE_NAME}.app/Contents/Resources)")

    install(FILES ${QTERM_QM} DESTINATION ${CMAKE_INSTALL_PREFIX}/${EXE_NAME}.app/Contents/translations)
endif()