From e38a3156c34d31b5d1286095bef467dfa8054e4f Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sun, 4 Nov 2018 12:37:43 -0500 Subject: [PATCH] Adding a pre-compiled header for MSVC --- cmake/GtsamAddPch.cmake | 27 +++++++++++++++++ gtsam/CMakeLists.txt | 28 ++++++++--------- gtsam/precompiled_header.cpp | 19 ++++++++++++ gtsam/precompiled_header.h | 59 ++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 cmake/GtsamAddPch.cmake create mode 100644 gtsam/precompiled_header.cpp create mode 100644 gtsam/precompiled_header.h diff --git a/cmake/GtsamAddPch.cmake b/cmake/GtsamAddPch.cmake new file mode 100644 index 000000000..cb872e361 --- /dev/null +++ b/cmake/GtsamAddPch.cmake @@ -0,0 +1,27 @@ +############################################################################### +# Macro: +# +# gtsamAddPch(precompiledHeader precompiledSource sources) +# +# Adds a precompiled header to compile all sources with. Currently only on MSVC. +# Inspired by https://stackoverflow.com/questions/148570/ +# +# Arguments: +# precompiledHeader: the header file that includes headers to be precompiled. +# precompiledSource: the source file that simply includes that header above. +# sources: the list of source files to apply this to. +# +macro(gtsamAddPch precompiledHeader precompiledSource sources) + get_filename_component(pchBasename ${precompiledHeader} NAME_WE) + SET(precompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${pchBasename}.pch") + IF(MSVC) + message(STATUS "Adding precompiled header for MSVC") + set_source_files_properties(${precompiledSource} + PROPERTIES COMPILE_FLAGS "/Yc\"${precompiledHeader}\" /Fp\"${precompiledBinary}\"" + OBJECT_OUTPUTS "${precompiledBinary}") + set_source_files_properties(${sources} + PROPERTIES COMPILE_FLAGS "/Yu\"${precompiledHeader}\" /FI\"${precompiledHeader}\" /Fp\"${precompiledBinary}\"" + OBJECT_DEPENDS "${precompiledBinary}") + ENDIF(MSVC) +endmacro(gtsamAddPch) + diff --git a/gtsam/CMakeLists.txt b/gtsam/CMakeLists.txt index 10092f195..6a3d08eb8 100644 --- a/gtsam/CMakeLists.txt +++ b/gtsam/CMakeLists.txt @@ -65,20 +65,19 @@ foreach(subdir ${gtsam_subdirs}) endforeach(subdir) # To add additional sources to gtsam when building the full library (static or shared) -# Add the subfolder with _srcs appended to the end to this list -set(gtsam_srcs - ${3rdparty_srcs} - ${base_srcs} - ${geometry_srcs} - ${inference_srcs} - ${symbolic_srcs} - ${discrete_srcs} - ${linear_srcs} - ${nonlinear_srcs} - ${slam_srcs} - ${navigation_srcs} - ${gtsam_core_headers} -) +# append the subfolder with _srcs appended to the end to this list +set(gtsam_srcs ${3rdparty_srcs}) +foreach(subdir ${gtsam_subdirs}) + list(APPEND gtsam_srcs ${${subdir}_srcs}) +endforeach(subdir) +list(APPEND gtsam_srcs ${gtsam_core_headers}) + +IF(MSVC) + # Add precompiled header to sources + include(gtsamAddPch) + gtsamAddPch("precompiled_header.h" "precompiled_header.cpp" ${gtsam_srcs}) + list(INSERT gtsam_srcs 0 "precompiled_header.cpp") +ENDIF(MSVC) # Generate and install config and dllexport files configure_file(config.h.in config.h) @@ -155,6 +154,7 @@ if(MSVC) APPEND PROPERTY COMPILE_FLAGS "/bigobj") endif() + # Create the matlab toolbox for the gtsam library if (GTSAM_INSTALL_MATLAB_TOOLBOX) # Set up codegen diff --git a/gtsam/precompiled_header.cpp b/gtsam/precompiled_header.cpp new file mode 100644 index 000000000..83bc6231a --- /dev/null +++ b/gtsam/precompiled_header.cpp @@ -0,0 +1,19 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + + /** + * @file precompiled_header.cpp + * @brief We need exactly one compilation unit that includes the precompiled headers + * @author Frank Dellaert + * @date November 2018 + */ + +#include "precompiled_header.h" \ No newline at end of file diff --git a/gtsam/precompiled_header.h b/gtsam/precompiled_header.h new file mode 100644 index 000000000..c1b159802 --- /dev/null +++ b/gtsam/precompiled_header.h @@ -0,0 +1,59 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + + /** + * @file precompiled_header.h> + * @brief Include headers that will be included nearly everywhere + * @author Frank Dellaert + * @date November 2018 + */ + +#pragma once + +// All headers in base: +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +