Skip to content

Commit 80e6181

Browse files
committed
Merge branch 'master' of github.com:ionyshch/cmake-qt5widgets-macos
2 parents a1ed73a + 09978cb commit 80e6181

File tree

2 files changed

+41
-84
lines changed

2 files changed

+41
-84
lines changed

CMakeLists.txt

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,81 @@
33
# using recommended cmake version, see http://doc.qt.io/qt-5/cmake-manual.html
44
cmake_minimum_required(VERSION 3.1.0)
55

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")
68
project(Qt5widgetsApp LANGUAGES CXX)
79

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-
2010
# Automatically add the current source- and build directories to the include path
2111
set(CMAKE_INCLUDE_CURRENT_DIR ON)
2212
set(CMAKE_AUTOMOC ON)
2313

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")
4017

41-
find_package(Qt5Widgets)
18+
find_package(Qt5 COMPONENTS Widgets REQUIRED)
4219

4320
add_executable(${PROJECT_NAME} MACOSX_BUNDLE "main.cpp" "mainwindow.cpp")
44-
qt5_use_modules(${PROJECT_NAME} Widgets)
21+
#qt5_use_modules(${PROJECT_NAME} Widgets)
4522

4623
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
4724

25+
# thus all files are visible in Projects view
4826
add_custom_target(Docs SOURCES README.md .gitignore LICENSE)
4927

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+
5051
# Destination paths below are relative to ${CMAKE_INSTALL_PREFIX}
5152
install(TARGETS ${PROJECT_NAME}
5253
BUNDLE DESTINATION . COMPONENT Runtime
5354
RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR} COMPONENT Runtime
5455
)
5556

5657
# 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")
5859

5960
# Directories to look for dependencies
6061
set(DIRS "${CMAKE_BINARY_DIR}")
6162

63+
# Path used for searching by FIND_XXX(), with appropriate suffixes added
6264
if(CMAKE_PREFIX_PATH)
6365
foreach(dir ${CMAKE_PREFIX_PATH})
6466
list(APPEND DIRS "${dir}/bin" "${dir}/lib")
6567
endforeach()
6668
endif()
6769

70+
# Append Qt's lib folder which is two levels above Qt5Widgets_DIR
71+
list(APPEND DIRS "${Qt5Widgets_DIR}/../..")
72+
6873
include(InstallRequiredSystemLibraries)
6974

75+
message(STATUS "APPS: ${APPS}")
76+
message(STATUS "QT_PLUGINS: ${QT_PLUGINS}")
77+
message(STATUS "DIRS: ${DIRS}")
78+
7079
install(CODE "include(BundleUtilities)
71-
fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")")
80+
fixup_bundle(\"${APPS}\" \"${QT_PLUGINS}\" \"${DIRS}\")")
7281

7382
set(CPACK_GENERATOR "DRAGNDROP")
7483
include(CPack)

cmake/InstallLocation.cmake

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)