1
by Michi Henning
Initial check-in of build-environment skeleton. |
1 |
cmake_minimum_required(VERSION 2.8.10) |
2 |
||
3 |
# Default install location. Must be set here, before setting the project.
|
|
4 |
if (NOT DEFINED CMAKE_INSTALL_PREFIX) |
|
5 |
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "" FORCE) |
|
6 |
endif() |
|
7 |
||
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
8 |
project(unity-api C CXX) |
9 |
||
10 |
if(${PROJECT_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) |
|
11 |
message(FATAL_ERROR "In-tree build attempt detected, aborting. Set your build dir outside your source dir, delete CMakeCache.txt from source root and try again.") |
|
12 |
endif() |
|
13 |
||
14 |
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) |
|
15 |
||
16 |
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower) # Build types should always be lowercase but sometimes they are not. |
|
17 |
||
61.1.4
by Jussi Pakkanen
Added documentation to precompiled header module. |
18 |
include(PrecompiledHeaders) |
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
19 |
include(EnableCoverageReport) |
20 |
#####################################################################
|
|
21 |
# Enable code coverage calculation with gcov/gcovr/lcov
|
|
22 |
# Usage:
|
|
23 |
# * Switch build type to coverage (use ccmake or cmake-gui)
|
|
24 |
# * Invoke make, make test, make coverage (or ninja if you use that backend)
|
|
25 |
# * Find html report in subdir coveragereport
|
|
43.1.2
by Michi Henning
Made daemonize_me() more robust when called at the file descriptor limit and |
26 |
# * Find xml report suitable for jenkins in coverage.xml
|
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
27 |
#####################################################################
|
28 |
if(cmake_build_type_lower MATCHES coverage) |
|
29 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage" ) |
|
30 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage" ) |
|
31 |
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage" ) |
|
32 |
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage" ) |
|
43.1.2
by Michi Henning
Made daemonize_me() more robust when called at the file descriptor limit and |
33 |
|
52.1.1
by Michi Henning
Added -g to compile flags when building for coverage. That way, valgrind and gdb will report line numbers. |
34 |
# We add -g when building with coverage so valgrind reports line numbers.
|
35 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g" ) |
|
36 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" ) |
|
37 |
||
43.1.2
by Michi Henning
Made daemonize_me() more robust when called at the file descriptor limit and |
38 |
# This allows us to skip the file descriptor closing test in Daemon_test
|
39 |
# when coverage is enabled. (Closing file descriptors
|
|
40 |
# in the test messes with coverage reporting.)
|
|
41 |
add_definitions(-DCOVERAGE_ENABLED) |
|
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
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
|
|
39.1.1
by Michi Henning
Added generated tests to cppcheck so we don't get bogus reports for unused functions. |
49 |
|
55.1.1
by Michi Henning
Added warning if cppcheck isn't found. |
50 |
find_program(CPPCHECK_COMMAND NAMES cppcheck) |
51 |
if (CPPCHECK_COMMAND) |
|
52 |
set(CPPCHECK_COMMAND_OPTIONS --check-config --inline-suppr --enable=all -q --error-exitcode=2) |
|
110.1.1
by Albert Astals
Avoid cmake warnings |
53 |
set(CPPCHECK_COMMAND_OPTIONS ${CPPCHECK_COMMAND_OPTIONS} --template "{file}({line}): {severity} ({id}): {message}") |
55.1.1
by Michi Henning
Added warning if cppcheck isn't found. |
54 |
add_custom_target(cppcheck COMMAND ${CPPCHECK_COMMAND} ${CPPCHECK_COMMAND_OPTIONS} |
55 |
${CMAKE_SOURCE_DIR}/src |
|
56 |
${CMAKE_SOURCE_DIR}/test |
|
57 |
${CMAKE_BINARY_DIR}/test |
|
110.1.1
by Albert Astals
Avoid cmake warnings |
58 |
VERBATIM
|
55.1.1
by Michi Henning
Added warning if cppcheck isn't found. |
59 |
)
|
60 |
else() |
|
61 |
message(WARNING "Cannot find cppcheck: cppcheck target will not be available") |
|
62 |
endif() |
|
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
63 |
|
64 |
#
|
|
65 |
# Definitions for testing with valgrind.
|
|
66 |
#
|
|
67 |
||
68 |
configure_file(CTestCustom.cmake.in CTestCustom.cmake) # Tests in CTestCustom.cmake are skipped for valgrind |
|
69 |
||
70 |
find_program(MEMORYCHECK_COMMAND NAMES valgrind) |
|
71 |
if (MEMORYCHECK_COMMAND) |
|
72 |
set(MEMORYCHECK_COMMAND_OPTIONS |
|
73 |
"--suppressions=${CMAKE_SOURCE_DIR}/valgrind-suppress --leak-check=full --num-callers=40 --error-exitcode=3"
|
|
74 |
)
|
|
75 |
add_custom_target(valgrind DEPENDS NightlyMemCheck) |
|
76 |
else() |
|
77 |
message(WARNING "Cannot find valgrind: valgrind target will not be available") |
|
78 |
endif() |
|
79 |
||
80 |
||
81 |
include(FindPkgConfig) |
|
52.2.1
by Jussi Pakkanen
Added class to do ini file parsing. |
82 |
pkg_check_modules(GLIB glib-2.0 REQUIRED) |
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
83 |
|
84 |
# Standard install paths
|
|
85 |
include(GNUInstallDirs) |
|
86 |
||
111.1.1
by Michal Hruby
Add pkg-config variable to get plugin directory |
87 |
# Shell install paths
|
88 |
set(SHELL_PLUGINDIR ${CMAKE_INSTALL_LIBDIR}/unity8/qml) |
|
89 |
||
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
90 |
include_directories( |
91 |
${CMAKE_CURRENT_BINARY_DIR} |
|
92 |
${CMAKE_CURRENT_BINARY_DIR}/include |
|
93 |
${CMAKE_CURRENT_SOURCE_DIR} |
|
94 |
${CMAKE_CURRENT_SOURCE_DIR}/include |
|
95 |
)
|
|
96 |
||
97 |
# When building the library, we set the default symbol visibility
|
|
98 |
# to "hidden", so we don't export things by default.
|
|
99 |
# Exported functions and classes are prefixed by a UNITY_API macro,
|
|
100 |
# which explicitly exports a symbol if UNITY_DLL_EXPORTS is defined.
|
|
101 |
add_definitions(-DUNITY_DLL_EXPORTS) |
|
102 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") |
|
1
by Michi Henning
Initial check-in of build-environment skeleton. |
103 |
|
107.1.1
by Michi Henning
Don't -fno-permissive when compiling with clang because clang produces an "ignored" warning for this flag. |
104 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall -Wextra") |
105 |
||
106 |
# -fno-permissive causes warnings with clang, so we only enable it for gcc
|
|
107 |
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
|
108 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-permissive") |
|
238.19.1
by Albert Astals Cid
Enable -Wsuggest-override |
109 |
|
110 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") |
|
111 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override" ) |
|
112 |
endif() |
|
107.1.1
by Michi Henning
Don't -fno-permissive when compiling with clang because clang produces an "ignored" warning for this flag. |
113 |
endif() |
17
by Michi Henning
More cleanup for cmake. |
114 |
|
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
115 |
if ("${CMAKE_BUILD_TYPE}" STREQUAL "release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "relwithdebinfo") |
17
by Michi Henning
More cleanup for cmake. |
116 |
option(Werror "Treat warnings as errors" ON) |
117 |
else() |
|
118 |
option(Werror "Treat warnings as errors" OFF) |
|
119 |
endif() |
|
120 |
||
121 |
if (Werror) |
|
122 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") |
|
123 |
endif() |
|
1
by Michi Henning
Initial check-in of build-environment skeleton. |
124 |
|
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
125 |
# API version
|
126 |
set(UNITY_API_MAJOR 0) |
|
75.1.11
by Michael Zanetti
bump only the launcher version, not the API's minor version |
127 |
set(UNITY_API_MINOR 1) |
213.2.8
by Marcus Tomlinson
Bump |
128 |
set(UNITY_API_MICRO 6) |
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
129 |
set(UNITY_API_VERSION "${UNITY_API_MAJOR}.${UNITY_API_MINOR}.${UNITY_API_MICRO}") |
130 |
||
131 |
# API library
|
|
16
by Michi Henning
Added new api namespace and adjusted tree structure. Many cleanups on the cmake files. |
132 |
set(UNITY_API_LIB unity-api) |
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
133 |
|
60.2.1
by Michi Henning
This changes the build environment to link the tests against a static version of the library, allows us to write unit tests for internal classes that are not visible through the public API. |
134 |
# Static version for testing
|
135 |
set(UNITY_API_STATIC_LIB unity-api-static) |
|
136 |
||
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
137 |
# Other libraries we depend on
|
92.1.1
by Jussi Pakkanen
Use glibc's memory checker. |
138 |
set(OTHER_API_LIBS) |
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
139 |
|
140 |
# All the libraries we need to link a normal executable that uses the Unity API
|
|
141 |
set(LIBS ${UNITY_API_LIB} ${OTHER_API_LIBS}) |
|
142 |
||
60.2.1
by Michi Henning
This changes the build environment to link the tests against a static version of the library, allows us to write unit tests for internal classes that are not visible through the public API. |
143 |
# All the libraries we need to link a gtest executable. (We link the tests against a static version
|
144 |
# so we can do whitebox testing on internal classes.
|
|
170.1.1
by Michi Henning
Reverted commit 93 because it cost me a cool 1.5 hours today. |
145 |
set(TESTLIBS ${UNITY_API_STATIC_LIB} ${OTHER_API_LIBS}) |
60.2.1
by Michi Henning
This changes the build environment to link the tests against a static version of the library, allows us to write unit tests for internal classes that are not visible through the public API. |
146 |
|
32.3.2
by Michał Sawicz
enable multiarch installation |
147 |
# Library install prefix
|
148 |
set(LIB_INSTALL_PREFIX lib/${CMAKE_LIBRARY_ARCHITECTURE}) |
|
149 |
||
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
150 |
# Tests
|
174.3.1
by Daniel d'Andrada
Add a NO_TESTS options to cmake |
151 |
if (NOT NO_TESTS) |
152 |
include(CTest) |
|
153 |
enable_testing() |
|
154 |
add_subdirectory(test) |
|
155 |
else() |
|
156 |
message(STATUS "Tests disabled") |
|
157 |
endif() |
|
1
by Michi Henning
Initial check-in of build-environment skeleton. |
158 |
|
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
159 |
# add subdirectories to build
|
160 |
add_subdirectory(include) |
|
161 |
add_subdirectory(src) |
|
111.1.1
by Michal Hruby
Add pkg-config variable to get plugin directory |
162 |
add_subdirectory(data) |
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
163 |
|
164 |
if (cmake_build_type_lower MATCHES coverage) |
|
165 |
ENABLE_COVERAGE_REPORT(TARGETS ${UNITY_API_LIB} FILTER /usr/include ${CMAKE_SOURCE_DIR}/test/* ${CMAKE_BINARY_DIR}/*) |
|
166 |
endif() |
|
167 |
||
1
by Michi Henning
Initial check-in of build-environment skeleton. |
168 |
#
|
169 |
# Documentation
|
|
170 |
#
|
|
171 |
||
172 |
find_package(Doxygen) |
|
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
173 |
find_program(DOT_EXECUTABLE dot /usr/bin) |
174 |
if (NOT DOXYGEN_FOUND OR NOT DOT_EXECUTABLE) |
|
175 |
message(WARNING "Cannot generate documentation: doxygen and/or graphviz not found") |
|
18.1.2
by Jussi Pakkanen
Do not require Doxygen. |
176 |
else() |
32.2.1
by Michał Sawicz
bring changes from lp:unity/phablet in bulk |
177 |
configure_file(${PROJECT_SOURCE_DIR}/doc/Doxyfile.in ${PROJECT_BINARY_DIR}/doc/Doxyfile @ONLY IMMEDIATE) |
178 |
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/doc/lib${UNITY_API_LIB}/index.html |
|
179 |
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/doc/Doxyfile |
|
180 |
DEPENDS ${PROJECT_BINARY_DIR}/doc/Doxyfile |
|
181 |
${UNITY_API_LIB_SRC} |
|
182 |
${UNITY_API_LIB_HDRS}) |
|
183 |
add_custom_target(doc ALL |
|
184 |
DEPENDS ${PROJECT_BINARY_DIR}/doc/lib${UNITY_API_LIB}/index.html) |
|
185 |
install(DIRECTORY ${PROJECT_BINARY_DIR}/doc/lib${UNITY_API_LIB} |
|
186 |
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc) |
|
1
by Michi Henning
Initial check-in of build-environment skeleton. |
187 |
endif() |