From f4350098ed23f82e7b9ea3b7df5fa88c4a035acf Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 23 Jan 2013 14:35:50 +0100 Subject: [PATCH] Use precompiled headers to compile C++ modules On an average system this will cut around 15% of the total build time. Unfortunately, including Boost headers in the precompiled header takes longer time to generate and then read in each module, than just including the necessary headers in each module. Use Noel Llopis' list_precomp.py at http://www.gamesfromwithin.com/wp-content/uploads/bin/list_precomp_py.txt to analyse which headers are included the most and are candidates for inclusion. --- CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++-- opm/core/opm-core-pch.hpp | 10 ++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 opm/core/opm-core-pch.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ff9a561..ac9ee177 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,9 @@ endif (CMAKE_VERSION VERSION_LESS "2.8.7") # use tricks to do faster builds include (UseFastBuilds) +# precompiled headers +include (UsePrecompHeaders) + # macro to set standard variables (INCLUDE_DIRS, LIBRARIES etc.) include (OpmFind) @@ -83,8 +86,20 @@ set (CMAKE_Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles") # against using globs to enumerate source code, but if you list the # files explicitly you'll change the build files every time you add to # the project as well as having to rebuild completely anyway. -file (GLOB_RECURSE opmcore_SOURCES "opm/core/[^.]*.c" "opm/core/[^.]*.cpp") -file (GLOB_RECURSE opmcore_HEADERS "opm/core/[^.]*.h" "opm/core/[^.]*.hpp") +file (GLOB_RECURSE opmcore_C_SOURCES "opm/core/[^.]*.c") +file (GLOB_RECURSE opmcore_CXX_SOURCES "opm/core/[^.]*.cpp") +file (GLOB_RECURSE opmcore_C_HEADERS "opm/core/[^.]*.h") +file (GLOB_RECURSE opmcore_CXX_HEADERS "opm/core/[^.]*.hpp") + +# remove pre-compile headers from output list +set (opmcore_PRECOMP_CXX_HEADER "opm/core/opm-core-pch.hpp") +list (REMOVE_ITEM opmcore_CXX_HEADERS + ${PROJECT_SOURCE_DIR}/${opmcore_PRECOMP_CXX_HEADER} + ) + +# merge both languages into one compilation/installation +set (opmcore_SOURCES ${opmcore_C_SOURCES} ${opmcore_CXX_SOURCES}) +set (opmcore_HEADERS ${opmcore_C_HEADERS} ${opmcore_CXX_HEADERS}) # Algebraic Multigrid must be compiled together with our program; # if it is not available, then remove our corresponding component @@ -212,6 +227,21 @@ configure_vars ( APPEND "${opm-core_CONFIG_VARS}" ) +# pre-compile common headers; this is setup *after* the library to pick +# up extra options set there +get_target_property (_type opmcore TYPE) +precompile_header (CXX ${_type} + HEADER "${opmcore_PRECOMP_CXX_HEADER}" + TARGET opmcore_CXX_pch + FLAGS opmcore_PRECOMP_CXX_FLAGS + ) +# must set property on source files instead of entire target, because +# it only applies to C++ modules (and cannot be used for C) +set_source_files_properties (${opmcore_CXX_SOURCES} PROPERTIES + OBJECT_DEPENDS "${opmcore_CXX_pch}" + COMPILE_FLAGS "${opmcore_PRECOMP_CXX_FLAGS}" + ) + ### installation ### foreach (_hdr IN LISTS opmcore_HEADERS) get_filename_component (_dir ${_hdr} PATH) diff --git a/opm/core/opm-core-pch.hpp b/opm/core/opm-core-pch.hpp new file mode 100644 index 00000000..9fc236d3 --- /dev/null +++ b/opm/core/opm-core-pch.hpp @@ -0,0 +1,10 @@ +/* List of headers that should be precompiled */ +#include +#include +#include +#include +#include +#include +#include +#include +#include