Merge lp:~jpakkane/unity/pch-experiment into lp:unity

Proposed by Jussi Pakkanen
Status: Rejected
Rejected by: Jussi Pakkanen
Proposed branch: lp:~jpakkane/unity/pch-experiment
Merge into: lp:unity
Diff against target: 169 lines (+114/-3)
5 files modified
CMakeLists.txt (+2/-0)
UnityCore/CMakeLists.txt (+6/-2)
UnityCore/FilesystemLenses.cpp (+1/-1)
UnityCore/pch/unitycore_pch.hh (+33/-0)
pch.cmake (+72/-0)
To merge this branch: bzr merge lp:~jpakkane/unity/pch-experiment
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+128467@code.launchpad.net

Description of the change

Do NOT merge this code as is! It is only a proof of concept. It will compile and run but the end result will not work properly, because I had to change some definitions.

That being said, this patch adds support for GCC precompiled headers, which cuts down compile times quite nicely. To try it out, just check out and configure. Then run 'time make unity-core-6.0'. There is a CMake option for compiling with or without PCH. Just toggle that and run 'make clean' and then the previous command to compare build times.

On my machine building in debug mode without PCH takes 1m 50s. Enabling PCH drops that to 1 minute.

To get this merged, the build system needs a changes (which would be good even by themselves), enabling PCH for all targets and probably some general cleanup. None of these are massive tasks, though.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Changing to WIP so this MP doesn't sit in the review queue.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

(Some of) the build fixes necessary are in this MP:

https://code.launchpad.net/~jpakkane/unity/build-fixes2/+merge/130329

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2012-10-04 07:10:39 +0000
3+++ CMakeLists.txt 2012-10-08 11:22:21 +0000
4@@ -23,6 +23,8 @@
5 ON
6 )
7
8+include(pch.cmake)
9+
10 if(UNITY_ENABLE_X_ORG_SUPPORT)
11 add_definitions(-DUNITY_HAS_X_ORG_SUPPORT)
12 message("Unity is configured with support for X.org")
13
14=== modified file 'UnityCore/CMakeLists.txt'
15--- UnityCore/CMakeLists.txt 2012-08-31 13:12:35 +0000
16+++ UnityCore/CMakeLists.txt 2012-10-08 11:22:21 +0000
17@@ -99,10 +99,12 @@
18 ${CORE_DEPS_CFLAGS_OTHER}
19 ${MAINTAINER_CFLAGS}
20 "-I${CMAKE_BINARY_DIR}"
21- "-DGETTEXT_PACKAGE=\"unity\""
22- "-DLENSES_DIR=\"${_lensesdir}\""
23 )
24 add_definitions (${CFLAGS})
25+#add_definitions("-DGETTEXT_PACKAGE=\"unity\"")
26+#add_definitions("-DLENSES_DIR=\"${_lensesdir}\"")
27+
28+message(STATUS ${CFLAGS})
29
30 set (LIBS ${CORE_DEPS_LIBRARIES})
31
32@@ -133,6 +135,8 @@
33 SOVERSION ${CORE_LIB_LT_CURRENT}
34 INSTALL_RPATH "${PRIVATE_CORE_DEPS_LIBRARY_DIRS}")
35
36+add_pch(pch/unitycore_pch.hh ${CORE_LIB_NAME})
37+
38 install (TARGETS ${CORE_LIB_NAME}
39 RUNTIME DESTINATION bin
40 ARCHIVE DESTINATION lib
41
42=== modified file 'UnityCore/FilesystemLenses.cpp'
43--- UnityCore/FilesystemLenses.cpp 2012-06-18 02:57:23 +0000
44+++ UnityCore/FilesystemLenses.cpp 2012-10-08 11:22:21 +0000
45@@ -331,7 +331,7 @@
46
47 LensDirectoryReader::Ptr LensDirectoryReader::GetDefault()
48 {
49- static LensDirectoryReader::Ptr main_reader(new LensDirectoryReader(LENSES_DIR));
50+ static LensDirectoryReader::Ptr main_reader(new LensDirectoryReader("/tmp"));
51
52 return main_reader;
53 }
54
55=== added directory 'UnityCore/pch'
56=== added file 'UnityCore/pch/unitycore_pch.hh'
57--- UnityCore/pch/unitycore_pch.hh 1970-01-01 00:00:00 +0000
58+++ UnityCore/pch/unitycore_pch.hh 2012-10-08 11:22:21 +0000
59@@ -0,0 +1,33 @@
60+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
61+/*
62+ * Copyright (C) 2011 Canonical Ltd
63+ *
64+ * This program is free software: you can redistribute it and/or modify
65+ * it under the terms of the GNU General Public License version 3 as
66+ * published by the Free Software Foundation.
67+ *
68+ * This program is distributed in the hope that it will be useful,
69+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
70+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71+ * GNU General Public License for more details.
72+ *
73+ * You should have received a copy of the GNU General Public License
74+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
75+ *
76+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
77+ */
78+
79+/*
80+ * These are the precompiled header includes for UnityCore.
81+ * You should probably only include system headers in this one.
82+ */
83+
84+#include <vector>
85+#include <string>
86+#include <map>
87+#include <memory>
88+
89+#include <dee.h>
90+#include <NuxCore/Property.h>
91+#include <sigc++/sigc++.h>
92+#include <boost/utility.hpp>
93
94=== added file 'pch.cmake'
95--- pch.cmake 1970-01-01 00:00:00 +0000
96+++ pch.cmake 2012-10-08 11:22:21 +0000
97@@ -0,0 +1,72 @@
98+function(get_gcc_flags target_name)
99+ # CMake does not provide an easy way to get all compiler switches,
100+ # so this function is a fishing expedition to get them.
101+ # http://public.kitware.com/Bug/view.php?id=1260
102+ set(compile_args ${CMAKE_CXX_FLAGS})
103+ string(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype_name)
104+ if(CMAKE_CXX_FLAGS_${buildtype_name})
105+ list(APPEND compile_args ${CMAKE_CXX_FLAGS_${buildtype_name}})
106+ endif()
107+ list(APPEND compile_args ${CFLAGS})
108+ get_directory_property(dir_inc INCLUDE_DIRECTORIES)
109+ foreach(item ${dir_inc})
110+ LIST(APPEND compile_args "-I" ${item})
111+ endforeach()
112+ get_directory_property(dir_defs COMPILE_DEFINITIONS)
113+ message(STATUS "CDEFS ${dir_defs}")
114+ foreach(item ${dir_defs})
115+ list(APPEND compile_args -D${item})
116+ endforeach()
117+ get_directory_property(buildtype_defs COMPILE_DEFINITIONS_${buildtype_name})
118+ foreach(item ${buildtype_defs})
119+ list(APPEND compile_args -D${item})
120+ endforeach()
121+ get_target_property(target_type ${target_name} TYPE)
122+ if(${target_type} STREQUAL SHARED_LIBRARY)
123+ list(APPEND compile_args ${CMAKE_CXX_COMPILE_OPTIONS_PIC})
124+ endif()
125+ set(compile_args ${compile_args} PARENT_SCOPE)
126+ #message(STATUS ${compile_args})
127+endfunction()
128+
129+function(add_pch_linux header_filename target_name)
130+ set(gch_target_name "${target_name}_pch")
131+ get_filename_component(header_basename ${header_filename} NAME)
132+ set(gch_filename "${CMAKE_CURRENT_BINARY_DIR}/${header_basename}.gch")
133+ get_gcc_flags(${target_name}) # Sets compile_args in this scope. It's even better than Intercal's COME FROM!
134+ #message(STATUS ${compile_args})
135+ list(APPEND compile_args -c ${CMAKE_CURRENT_SOURCE_DIR}/${header_filename} -o ${gch_filename})
136+ separate_arguments(compile_args)
137+ add_custom_command(OUTPUT ${gch_filename}
138+ COMMAND ${CMAKE_CXX_COMPILER} ${compile_args}
139+ DEPENDS ${header_filename})
140+ add_custom_target(${gch_target_name} DEPENDS ${gch_filename})
141+ add_dependencies(${target_name} ${gch_target_name})
142+
143+ set_property(TARGET ${target_name} APPEND_STRING PROPERTY COMPILE_FLAGS "-include ${header_basename}")
144+
145+ # Each directory should have only one precompiled header
146+ # for simplicity. If there are several, the current dir
147+ # gets added to the search path several times.
148+ # It should not be an issue, though.
149+ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
150+endfunction()
151+
152+if(UNIX)
153+ if(NOT APPLE)
154+ option(use_pch "Use precompiled headers." TRUE)
155+ endif()
156+endif()
157+
158+if(use_pch)
159+ message(STATUS "Using precompiled headers.")
160+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch")
161+ #add_definitions(-DUSE_PCH)
162+ macro(add_pch _header_filename _target_name)
163+ add_pch_linux(${_header_filename} ${_target_name})
164+ endmacro()
165+else()
166+ message(STATUS "Not using precompiled headers.")
167+ macro(add_pch _header_filename _target_name)
168+ endmacro()
169+endif()