Allow Unity build. Two parts: - missing include guard in solver_utils.h - exclude schur_specializations from unity build. This can only be done with cmake >= 3.16, so only allow unity build for these versions. Cuts build time by 5 minutes with default settings. libceres.a shrinks from 7549968 bytes to 7009696 bytes. Change-Id: I833ac8266623da0e725cc2f07a6415b4fa72bc18
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt index 6dc7262..140b250 100644 --- a/internal/ceres/CMakeLists.txt +++ b/internal/ceres/CMakeLists.txt
@@ -170,6 +170,21 @@ file(GLOB CERES_INTERNAL_SCHUR_FILES generated/*_d_d_d.cc) endif (SCHUR_SPECIALIZATIONS) +# The generated specializations of the Schur eliminator include +# schur_eliminator_impl.h which defines EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD +# to a different value than Eigen's default. Depending on the order of files +# in the unity build this can lead to clashes. Additionally, these files are +# already generated in a way which leads to fairly large compilation units, +# so the gains from a unity build would be marginal. Since this property is +# not available before cmake 3.16, unity build is only available from this +# version on. +if (NOT CMAKE_VERSION VERSION_LESS 3.16) + set_source_files_properties(${CERES_INTERNAL_SCHUR_FILES} PROPERTIES + SKIP_UNITY_BUILD_INCLUSION ON) +elseif(CMAKE_UNITY_BUILD) + message(FATAL_ERROR "Unity build requires cmake 3.16 or newer. Please unset CMAKE_UNITY_BUILD.") +endif() + # Build the list of dependencies for Ceres based on the current configuration. find_package(Threads QUIET) list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES Threads::Threads)
diff --git a/internal/ceres/solver_utils.h b/internal/ceres/solver_utils.h index 85fbf37..5715cb7 100644 --- a/internal/ceres/solver_utils.h +++ b/internal/ceres/solver_utils.h
@@ -28,6 +28,9 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) +#ifndef CERES_INTERNAL_SOLVER_UTILS_H_ +#define CERES_INTERNAL_SOLVER_UTILS_H_ + #include <algorithm> #include <string> @@ -59,3 +62,5 @@ } // namespace internal } // namespace ceres + +#endif // CERES_INTERNAL_SOLVER_UTILS_H_