summaryrefslogtreecommitdiff
diff options
authorJussi Pakkanen <jussi.pakkanen@canonical.com>2012-12-19 15:30:32 +0000
committerTarmac <>2012-12-19 15:30:32 +0000
commit76e8006820a1216cb877c9ed0cc1026a558371e5 (patch)
tree760fd364c0a2996cbcf7854a5be924ca20eef93d
parent159d6ca00a57bc6c322a748eb17b09a3ebf9d8c9 (diff)
parent6951e1de4c5d14648e10e2f380f05c44c8b31bdc (diff)
Add support for precompiled headers.
Approved by Stephen M. Webb. (bzr r3002)
-rw-r--r--CMakeLists.txt3
-rw-r--r--UnityCore/CMakeLists.txt1
-rw-r--r--UnityCore/pch/unitycore_pch.hh33
-rw-r--r--cmake/isclang.cc26
-rw-r--r--cmake/pch.cmake78
-rw-r--r--dash/CMakeLists.txt3
-rw-r--r--dash/pch/dash_pch.hh29
-rw-r--r--dash/previews/CMakeLists.txt1
-rw-r--r--dash/previews/pch/previews_pch.hh28
-rw-r--r--hud/CMakeLists.txt1
-rw-r--r--hud/pch/hud_pch.hh31
-rw-r--r--launcher/CMakeLists.txt1
-rw-r--r--launcher/pch/launcher_pch.hh33
-rw-r--r--panel/CMakeLists.txt1
-rw-r--r--panel/pch/panel_pch.hh31
-rw-r--r--shortcuts/CMakeLists.txt1
-rw-r--r--shortcuts/pch/shortcuts_pch.hh32
-rw-r--r--unity-shared/CMakeLists.txt1
-rw-r--r--unity-shared/pch/unity-shared_pch.hh33
19 files changed, 366 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2310f4770..ee0f09012 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,8 @@
project (unity)
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.8.9)
include (cmake/Documentation.cmake)
+include (cmake/pch.cmake)
#
# Base bits
diff --git a/UnityCore/CMakeLists.txt b/UnityCore/CMakeLists.txt
index c000adf6c..b3d270677 100644
--- a/UnityCore/CMakeLists.txt
+++ b/UnityCore/CMakeLists.txt
@@ -131,6 +131,7 @@ set_target_properties(${CORE_LIB_NAME} PROPERTIES
VERSION ${CORE_LIB_LT_CURRENT}.${CORE_LIB_LT_REV}.${CORE_LIB_LT_AGE}
SOVERSION ${CORE_LIB_LT_CURRENT}
INSTALL_RPATH "${PRIVATE_CORE_DEPS_LIBRARY_DIRS}")
+add_pch(pch/unitycore_pch.hh ${CORE_LIB_NAME})
install (TARGETS ${CORE_LIB_NAME}
RUNTIME DESTINATION bin
diff --git a/UnityCore/pch/unitycore_pch.hh b/UnityCore/pch/unitycore_pch.hh
new file mode 100644
index 000000000..43a04d774
--- /dev/null
+++ b/UnityCore/pch/unitycore_pch.hh
@@ -0,0 +1,33 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
+ */
+
+/*
+ * These are the precompiled header includes for UnityCore.
+ * Only system header files can be listed here.
+ */
+
+#include <vector>
+#include <string>
+#include <map>
+#include <memory>
+
+#include <dee.h>
+#include <NuxCore/Property.h>
+#include <sigc++/sigc++.h>
+#include <boost/utility.hpp>
diff --git a/cmake/isclang.cc b/cmake/isclang.cc
new file mode 100644
index 000000000..35cbb3295
--- /dev/null
+++ b/cmake/isclang.cc
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2012 Canonical, Ltd.
+ *
+ * Authors:
+ * Jussi Pakkanen <jussi.pakkanen@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+int main(int argc, char **argv) {
+#ifdef __clang__
+ return 1; // This gets assigned to a CMake variable so "1" means "true".
+#else
+ return 0;
+#endif
+}
diff --git a/cmake/pch.cmake b/cmake/pch.cmake
new file mode 100644
index 000000000..83e94255b
--- /dev/null
+++ b/cmake/pch.cmake
@@ -0,0 +1,78 @@
+function(get_gcc_flags target_name)
+ # CMake does not provide an easy way to get all compiler switches,
+ # so this function is a fishing expedition to get them.
+ # http://public.kitware.com/Bug/view.php?id=1260
+ set(compile_args ${CMAKE_CXX_FLAGS})
+ string(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype_name)
+ if(CMAKE_CXX_FLAGS_${buildtype_name})
+ list(APPEND compile_args ${CMAKE_CXX_FLAGS_${buildtype_name}})
+ endif()
+ get_directory_property(dir_inc INCLUDE_DIRECTORIES)
+ foreach(item ${dir_inc})
+ LIST(APPEND compile_args "-I" ${item})
+ endforeach()
+ get_directory_property(dir_defs COMPILE_DEFINITIONS)
+ foreach(item ${dir_defs})
+ list(APPEND compile_args -D${item})
+ endforeach()
+ get_directory_property(buildtype_defs COMPILE_DEFINITIONS_${buildtype_name})
+ foreach(item ${buildtype_defs})
+ list(APPEND compile_args -D${item})
+ endforeach()
+ get_target_property(target_type ${target_name} TYPE)
+ if(${target_type} STREQUAL SHARED_LIBRARY)
+ list(APPEND compile_args ${CMAKE_CXX_COMPILE_OPTIONS_PIC})
+ endif()
+ set(compile_args ${compile_args} PARENT_SCOPE)
+ #message(STATUS ${compile_args})
+endfunction()
+
+function(add_pch_linux header_filename target_name pch_suffix)
+ set(gch_target_name "${target_name}_pch")
+ get_filename_component(header_basename ${header_filename} NAME)
+ set(gch_filename "${CMAKE_CURRENT_BINARY_DIR}/${header_basename}.${pch_suffix}")
+ get_gcc_flags(${target_name}) # Sets compile_args in this scope. It's even better than Intercal's COME FROM!
+ #message(STATUS ${compile_args})
+ list(APPEND compile_args -c ${CMAKE_CURRENT_SOURCE_DIR}/${header_filename} -o ${gch_filename})
+ separate_arguments(compile_args)
+ add_custom_command(OUTPUT ${gch_filename}
+ COMMAND ${CMAKE_CXX_COMPILER} ${compile_args}
+ DEPENDS ${header_filename})
+ add_custom_target(${gch_target_name} DEPENDS ${gch_filename})
+ add_dependencies(${target_name} ${gch_target_name})
+
+ # Add the PCH to every source file's include list.
+ # This is the only way that is supported by both GCC and Clang.
+ set_property(TARGET ${target_name} APPEND_STRING PROPERTY COMPILE_FLAGS "-include ${header_basename}")
+
+ # Each directory should have only one precompiled header
+ # for simplicity. If there are several, the current dir
+ # gets added to the search path several times.
+ # It should not be an issue, though.
+ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
+endfunction()
+
+try_run(IS_CLANG did_build ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/isclang.cc)
+
+if(UNIX)
+ if(NOT APPLE)
+ option(use_pch "Use precompiled headers." TRUE)
+ endif()
+endif()
+
+if(use_pch)
+ message(STATUS "Using precompiled headers.")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch")
+ if(IS_CLANG)
+ set(precompiled_header_extension pch)
+ else()
+ set(precompiled_header_extension gch)
+ endif()
+ macro(add_pch _header_filename _target_name)
+ add_pch_linux(${_header_filename} ${_target_name} ${precompiled_header_extension})
+ endmacro()
+else()
+ message(STATUS "Not using precompiled headers.")
+ macro(add_pch _header_filename _target_name)
+ endmacro()
+endif()
diff --git a/dash/CMakeLists.txt b/dash/CMakeLists.txt
index 02554d4ea..38917839b 100644
--- a/dash/CMakeLists.txt
+++ b/dash/CMakeLists.txt
@@ -52,6 +52,9 @@ set (DASH_SOURCES
add_library (dash-lib STATIC ${DASH_SOURCES})
add_dependencies (dash-lib unity-core-${UNITY_API_VERSION} unity-shared)
target_link_libraries (dash-lib previews-lib)
+add_pch(pch/dash_pch.hh dash-lib)
+
+
#
# Standalone variant
#
diff --git a/dash/pch/dash_pch.hh b/dash/pch/dash_pch.hh
new file mode 100644
index 000000000..8e582fc74
--- /dev/null
+++ b/dash/pch/dash_pch.hh
@@ -0,0 +1,29 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
+ */
+
+/*
+ * These are the precompiled header includes for Dash.
+ * Only system header files can be listed here.
+ */
+
+#include <vector>
+#include <string>
+#include <memory>
+
+#include <Nux/Nux.h>
diff --git a/dash/previews/CMakeLists.txt b/dash/previews/CMakeLists.txt
index ed58a95f9..731bebda0 100644
--- a/dash/previews/CMakeLists.txt
+++ b/dash/previews/CMakeLists.txt
@@ -41,6 +41,7 @@ set (PREVIEWS_SOURCES
add_library (previews-lib STATIC ${PREVIEWS_SOURCES})
add_dependencies (previews-lib unity-core-${UNITY_API_VERSION} unity-shared)
target_link_libraries (previews-lib unity-shared)
+add_pch(pch/previews_pch.hh previews-lib)
#
# Application Standalone variant
diff --git a/dash/previews/pch/previews_pch.hh b/dash/previews/pch/previews_pch.hh
new file mode 100644
index 000000000..bdc5cae3f
--- /dev/null
+++ b/dash/previews/pch/previews_pch.hh
@@ -0,0 +1,28 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
+ */
+
+/*
+ * These are the precompiled header includes for this module.
+ * Only system header files can be listed here.
+ */
+
+#include <Nux/Nux.h>
+#include <UnityCore/Preview.h>
+#include <UnityCore/Tracks.h>
+#include <UnityCore/Variant.h>
diff --git a/hud/CMakeLists.txt b/hud/CMakeLists.txt
index f9af1e588..01dbb8df2 100644
--- a/hud/CMakeLists.txt
+++ b/hud/CMakeLists.txt
@@ -31,6 +31,7 @@ set (HUD_SOURCES
add_library (hud-lib STATIC ${HUD_SOURCES})
add_dependencies (hud-lib unity-core-${UNITY_API_VERSION} unity-shared)
+add_pch(pch/hud_pch.hh hud-lib)
#
# Standalone variant
diff --git a/hud/pch/hud_pch.hh b/hud/pch/hud_pch.hh
new file mode 100644
index 000000000..f4979cb97
--- /dev/null
+++ b/hud/pch/hud_pch.hh
@@ -0,0 +1,31 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
+ */
+
+/*
+ * These are the precompiled header includes for this module.
+ * Only system header files can be listed here.
+ */
+
+#include <memory>
+#include <string>
+
+#include <Nux/Nux.h>
+#include <UnityCore/GLibSource.h>
+#include <UnityCore/GLibWrapper.h>
+#include <UnityCore/Variant.h>
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index cfb6bfb5e..b08719bc0 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -81,6 +81,7 @@ endif ()
add_library (launcher-lib STATIC ${LAUNCHER_SOURCES})
add_dependencies (launcher-lib unity-core-${UNITY_API_VERSION} unity-shared)
target_link_libraries (launcher-lib unity-shared)
+add_pch(pch/launcher_pch.hh launcher-lib)
set (SWITCHER_SOURCES
SwitcherController.cpp
diff --git a/launcher/pch/launcher_pch.hh b/launcher/pch/launcher_pch.hh
new file mode 100644
index 000000000..569390f4b
--- /dev/null
+++ b/launcher/pch/launcher_pch.hh
@@ -0,0 +1,33 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
+ */
+
+/*
+ * These are the precompiled header includes for this module.
+ * Only system header files can be listed here.
+ */
+
+#include <memory>
+
+#include <Nux/Nux.h>
+#include <UnityCore/GLibSource.h>
+#include <UnityCore/GLibWrapper.h>
+#include <UnityCore/Variant.h>
+
+#include <boost/noncopyable.hpp>
+#include <boost/utility.hpp>
diff --git a/panel/CMakeLists.txt b/panel/CMakeLists.txt
index fd6faf0e2..21cdc044a 100644
--- a/panel/CMakeLists.txt
+++ b/panel/CMakeLists.txt
@@ -32,6 +32,7 @@ set (PANEL_SOURCES
add_library (panel-lib STATIC ${PANEL_SOURCES})
add_dependencies (panel-lib unity-core-${UNITY_API_VERSION} unity-shared)
+add_pch(pch/panel_pch.hh panel-lib)
#
# Standalone variant
diff --git a/panel/pch/panel_pch.hh b/panel/pch/panel_pch.hh
new file mode 100644
index 000000000..eb73fb367
--- /dev/null
+++ b/panel/pch/panel_pch.hh
@@ -0,0 +1,31 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
+ */
+
+/*
+ * These are the precompiled header includes for this module.
+ * Only system header files can be listed here.
+ */
+
+#include <memory>
+#include <vector>
+
+#include <Nux/Nux.h>
+#include <UnityCore/GLibSource.h>
+#include <UnityCore/GLibWrapper.h>
+#include <UnityCore/Variant.h>
diff --git a/shortcuts/CMakeLists.txt b/shortcuts/CMakeLists.txt
index 164755f9a..2d39dee4f 100644
--- a/shortcuts/CMakeLists.txt
+++ b/shortcuts/CMakeLists.txt
@@ -35,6 +35,7 @@ set (SHORTCUTS_SOURCES
add_library (shortcuts-lib STATIC ${SHORTCUTS_SOURCES})
add_dependencies (shortcuts-lib unity-core-${UNITY_API_VERSION} unity-shared)
+add_pch(pch/shortcuts_pch.hh shortcuts-lib)
#
# Standalone variant
diff --git a/shortcuts/pch/shortcuts_pch.hh b/shortcuts/pch/shortcuts_pch.hh
new file mode 100644
index 000000000..67e6f1fd5
--- /dev/null
+++ b/shortcuts/pch/shortcuts_pch.hh
@@ -0,0 +1,32 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
+ */
+
+/*
+ * These are the precompiled header includes for this module.
+ * Only system header files can be listed here.
+ */
+
+#include <memory>
+#include <map>
+#include <vector>
+
+#include <Nux/Nux.h>
+#include <UnityCore/GLibSource.h>
+#include <UnityCore/GLibWrapper.h>
+#include <UnityCore/Variant.h>
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt
index b4df6d020..54716d9f2 100644
--- a/unity-shared/CMakeLists.txt
+++ b/unity-shared/CMakeLists.txt
@@ -84,6 +84,7 @@ endif()
add_library (unity-shared STATIC ${UNITY_SHARED_SOURCES})
target_link_libraries (unity-shared ${LIBS})
add_dependencies (unity-shared unity-core-${UNITY_API_VERSION})
+add_pch(pch/unity-shared_pch.hh unity-shared)
#
# We also need to build compiz specific parts and standalone variants of those parts
diff --git a/unity-shared/pch/unity-shared_pch.hh b/unity-shared/pch/unity-shared_pch.hh
new file mode 100644
index 000000000..060dbba3c
--- /dev/null
+++ b/unity-shared/pch/unity-shared_pch.hh
@@ -0,0 +1,33 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
+ */
+
+/*
+ * These are the precompiled header includes for UnityCore.
+ * Only system header files can be listed here.
+ */
+
+#include <vector>
+#include <string>
+#include <map>
+#include <memory>
+
+#include <Nux/Nux.h>
+#include <sigc++/sigc++.h>
+#include <boost/utility.hpp>
+#include <boost/algorithm/string.hpp>