|
3 | 3 | # using recommended cmake version, see http://doc.qt.io/qt-5/cmake-manual.html |
4 | 4 | cmake_minimum_required(VERSION 3.1.0) |
5 | 5 |
|
| 6 | +# CMAKE_OSX_DEPLOYMENT_TARGET must go before project() or enable_language() |
| 7 | +set(CMAKE_OSX_DEPLOYMENT_TARGET "10.10" CACHE STRING "Minimum OS X deployment version") |
6 | 8 | project(Qt5widgetsApp LANGUAGES CXX) |
7 | 9 |
|
8 | | -set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) |
9 | | - |
10 | | -# Request C++11 standard, using new CMake variables. |
11 | | -set(CMAKE_CXX_STANDARD 11) |
12 | | -set(CMAKE_CXX_STANDARD_REQUIRED True) |
13 | | -set(CMAKE_CXX_EXTENSIONS False) |
14 | | - |
15 | | -# Set symbol visibility defaults for all targets. |
16 | | -cmake_policy(SET CMP0063 NEW) |
17 | | -set(CMAKE_CXX_VISIBILITY_PRESET "hidden") |
18 | | -set(CMAKE_VISIBILITY_INLINES_HIDDEN True) |
19 | | - |
20 | 10 | # Automatically add the current source- and build directories to the include path |
21 | 11 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
22 | 12 | set(CMAKE_AUTOMOC ON) |
23 | 13 |
|
24 | | -# includes section |
25 | | -include(InstallLocation) |
26 | | - |
27 | | -# TODO set app version |
28 | | - |
29 | | -if(APPLE) |
30 | | - set(MACOSX_BUNDLE_NAME "${PROJECT_NAME}") |
31 | | - set(prefix "${MACOSX_BUNDLE_NAME}.app/Contents") |
32 | | - set(INSTALL_INCLUDE_DIR "${prefix}/${INSTALL_INCLUDE_DIR}") |
33 | | - set(INSTALL_RUNTIME_DIR "${prefix}/MacOS") |
34 | | - set(INSTALL_LIBRARY_DIR "${prefix}/${INSTALL_LIBRARY_DIR}") |
35 | | - set(INSTALL_ARCHIVE_DIR "${prefix}/${INSTALL_ARCHIVE_DIR}") |
36 | | - set(INSTALL_DATA_DIR "${prefix}/${INSTALL_DATA_DIR}") |
37 | | - set(INSTALL_DOC_DIR "${prefix}/${INSTALL_DOC_DIR}") |
38 | | - set(INSTALL_CMAKE_DIR "${prefix}/Resources") |
39 | | -endif() |
| 14 | +set(prefix "${PROJECT_NAME}.app/Contents") |
| 15 | +set(INSTALL_RUNTIME_DIR "${prefix}/MacOS") |
| 16 | +set(INSTALL_CMAKE_DIR "${prefix}/Resources") |
40 | 17 |
|
41 | | -find_package(Qt5Widgets) |
| 18 | +find_package(Qt5 COMPONENTS Widgets REQUIRED) |
42 | 19 |
|
43 | 20 | add_executable(${PROJECT_NAME} MACOSX_BUNDLE "main.cpp" "mainwindow.cpp") |
44 | | -qt5_use_modules(${PROJECT_NAME} Widgets) |
| 21 | +#qt5_use_modules(${PROJECT_NAME} Widgets) |
45 | 22 |
|
46 | 23 | target_link_libraries(${PROJECT_NAME} Qt5::Widgets) |
47 | 24 |
|
| 25 | +# thus all files are visible in Projects view |
48 | 26 | add_custom_target(Docs SOURCES README.md .gitignore LICENSE) |
49 | 27 |
|
| 28 | +# based on code from CMake's QtDialog/CMakeLists.txt |
| 29 | +macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var _prefix) |
| 30 | + get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION) |
| 31 | + if(EXISTS "${_qt_plugin_path}") |
| 32 | + get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME) |
| 33 | + get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH) |
| 34 | + get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME) |
| 35 | + set(_qt_plugin_dest "${_prefix}/PlugIns/${_qt_plugin_type}") |
| 36 | + install(FILES "${_qt_plugin_path}" |
| 37 | + DESTINATION "${_qt_plugin_dest}") |
| 38 | + set(${_qt_plugins_var} |
| 39 | + "${${_qt_plugins_var}};\$ENV{DEST_DIR}\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}") |
| 40 | + else() |
| 41 | + message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found") |
| 42 | + endif() |
| 43 | +endmacro() |
| 44 | + |
| 45 | +install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) |
| 46 | +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" |
| 47 | + "[Paths]\nPlugins = ${_qt_plugin_dir}\n") |
| 48 | +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" |
| 49 | + DESTINATION "${INSTALL_CMAKE_DIR}") |
| 50 | + |
50 | 51 | # Destination paths below are relative to ${CMAKE_INSTALL_PREFIX} |
51 | 52 | install(TARGETS ${PROJECT_NAME} |
52 | 53 | BUNDLE DESTINATION . COMPONENT Runtime |
53 | 54 | RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR} COMPONENT Runtime |
54 | 55 | ) |
55 | 56 |
|
56 | 57 | # Note Mac specific extension .app |
57 | | -set(APPS "\${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app") |
| 58 | +set(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app") |
58 | 59 |
|
59 | 60 | # Directories to look for dependencies |
60 | 61 | set(DIRS "${CMAKE_BINARY_DIR}") |
61 | 62 |
|
| 63 | +# Path used for searching by FIND_XXX(), with appropriate suffixes added |
62 | 64 | if(CMAKE_PREFIX_PATH) |
63 | 65 | foreach(dir ${CMAKE_PREFIX_PATH}) |
64 | 66 | list(APPEND DIRS "${dir}/bin" "${dir}/lib") |
65 | 67 | endforeach() |
66 | 68 | endif() |
67 | 69 |
|
| 70 | +# Append Qt's lib folder which is two levels above Qt5Widgets_DIR |
| 71 | +list(APPEND DIRS "${Qt5Widgets_DIR}/../..") |
| 72 | + |
68 | 73 | include(InstallRequiredSystemLibraries) |
69 | 74 |
|
| 75 | +message(STATUS "APPS: ${APPS}") |
| 76 | +message(STATUS "QT_PLUGINS: ${QT_PLUGINS}") |
| 77 | +message(STATUS "DIRS: ${DIRS}") |
| 78 | + |
70 | 79 | install(CODE "include(BundleUtilities) |
71 | | - fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")") |
| 80 | + fixup_bundle(\"${APPS}\" \"${QT_PLUGINS}\" \"${DIRS}\")") |
72 | 81 |
|
73 | 82 | set(CPACK_GENERATOR "DRAGNDROP") |
74 | 83 | include(CPack) |
0 commit comments