diff --git a/CHANGELOG.md b/CHANGELOG.md index ad653f09..d0567cdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,10 +18,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +* Added build flags for file size reduction in `CMakeLists.txt`. + ### Changed +* Precompiled header is optional and set to OFF to reduce deployment built size. +* Moved `compas.h` module specific headers to the individual source files. + ### Removed +* Remove unnecessary headers from `compas_cgal.h`. + ## [0.7.3] 2025-03-18 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1053c6ee..07c5f725 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,27 @@ project(cgal_wrapper LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_BUILD_TYPE Release) +set(CMAKE_CXX_FLAGS_DEBUG "") + +# ===================================================================== +# Set this flag to ON for developing to reduce build time. +# Set this flag to OFF for publishing for file size reduction. +# ===================================================================== +option(ENABLE_PRECOMPILED_HEADERS "Enable precompiled headers for the build" OFF) + +# ===================================================================== +# Build size reduction. +# ===================================================================== + +if (NOT ENABLE_PRECOMPILED_HEADERS) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) + if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O1") # Optimize for size on MSVC + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os") # Optimize for size on GCC/Clang + endif() +endif() # ===================================================================== # Dependencies @@ -196,15 +217,17 @@ target_include_directories(compas_cgal_ext PRIVATE # Make sure external dependencies are downloaded before building the extension add_dependencies(compas_cgal_ext external_downloads) -# Enhanced PCH configuration -set(CMAKE_PCH_INSTANTIATE_TEMPLATES OFF) -set(CMAKE_PCH_WARN_INVALID OFF) +if (ENABLE_PRECOMPILED_HEADERS) + # Enhanced PCH configuration + set(CMAKE_PCH_INSTANTIATE_TEMPLATES ON) + set(CMAKE_PCH_WARN_INVALID ON) -# Configure PCH for the extension -target_precompile_headers(compas_cgal_ext - PRIVATE - src/compas.h -) + # Configure PCH for the extension + target_precompile_headers(compas_cgal_ext + PRIVATE + src/compas.h + ) +endif() # Install directive for scikit-build-core install(TARGETS compas_cgal_ext LIBRARY DESTINATION compas_cgal) \ No newline at end of file diff --git a/src/booleans.h b/src/booleans.h index e2387173..ff42bdea 100644 --- a/src/booleans.h +++ b/src/booleans.h @@ -2,6 +2,10 @@ #include "compas.h" +// CGAL boolean +#include +#include + /** * Compute the boolean union of two triangle meshes. * diff --git a/src/compas.h b/src/compas.h index df972add..a9133673 100644 --- a/src/compas.h +++ b/src/compas.h @@ -5,38 +5,12 @@ // This file is referenced in CMakeLists PCH section. // STD -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - // Nanobind #include #include #include -#include -#include #include #include #include @@ -49,7 +23,6 @@ using namespace nb::literals; // enables syntax for annotating function and argu #include #include - // Eigen #include #include @@ -62,67 +35,6 @@ using namespace nb::literals; // enables syntax for annotating function and argu #include #include -// CGAL remesh -#include -#include - -// CGAL measure -#include -#include - -// CGAL boolean -#include -#include - -// CGAL intersection -#include - -// CGAL reconstruction -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// CGAL skeletonization -#include -#include - -// CGAL slicer -#include - -// CGAL subdivision -#include - -// CGAL triangulation -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// CGAL straight skeleton 2 -#include -#include -#include -#include -#include -#include -#include - - namespace compas { using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; diff --git a/src/intersections.h b/src/intersections.h index 825f7d5e..51c2f29a 100644 --- a/src/intersections.h +++ b/src/intersections.h @@ -2,6 +2,9 @@ #include "compas.h" +// CGAL intersection +#include + /** * Compute intersection between two triangle meshes. * diff --git a/src/measure.cpp b/src/measure.cpp index 840d5e43..d186a9bd 100644 --- a/src/measure.cpp +++ b/src/measure.cpp @@ -17,6 +17,7 @@ pmp_volume( { compas::Mesh mesh = compas::mesh_from_vertices_and_faces(vertices, faces); double volume = CGAL::Polygon_mesh_processing::volume(mesh); + int a = 0; return volume; } diff --git a/src/measure.h b/src/measure.h index 649aeb04..1545d995 100644 --- a/src/measure.h +++ b/src/measure.h @@ -2,6 +2,10 @@ #include "compas.h" +// CGAL measure +#include +#include + /** * @brief Computes the surface area of a triangle mesh. * diff --git a/src/meshing.h b/src/meshing.h index a008cbc9..476b3f50 100644 --- a/src/meshing.h +++ b/src/meshing.h @@ -1,12 +1,11 @@ -/** - * @file meshing.h - * @brief Header file for mesh processing operations using CGAL - */ - #pragma once #include "compas.h" +// CGAL remesh +#include +#include + namespace compas { /** diff --git a/src/reconstruction.h b/src/reconstruction.h index 4bcad272..a7190601 100644 --- a/src/reconstruction.h +++ b/src/reconstruction.h @@ -2,6 +2,18 @@ #include "compas.h" +// CGAL reconstruction +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + /** * @brief Perform Poisson surface reconstruction on an oriented pointcloud with normals. * diff --git a/src/skeletonization.h b/src/skeletonization.h index 6a8322ef..939c82bf 100644 --- a/src/skeletonization.h +++ b/src/skeletonization.h @@ -2,6 +2,10 @@ #include "compas.h" +// CGAL skeletonization +#include +#include + /** * @brief Compute the geometric skeleton of a triangle mesh using mean curvature flow. * diff --git a/src/slicer.h b/src/slicer.h index 0e2a0ada..cb2e6c78 100644 --- a/src/slicer.h +++ b/src/slicer.h @@ -2,6 +2,9 @@ #include "compas.h" +// CGAL slicer +#include + /** * @brief Slice a mesh with a set of planes defined by points and normals. * diff --git a/src/straight_skeleton_2.h b/src/straight_skeleton_2.h index 42f16546..126c0d7f 100644 --- a/src/straight_skeleton_2.h +++ b/src/straight_skeleton_2.h @@ -2,6 +2,16 @@ #include "compas.h" +// CGAL straight skeleton 2 +#include +#include +#include +#include +#include +#include +#include + + /** * @brief Creates a straight skeleton from a simple polygon without holes. * diff --git a/src/subdivision.h b/src/subdivision.h index a560b55f..6babb1bb 100644 --- a/src/subdivision.h +++ b/src/subdivision.h @@ -2,6 +2,9 @@ #include "compas.h" +// CGAL subdivision +#include + /** * @brief Subdivide a mesh with the Catmull-Clark scheme. * diff --git a/src/triangulation.h b/src/triangulation.h index cd559e42..46b046d0 100644 --- a/src/triangulation.h +++ b/src/triangulation.h @@ -2,6 +2,20 @@ #include "compas.h" +// CGAL triangulation +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + /** * @brief Delaunay Triangulation of a given set of points. *