~mterry/qtmir/warn-on-xapp

« back to all changes in this revision

Viewing changes to CMakeLists.txt

  • Committer: Robert Carr
  • Date: 2014-09-17 20:40:39 UTC
  • mto: (250.4.57 cmake)
  • mto: This revision was merged to the branch mainline in revision 285.
  • Revision ID: robert.carr@canonical.com-20140917204039-40y2j5hm32cmscss
Begin on cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
cmake_minimum_required(VERSION 2.8.9)
 
2
 
 
3
project(qtmir)
 
4
 
 
5
set(QTMIR_VERSION_MAJOR 0)
 
6
set(QTMIR_VERSION_MINOR 1)
 
7
set(QTMIR_VERSION_PATCH 0)
 
8
 
 
9
if(${PROJECT_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
 
10
   message(FATAL_ERROR "In-tree build attempt detected, aborting. Set your build dir outside your source dir, delete CMakeCache.txt and CMakeFiles/ from source root and try again.")
 
11
endif()
 
12
 
 
13
# Find includes in corresponding build directories
 
14
set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
15
 
 
16
# add custom cmake modules
 
17
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
 
18
 
 
19
# Instruct CMake to run moc automatically when needed.
 
20
set(CMAKE_AUTOMOC ON)
 
21
 
 
22
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -pedantic -Wextra")
 
23
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fno-strict-aliasing -pedantic -Wextra")
 
24
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
 
25
 
 
26
 
 
27
include(EnableCoverageReport)
 
28
#####################################################################
 
29
# Enable code coverage calculation with gcov/gcovr/lcov
 
30
# Usage:
 
31
#  * Switch build type to coverage (use ccmake or cmake-gui)
 
32
#  * Invoke make, make test, make coverage (or ninja if you use that backend)
 
33
#  * Find html report in subdir coveragereport
 
34
#  * Find xml report feasible for jenkins in coverage.xml
 
35
#####################################################################
 
36
if(cmake_build_type_lower MATCHES coverage)
 
37
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage" )
 
38
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage" )
 
39
    set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage" )
 
40
    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage" )
 
41
    ENABLE_COVERAGE_REPORT(TARGETS ${SHELL_APP} FILTER /usr/include ${CMAKE_SOURCE_DIR}/tests/* ${CMAKE_BINARY_DIR}/*)
 
42
endif()
 
43
 
 
44
# Make sure we have all the needed symbols
 
45
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
 
46
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,defs")
 
47
 
 
48
# Static C++ checks
 
49
add_custom_target(cppcheck COMMAND cppcheck --enable=all -q --error-exitcode=2
 
50
                                       ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/tests)
 
51
 
 
52
include(FindPkgConfig)
 
53
find_package(Qt5Core 5.2 REQUIRED)
 
54
find_package(Qt5DBus 5.2 REQUIRED)
 
55
find_package(Qt5Gui 5.2 REQUIRED)
 
56
find_package(Qt5Qml 5.2 REQUIRED)
 
57
find_package(Qt5Quick 5.2 REQUIRED)
 
58
 
 
59
find_package(Threads REQUIRED)
 
60
find_package(Boost 1.50 COMPONENTS system REQUIRED)
 
61
 
 
62
find_package(Protobuf REQUIRED)
 
63
if(PROTOBUF_PROTOC_EXECUTABLE STREQUAL "PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND")
 
64
    message(SEND_ERROR "protoc executable not found! Missing protobuf-compiler package?")
 
65
endif()
 
66
 
 
67
pkg_check_modules(MIRSERVER mirserver REQUIRED)
 
68
pkg_check_modules(MIRCOMMON mircommon REQUIRED)
 
69
 
 
70
# detect if Qt compiled with GL or GLES
 
71
include(CheckCXXSourceCompiles)
 
72
check_cxx_source_compiles("
 
73
#include <QtCore/QtGlobal>
 
74
#if !defined(QT_OPENGL_ES)
 
75
#error \"No OpenGLES\"
 
76
#endif
 
77
int main() {}
 
78
" USE_OPENGLES)
 
79
 
 
80
if (USE_OPENGLES)
 
81
    message(STATUS "Qt5 determined to be compiled with GLES support")
 
82
    find_package(GLESv2 REQUIRED)
 
83
    add_definitions(-DQT_USING_GLES)
 
84
    include_directories (${GLESv2_INCLUDE_DIRS})
 
85
    set (GL_LIBRARIES "${GLESv2_LIBRARIES}")
 
86
 
 
87
else()
 
88
    message(STATUS "Qt5 determined to be compiled with OpenGL support")
 
89
    find_package(OpenGL REQUIRED)
 
90
    add_definitions(-DQT_USING_OPENGL)
 
91
    include_directories (${OpenGL_INCLUDE_DIRS})
 
92
    set (GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
 
93
endif()
 
94
 
 
95
# Standard install paths
 
96
include(GNUInstallDirs)
 
97
 
 
98
 
 
99
# Determine QPA plugin install path
 
100
# FIXME(greyback) there must be a better way than calling a private macro to set a property.
 
101
# I'm manually calling a macro from Qt5GuiConfig.cmake, but I don't understand why it isn't being called.
 
102
_populate_Gui_plugin_properties("Gui" "PLATFORMS" "platforms")
 
103
get_target_property(Qt5Gui_QPA_Plugin_Path Qt5::Gui IMPORTED_LOCATION_PLATFORMS)
 
104
 
 
105
# Determine install path for QML module
 
106
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=plugindir_suffix unity-shell-api OUTPUT_VARIABLE QTMIR_INSTALL_QML OUTPUT_STRIP_TRAILING_WHITESPACE)
 
107
if(SHELL_INSTALL_QML STREQUAL "")
 
108
    message(FATAL_ERROR "Could not determine plugin installation dir.")
 
109
endif()
 
110
 
 
111
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=plugindir unity-shell-api OUTPUT_VARIABLE QTMIR_PLUGINDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
 
112
if(SHELL_PLUGINDIR STREQUAL "")
 
113
    message(FATAL_ERROR "Could not determine plugin import dir.")
 
114
endif()
 
115
 
 
116
 
 
117
 
 
118
# Customisations for the build type
 
119
if(NOT CMAKE_BUILD_TYPE)
 
120
    message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
 
121
    set(CMAKE_BUILD_TYPE RelWithDebInfo)
 
122
endif()
 
123
 
 
124
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower)
 
125
 
 
126
if(cmake_build_type_lower MATCHES relwithdebinfo) # workaround for http://public.kitware.com/Bug/view.php?id=14696
 
127
    add_definitions(-DQT_NO_DEBUG)
 
128
endif()
 
129
if ("${CMAKE_BUILD_TYPE}" STREQUAL "release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "relwithdebinfo")
 
130
    option(Werror "Treat warnings as errors" ON)
 
131
else()
 
132
    option(Werror "Treat warnings as errors" OFF)
 
133
endif()
 
134
 
 
135
if (Werror)
 
136
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
 
137
endif()
 
138
 
 
139
 
 
140
# Mir uses boost, which does not like Qt defining macros named "signals" and "slots"
 
141
#add_definitions(-DQT_NO_KEYWORDS)
 
142
 
 
143
# Tests
 
144
include(CTest)
 
145
enable_testing()
 
146
 
 
147
 
 
148
# add subdirectories to build
 
149
add_subdirectory(src)
 
150
#add_subdirectory(demos)
 
151