make building GUI optional

This commit is contained in:
Martchus 2016-04-07 23:51:12 +02:00
parent b6a636cf8a
commit 1759bfd0bd
1 changed files with 128 additions and 95 deletions

View File

@ -170,81 +170,99 @@ if(MINGW)
endif(MINGW)
# read cached variables
set(JS_PROVIDER "auto" CACHE STRING "specifies the JavaScript provider: auto, qml or script")
set(WEBVIEW_PROVIDER "auto" CACHE STRING "specifies the webview provider: auto, webkit or webengine")
set(WIDGETS_GUI "yes" CACHE STRING "enables/disables building the Qt Widgets GUI: yes (default) or no")
set(JS_PROVIDER "auto" CACHE STRING "specifies the JavaScript provider: auto (default), qml or script")
set(WEBVIEW_PROVIDER "auto" CACHE STRING "specifies the webview provider: auto (default), webkit or webengine")
if(${WIDGETS_GUI} STREQUAL "yes")
message(STATUS "Building with Qt Widgets GUI.")
elseif(${WIDGETS_GUI} STREQUAL "no")
message(STATUS "Building WITHOUT Qt Widgets GUI.")
else()
message(FATAL_ERROR "Specification whether to build with Qt Widgets GUI is invalid (must be either yes or no).")
endif()
# check required Qt 5 modules
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt5Concurrent REQUIRED)
find_package(Qt5Network REQUIRED)
# select Qt module providing JavaScript (either Qt Script or Qt Qml)
if(${JS_PROVIDER} STREQUAL "auto")
find_package(Qt5Script)
if(Qt5Script_FOUND)
set(JS_PROVIDER Qt5::Script)
message(STATUS "No JavaScript provider explicitely specified, defaulting to Qt Script.")
if(${WIDGETS_GUI} STREQUAL "yes")
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt5Concurrent REQUIRED)
find_package(Qt5Network REQUIRED)
set(WIDGETS_LIBS Qt5::Core Qt5::Widgets Qt5::Concurrent Qt5::Network)
# select Qt module providing JavaScript (either Qt Script or Qt Qml)
if(${JS_PROVIDER} STREQUAL "auto")
find_package(Qt5Script)
if(Qt5Script_FOUND)
set(JS_PROVIDER Qt5::Script)
message(STATUS "No JavaScript provider explicitely specified, defaulting to Qt Script.")
else()
find_package(Qt5Qml REQUIRED)
set(JS_PROVIDER Qt5::Qml)
message(STATUS "No JavaScript provider explicitely specified, defaulting to Qt Qml.")
endif()
else()
find_package(Qt5Qml REQUIRED)
set(JS_PROVIDER Qt5::Qml)
message(STATUS "No JavaScript provider explicitely specified, defaulting to Qt Qml.")
if(${JS_PROVIDER} STREQUAL "script")
find_package(Qt5Script REQUIRED)
set(JS_PROVIDER Qt5::Script)
message(STATUS "Using Qt Script as JavaScript provider.")
elseif(${JS_PROVIDER} STREQUAL "qml")
find_package(Qt5Qml REQUIRED)
set(JS_PROVIDER Qt5::Qml)
set(JS_DEFINITION -DTAGEDITOR_USE_JSENGINE)
message(STATUS "Using Qt Qml as JavaScript provider.")
else()
message(FATAL_ERROR "The specified JavaScript provider '${JS_PROVIDER}' is unknown.")
endif()
endif()
else()
if(${JS_PROVIDER} STREQUAL "script")
find_package(Qt5Script REQUIRED)
set(JS_PROVIDER Qt5::Script)
message(STATUS "Using Qt Script as JavaScript provider.")
elseif(${JS_PROVIDER} STREQUAL "qml")
find_package(Qt5Qml REQUIRED)
set(JS_PROVIDER Qt5::Qml)
set(JS_DEFINITION -DTAGEDITOR_USE_JSENGINE)
message(STATUS "Using Qt Qml as JavaScript provider.")
# select Qt module providing webview (either Qt WebKit or Qt WebEngine)
if(${WEBVIEW_PROVIDER} STREQUAL "auto")
find_package(Qt5WebKitWidgets)
if(Qt5WebKitWidgets_FOUND)
set(WEBVIEW_PROVIDER Qt5::WebKitWidgets)
message(STATUS "No webview provider explicitely specified, defaulting to Qt WebKit.")
else()
find_package(Qt5WebEngineWidgets REQUIRED)
set(WEBVIEW_PROVIDER Qt5::WebEngineWidgets)
set(WEBVIEW_DEFINITION -DTAGEDITOR_USE_WEBENGINE)
message(STATUS "No webview provider explicitely specified, defaulting to Qt WebEngine.")
endif()
else()
message(FATAL_ERROR "The specified JavaScript provider '${JS_PROVIDER}' is unknown.")
endif()
endif()
# select Qt module providing webview (either Qt WebKit or Qt WebEngine)
if(${WEBVIEW_PROVIDER} STREQUAL "auto")
find_package(Qt5WebKitWidgets)
if(Qt5WebKitWidgets_FOUND)
set(WEBVIEW_PROVIDER Qt5::WebKitWidgets)
message(STATUS "No webview provider explicitely specified, defaulting to Qt WebKit.")
else()
find_package(Qt5WebEngineWidgets REQUIRED)
set(WEBVIEW_PROVIDER Qt5::WebEngineWidgets)
set(WEBVIEW_DEFINITION -DTAGEDITOR_USE_WEBENGINE)
message(STATUS "No webview provider explicitely specified, defaulting to Qt WebEngine.")
endif()
else()
if(${WEBVIEW_PROVIDER} STREQUAL "webkit")
find_package(Qt5WebKitWidgets REQUIRED)
set(WEBVIEW_PROVIDER Qt5::WebKitWidgets)
message(STATUS "Using Qt WebKit as webview provider.")
elseif(${WEBVIEW_PROVIDER} STREQUAL "webengine")
find_package(Qt5WebEngineWidgets REQUIRED)
set(WEBVIEW_PROVIDER Qt5::WebEngineWidgets)
set(WEBVIEW_DEFINITION -DTAGEDITOR_USE_WEBENGINE)
message(STATUS "Using Qt WebEngine as webview provider.")
elseif(${WEBVIEW_PROVIDER} STREQUAL "none")
set(WEBVIEW_DEFINITION -DTAGEDITOR_NO_WEBVIEW)
message(STATUS "Webview has been disabled.")
else()
message(FATAL_ERROR "The specified webview provider '${WEBVIEW_PROVIDER}' is unknown.")
if(${WEBVIEW_PROVIDER} STREQUAL "webkit")
find_package(Qt5WebKitWidgets REQUIRED)
set(WEBVIEW_PROVIDER Qt5::WebKitWidgets)
message(STATUS "Using Qt WebKit as webview provider.")
elseif(${WEBVIEW_PROVIDER} STREQUAL "webengine")
find_package(Qt5WebEngineWidgets REQUIRED)
set(WEBVIEW_PROVIDER Qt5::WebEngineWidgets)
set(WEBVIEW_DEFINITION -DTAGEDITOR_USE_WEBENGINE)
message(STATUS "Using Qt WebEngine as webview provider.")
elseif(${WEBVIEW_PROVIDER} STREQUAL "none")
set(WEBVIEW_DEFINITION -DTAGEDITOR_NO_WEBVIEW)
message(STATUS "Webview has been disabled.")
else()
message(FATAL_ERROR "The specified webview provider '${WEBVIEW_PROVIDER}' is unknown.")
endif()
endif()
endif()
# enable Qt Widgets GUI
if(${WIDGETS_GUI} STREQUAL "yes")
add_definitions(
-DGUI_QTWIDGETS
-DMODEL_UNDO_SUPPORT
${JS_DEFINITION}
${WEBVIEW_DEFINITION}
)
endif()
# disable new ABI (can't catch ios_base::failure with new ABI)
# enable code for debugging
add_definitions(
-DGUI_QTWIDGETS
-DMODEL_UNDO_SUPPORT
-D_GLIBCXX_USE_CXX11_ABI=0
${JS_DEFINITION}
${WEBVIEW_DEFINITION}
)
# enable code for debugging
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG_BUILD)
message(STATUS "Debug build enabled.")
@ -252,17 +270,26 @@ endif()
# enable moc, uic and rcc
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(${WIDGETS_GUI} STREQUAL "yes")
set(CMAKE_AUTOUIC ON)
endif()
# enable lrelease
qt5_add_translation(QM_FILES ${TS_FILES})
add_custom_target(translations ALL DEPENDS ${QM_FILES})
if(${WIDGETS_GUI} STREQUAL "yes")
qt5_add_translation(QM_FILES ${TS_FILES})
add_custom_target(translations ALL DEPENDS ${QM_FILES})
endif()
# stuff which is only required when building Qt GUI
if(${WIDGETS_GUI} STREQUAL "yes")
set(WIDGETS_STUFF ${GUI_TYPE} ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES} ${WIDGETS_UI_FILES} ${QM_FILES} ${RES_FILES})
endif()
# executable and linking
add_executable(${META_PROJECT_NAME} ${GUI_TYPE} ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES} ${WIDGETS_UI_FILES} ${QM_FILES} ${RES_FILES} ${WINDOWS_ICON_PATH})
target_link_libraries(${META_PROJECT_NAME} c++utilities qtutilities tagparser Qt5::Core Qt5::Widgets Qt5::Concurrent Qt5::Network ${JS_PROVIDER} ${WEBVIEW_PROVIDER})
add_executable(${META_PROJECT_NAME} ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_STUFF} ${WINDOWS_ICON_PATH})
target_link_libraries(${META_PROJECT_NAME} c++utilities qtutilities tagparser ${WIDGETS_LIBS} ${JS_PROVIDER} ${WEBVIEW_PROVIDER})
set_target_properties(${META_PROJECT_NAME} PROPERTIES
CXX_STANDARD 11
)
@ -272,43 +299,49 @@ install(TARGETS ${META_PROJECT_NAME}
RUNTIME DESTINATION bin
COMPONENT binary
)
install(FILES resources/icons/hicolor/scalable/apps/${META_PROJECT_NAME}.svg
DESTINATION share/icons/hicolor/scalable/apps
COMPONENT desktop
)
install(FILES resources/desktop/applications/${META_PROJECT_NAME}.desktop
DESTINATION share/applications
COMPONENT desktop
)
install(FILES resources/desktop/applications/${META_PROJECT_NAME}-renamingutility.desktop
DESTINATION share/applications
COMPONENT desktop
)
install(FILES ${QM_FILES}
DESTINATION share/${META_PROJECT_NAME}/translations
COMPONENT localization
)
if(${WIDGETS_GUI} STREQUAL "yes")
install(FILES resources/icons/hicolor/scalable/apps/${META_PROJECT_NAME}.svg
DESTINATION share/icons/hicolor/scalable/apps
COMPONENT desktop
)
install(FILES resources/desktop/applications/${META_PROJECT_NAME}.desktop
DESTINATION share/applications
COMPONENT desktop
)
install(FILES resources/desktop/applications/${META_PROJECT_NAME}-renamingutility.desktop
DESTINATION share/applications
COMPONENT desktop
)
install(FILES ${QM_FILES}
DESTINATION share/${META_PROJECT_NAME}/translations
COMPONENT localization
)
endif()
if(NOT TARGET install-binary)
add_custom_target(install-binary
DEPENDS ${META_PROJECT_NAME}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=binary -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
endif()
if(NOT TARGET install-desktop)
add_custom_target(install-desktop
DEPENDS ${META_PROJECT_NAME}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=desktop -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
endif()
if(NOT TARGET install-localization)
add_custom_target(install-localization
DEPENDS ${META_PROJECT_NAME}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=localization -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
if(${WIDGETS_GUI} STREQUAL "yes")
if(NOT TARGET install-desktop)
add_custom_target(install-desktop
DEPENDS ${META_PROJECT_NAME}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=desktop -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
endif()
# localization isn't provided for the command line interface
if(NOT TARGET install-localization)
set(LOCALIZATION_TARGET "install-localization")
add_custom_target(install-localization
DEPENDS ${META_PROJECT_NAME}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=localization -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
endif()
endif()
if(NOT TARGET install-mingw-w64)
add_custom_target(install-mingw-w64
DEPENDS install-binary install-localization
DEPENDS install-binary ${LOCALIZATION_TARGET}
)
endif()
if(NOT TARGET install-binary-strip)
@ -319,6 +352,6 @@ if(NOT TARGET install-binary-strip)
endif()
if(NOT TARGET install-mingw-w64-strip)
add_custom_target(install-mingw-w64-strip
DEPENDS install-binary-strip install-localization
DEPENDS install-binary-strip ${LOCALIZATION_TARGET}
)
endif()