aboutsummaryrefslogtreecommitdiff
path: root/modules/ECMQtFramework.cmake
blob: fdbb6de99e9605e9b4fb8b505f27c6a8adb59d0c (plain)
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
#- Automatic configuration of a project as a Qt framework.
#
# This module can be used to simplify creation of quality frameworks written in Qt.
# It sets compiler flags, Qt definitions and CMake options which make sense to use when creating
# A Qt based framework.
#
#  project(myspeciallib)
#  ecm_framework_version(5 0 0)
#  include(ECMQtFramework)
#
# This will set myspeciallib to be a Qt framework, that is, the name of the project is
# relevant and used (see below). The version of the project is 5.0.0. It is important to
# include ECMQtFramework before finding Qt itself.
#
# Specifically being an ECM Qt framework means:
#
# 1) The compiler is configured with export flags. With GCC and clang, this means enabling
# the -hidden-visibility flags. See the GenerateExportHeader module for more on generating
# and installing export headers.
#
# 2) A Coverage build type is created and made available in the cmake-gui. This means that
# running
#
#  cmake $SRCDIR -DCMAKE_BUILD_TYPE=Coverage
#
# Will enable the use of the -fprofile-arcs -ftest-coverage flags on GCC. The Coverage type is also
# available through the cmake-gui program.
#
# 3) Sensible compiler warnings are enabled. These are the flags determined to be useful through
# a history in KDE buildsystem.
#
# 4) Qt build flags are defined.
# These include
#
# * Disabling automatic ascii casts provided by Qt (so for example QLatin1String must be used). This is
# relevant to prevent encoding errors, and makes conversion to QString potentially faster or avoidable.
#
# * Disabling Qt keywords such as signals and slots so that Q_SIGNALS and Q_SLOTS must be used instead. This
# is relevant if using the framework together with boost signals.
#
# * Enabling the use of fast concatenation. This makes it possible to create strings from multiple pieces
# with one memory allocation.
#
# 5) CMake will use imported targets for Qt. This is relevant on windows because it is easier
# to build both debug and release versions of the framework.
#
# 6) CMake will include the current source and binary directories automatically while preprocessing. The
# source and binary directories of the current project will be used before others.
#
# 7) CMake will use built in automatic moc support.
#
# 8) A LIB_SUFFIX variable is made available. This is used to install libraries optionally
# to for example /lib64 instead of /lib
#
# 9) The ECM_TARGET_DEFAULT_ARGS variable is made available for use by targets in the framework. This is
# used in install(TARGETS) calls to install components of targets to the configured binary and library directories,
# to create an export target for the framework, and to put them in a component for use with CPack. The name of the
# component is the same as the argument to the project call (myspeciallib above).
#
# 10) The use of RPATH is enabled. (TODO RUNPATH?)
#
# 11) A CMake config file and config version are created and installed. The config file uses the project name so that:
#
# * The file is called myspeciallibConfig.cmake. A companion file myspeciallibVersionConfig is also created.
#
# * The variables myspeciallib_VERSION_MAJOR, myspeciallib_VERSION_MINOR, myspeciallib_VERSION_PATCH are defined
# as specified by the use of ecm_framework_version.
#
# * Standard variables are set for linking to the library and including the directories of its headers.
#
# 12) The targets file is installed. This means that myspeciallib can be used as an imported target.
#
# 13) A version file is created called myspeciallib_version.h, which contains version information usable by
# the preprocessor. The version file must be installed by the user.
#
# 14) The FeatureSummary module is included.
#
# 15) The CMAKE_LINK_INTERFACE_LIBRARIES variable is set to empty. This means that the library targets created
# will have an empty link interface unless the LINK_INTERFACE_LIBRARIES or the LINK_PUBLIC keyword
# to target_link_libraries are used.

# We need to make sure this file is included before Qt found.
# Otherwise QT_USE_IMPORTED_TARGETS would have no effect.
# ### Temporarily disabled until KDE Frameworks includes this file before finding Qt.
# if (QT4_FOUND)
#   message(SEND_ERROR "This file must be included before finding the Qt package.")
# endif()


include(FeatureSummary)

set(LIBRARY_TYPE SHARED)

set(ECM_TARGET_DEFAULT_ARGS
#   EXPORT ${PROJECT_NAME}LibraryTargets
  RUNTIME DESTINATION "${BIN_INSTALL_DIR}" COMPONENT ${PROJECT_NAME}
  LIBRARY DESTINATION "${LIB_INSTALL_DIR}" COMPONENT ${PROJECT_NAME}
  ARCHIVE DESTINATION "${LIB_INSTALL_DIR}" COMPONENT ${PROJECT_NAME}
)

set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/${PROJECT_NAME}")

include(CMakePackageConfigHelpers)

configure_package_config_file(
  "${CMAKE_CURRENT_LIST_DIR}/ECMQtFrameworkConfig.cmake.in"
  "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  INSTALL_DESTINATION  ${CMAKECONFIG_INSTALL_DIR}
  PATH_VARS  INCLUDE_INSTALL_DIR LIB_INSTALL_DIR CMAKE_INSTALL_PREFIX
)

include(WriteBasicConfigVersionFile)

write_basic_config_version_file("${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
  VERSION ${ECM_VERSION_MAJOR}.${ECM_VERSION_MINOR}.${ECM_VERSION_PATCH}
  COMPATIBILITY AnyNewerVersion
)

install(FILES
  "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
  DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
  COMPONENT Devel
)

# Disabled for now, as long as kdelibs is one big module
#install(EXPORT ${PROJECT_NAME}LibraryTargets
  #DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
  #FILE ${PROJECT_NAME}Targets.cmake
  #COMPONENT Devel
#)

string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)

configure_file(
  "${CMAKE_CURRENT_LIST_DIR}/ECMVersionHeader.h.in"
  "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_version.h"
)