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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2012-10-04 07:10:39 +0000
+++ CMakeLists.txt 2012-10-08 11:22:21 +0000
@@ -23,6 +23,8 @@
23 ON23 ON
24)24)
2525
26include(pch.cmake)
27
26if(UNITY_ENABLE_X_ORG_SUPPORT)28if(UNITY_ENABLE_X_ORG_SUPPORT)
27 add_definitions(-DUNITY_HAS_X_ORG_SUPPORT)29 add_definitions(-DUNITY_HAS_X_ORG_SUPPORT)
28 message("Unity is configured with support for X.org")30 message("Unity is configured with support for X.org")
2931
=== modified file 'UnityCore/CMakeLists.txt'
--- UnityCore/CMakeLists.txt 2012-08-31 13:12:35 +0000
+++ UnityCore/CMakeLists.txt 2012-10-08 11:22:21 +0000
@@ -99,10 +99,12 @@
99 ${CORE_DEPS_CFLAGS_OTHER}99 ${CORE_DEPS_CFLAGS_OTHER}
100 ${MAINTAINER_CFLAGS}100 ${MAINTAINER_CFLAGS}
101 "-I${CMAKE_BINARY_DIR}"101 "-I${CMAKE_BINARY_DIR}"
102 "-DGETTEXT_PACKAGE=\"unity\""
103 "-DLENSES_DIR=\"${_lensesdir}\""
104 )102 )
105add_definitions (${CFLAGS})103add_definitions (${CFLAGS})
104#add_definitions("-DGETTEXT_PACKAGE=\"unity\"")
105#add_definitions("-DLENSES_DIR=\"${_lensesdir}\"")
106
107message(STATUS ${CFLAGS})
106108
107set (LIBS ${CORE_DEPS_LIBRARIES})109set (LIBS ${CORE_DEPS_LIBRARIES})
108110
@@ -133,6 +135,8 @@
133 SOVERSION ${CORE_LIB_LT_CURRENT}135 SOVERSION ${CORE_LIB_LT_CURRENT}
134 INSTALL_RPATH "${PRIVATE_CORE_DEPS_LIBRARY_DIRS}")136 INSTALL_RPATH "${PRIVATE_CORE_DEPS_LIBRARY_DIRS}")
135137
138add_pch(pch/unitycore_pch.hh ${CORE_LIB_NAME})
139
136install (TARGETS ${CORE_LIB_NAME}140install (TARGETS ${CORE_LIB_NAME}
137 RUNTIME DESTINATION bin141 RUNTIME DESTINATION bin
138 ARCHIVE DESTINATION lib142 ARCHIVE DESTINATION lib
139143
=== modified file 'UnityCore/FilesystemLenses.cpp'
--- UnityCore/FilesystemLenses.cpp 2012-06-18 02:57:23 +0000
+++ UnityCore/FilesystemLenses.cpp 2012-10-08 11:22:21 +0000
@@ -331,7 +331,7 @@
331331
332LensDirectoryReader::Ptr LensDirectoryReader::GetDefault()332LensDirectoryReader::Ptr LensDirectoryReader::GetDefault()
333{333{
334 static LensDirectoryReader::Ptr main_reader(new LensDirectoryReader(LENSES_DIR));334 static LensDirectoryReader::Ptr main_reader(new LensDirectoryReader("/tmp"));
335335
336 return main_reader;336 return main_reader;
337}337}
338338
=== added directory 'UnityCore/pch'
=== added file 'UnityCore/pch/unitycore_pch.hh'
--- UnityCore/pch/unitycore_pch.hh 1970-01-01 00:00:00 +0000
+++ UnityCore/pch/unitycore_pch.hh 2012-10-08 11:22:21 +0000
@@ -0,0 +1,33 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
18 */
19
20/*
21 * These are the precompiled header includes for UnityCore.
22 * You should probably only include system headers in this one.
23 */
24
25#include <vector>
26#include <string>
27#include <map>
28#include <memory>
29
30#include <dee.h>
31#include <NuxCore/Property.h>
32#include <sigc++/sigc++.h>
33#include <boost/utility.hpp>
034
=== added file 'pch.cmake'
--- pch.cmake 1970-01-01 00:00:00 +0000
+++ pch.cmake 2012-10-08 11:22:21 +0000
@@ -0,0 +1,72 @@
1function(get_gcc_flags target_name)
2 # CMake does not provide an easy way to get all compiler switches,
3 # so this function is a fishing expedition to get them.
4 # http://public.kitware.com/Bug/view.php?id=1260
5 set(compile_args ${CMAKE_CXX_FLAGS})
6 string(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype_name)
7 if(CMAKE_CXX_FLAGS_${buildtype_name})
8 list(APPEND compile_args ${CMAKE_CXX_FLAGS_${buildtype_name}})
9 endif()
10 list(APPEND compile_args ${CFLAGS})
11 get_directory_property(dir_inc INCLUDE_DIRECTORIES)
12 foreach(item ${dir_inc})
13 LIST(APPEND compile_args "-I" ${item})
14 endforeach()
15 get_directory_property(dir_defs COMPILE_DEFINITIONS)
16 message(STATUS "CDEFS ${dir_defs}")
17 foreach(item ${dir_defs})
18 list(APPEND compile_args -D${item})
19 endforeach()
20 get_directory_property(buildtype_defs COMPILE_DEFINITIONS_${buildtype_name})
21 foreach(item ${buildtype_defs})
22 list(APPEND compile_args -D${item})
23 endforeach()
24 get_target_property(target_type ${target_name} TYPE)
25 if(${target_type} STREQUAL SHARED_LIBRARY)
26 list(APPEND compile_args ${CMAKE_CXX_COMPILE_OPTIONS_PIC})
27 endif()
28 set(compile_args ${compile_args} PARENT_SCOPE)
29 #message(STATUS ${compile_args})
30endfunction()
31
32function(add_pch_linux header_filename target_name)
33 set(gch_target_name "${target_name}_pch")
34 get_filename_component(header_basename ${header_filename} NAME)
35 set(gch_filename "${CMAKE_CURRENT_BINARY_DIR}/${header_basename}.gch")
36 get_gcc_flags(${target_name}) # Sets compile_args in this scope. It's even better than Intercal's COME FROM!
37 #message(STATUS ${compile_args})
38 list(APPEND compile_args -c ${CMAKE_CURRENT_SOURCE_DIR}/${header_filename} -o ${gch_filename})
39 separate_arguments(compile_args)
40 add_custom_command(OUTPUT ${gch_filename}
41 COMMAND ${CMAKE_CXX_COMPILER} ${compile_args}
42 DEPENDS ${header_filename})
43 add_custom_target(${gch_target_name} DEPENDS ${gch_filename})
44 add_dependencies(${target_name} ${gch_target_name})
45
46 set_property(TARGET ${target_name} APPEND_STRING PROPERTY COMPILE_FLAGS "-include ${header_basename}")
47
48 # Each directory should have only one precompiled header
49 # for simplicity. If there are several, the current dir
50 # gets added to the search path several times.
51 # It should not be an issue, though.
52 include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
53endfunction()
54
55if(UNIX)
56 if(NOT APPLE)
57 option(use_pch "Use precompiled headers." TRUE)
58 endif()
59endif()
60
61if(use_pch)
62 message(STATUS "Using precompiled headers.")
63 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch")
64 #add_definitions(-DUSE_PCH)
65 macro(add_pch _header_filename _target_name)
66 add_pch_linux(${_header_filename} ${_target_name})
67 endmacro()
68else()
69 message(STATUS "Not using precompiled headers.")
70 macro(add_pch _header_filename _target_name)
71 endmacro()
72endif()