Skip to content

Commit 1df4b7e

Browse files
FIX cmakelists precompiled header is compiled only once.
1 parent 5b127aa commit 1df4b7e

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

CMakeLists.txt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,34 +122,38 @@ if (NOT SKBUILD)
122122
after editing C++ files.")
123123
endif()
124124

125-
# Enhanced PCH configuration
126-
if (ENABLE_PRECOMPILED_HEADERS)
127-
set(CMAKE_PCH_INSTANTIATE_TEMPLATES ON)
128-
set(CMAKE_PCH_WARN_INVALID ON)
129-
endif()
130-
131125
# Find Python and nanobind
132126
find_package(Python 3.8
133127
REQUIRED COMPONENTS Interpreter Development.Module
134128
OPTIONAL_COMPONENTS Development.SABIModule)
135129
find_package(nanobind CONFIG REQUIRED)
136130
find_package(Threads REQUIRED)
137131

132+
# Create a shared precompiled header library
133+
if (ENABLE_PRECOMPILED_HEADERS)
134+
add_library(compas_pch INTERFACE)
135+
target_precompile_headers(compas_pch INTERFACE src/compas.hpp)
136+
target_include_directories(compas_pch INTERFACE
137+
${EIGEN_INCLUDE_DIR}
138+
${LIBIGL_INCLUDE_DIR}
139+
)
140+
endif()
141+
138142
# Function to add a nanobind module with include directories
139143
function(add_nanobind_module module_name source_file)
140144
nanobind_add_module(${module_name} STABLE_ABI NB_STATIC ${source_file})
141145

142146
# Ensure external dependencies are downloaded first
143147
add_dependencies(${module_name} external_downloads)
144148

145-
# Add include directories
146-
target_include_directories(${module_name} SYSTEM PRIVATE
147-
${EIGEN_INCLUDE_DIR}
148-
${LIBIGL_INCLUDE_DIR}
149-
)
150-
149+
# Add include directories and link PCH if enabled
151150
if (ENABLE_PRECOMPILED_HEADERS)
152-
target_precompile_headers(${module_name} PRIVATE src/compas.hpp)
151+
target_link_libraries(${module_name} PRIVATE compas_pch)
152+
else()
153+
target_include_directories(${module_name} SYSTEM PRIVATE
154+
${EIGEN_INCLUDE_DIR}
155+
${LIBIGL_INCLUDE_DIR}
156+
)
153157
endif()
154158

155159
target_link_libraries(${module_name} PRIVATE Threads::Threads)

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ conda create -n igl compas_libigl
1818
A dev version of `compas_libigl` can be installed using a combination of conda and pip.
1919

2020
```bash
21-
conda create -n igl-dev python=3.9 git cmake">=3.14" boost eigen=3.3 pybind11 --yes
21+
conda create -n igl-dev python=3.9 --yes
2222
conda activate igl
23-
git clone --recursive https://github.com/BlockResearchGroup/compas_libigl.git
24-
cd compas_libigl
25-
rm -rf build
26-
pip install -e .
23+
pip install --no-build-isolation -ve .
2724
```
2825

2926
## Libigl functions

src/boundaries.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
#include "boundaries.hpp"
22

3-
void function(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F) {}
3+
using namespace Eigen;
44

5-
NB_MODULE(curvature, m) {
5+
std::vector<std::vector<int>>
6+
trimesh_boundaries(
7+
compas::RowMatrixXi F)
8+
{
9+
std::vector<std::vector<int>> L;
610

11+
igl::boundary_loop(F, L);
12+
13+
return L;
14+
}
15+
16+
NB_MODULE(compas_libigl_boundaries, m) {
717
m.def(
8-
"function_name",
9-
&function,
10-
"Description.",
11-
"V"_a,
12-
"F"_a);
18+
"trimesh_boundaries",
19+
&trimesh_boundaries,
20+
"Compute list of ordered boundary loops for a manifold mesh.",
21+
"F"_a
22+
);
1323
}

0 commit comments

Comments
 (0)