Skip to content

Commit c2cb92e

Browse files
CLEANUP cmakelists function for multiple dynamic libraries.
1 parent cbb046c commit c2cb92e

File tree

1 file changed

+22
-52
lines changed

1 file changed

+22
-52
lines changed

CMakeLists.txt

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -199,61 +199,31 @@ find_package(nanobind CONFIG REQUIRED)
199199
# Important: If you add a new .cpp file, you must rebuild the project with:
200200
# pip install --no-build-isolation -ve . -Ceditable.rebuild=true
201201

202-
# Add the booleans module
203-
nanobind_add_module(
204-
booleans_ext
205-
STABLE_ABI
206-
NB_STATIC
207-
src/booleans.cpp)
208-
209-
# Set include directories for the extension
210-
target_include_directories(booleans_ext PRIVATE
211-
${CGAL_INCLUDE_DIR}
212-
${BOOST_INCLUDE_DIR}
213-
${EIGEN_INCLUDE_DIR}
214-
)
215-
216-
message(STATUS "Checking for src/meshing.cpp")
217-
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/meshing.cpp")
218-
message(STATUS "src/meshing.cpp found")
219-
else()
220-
message(FATAL_ERROR "src/meshing.cpp NOT found")
221-
endif()
222-
223-
# Add the meshing module
224-
nanobind_add_module(
225-
meshing_ext
226-
STABLE_ABI
227-
NB_STATIC
228-
src/meshing.cpp)
229-
230-
# Set include directories for the extension
231-
target_include_directories(meshing_ext PRIVATE
232-
${CGAL_INCLUDE_DIR}
233-
${BOOST_INCLUDE_DIR}
234-
${EIGEN_INCLUDE_DIR}
235-
)
236-
237-
# Make sure external dependencies are downloaded before building the extension
238-
add_dependencies(booleans_ext external_downloads)
239-
add_dependencies(meshing_ext external_downloads)
240-
202+
# Enhanced PCH configuration
241203
if (ENABLE_PRECOMPILED_HEADERS)
242-
# Enhanced PCH configuration
243204
set(CMAKE_PCH_INSTANTIATE_TEMPLATES ON)
244205
set(CMAKE_PCH_WARN_INVALID ON)
206+
endif()
245207

246-
# Configure PCH for the extension
247-
target_precompile_headers(booleans_ext
248-
PRIVATE
249-
src/compas.h
250-
)
251-
target_precompile_headers(meshing_ext
252-
PRIVATE
253-
src/compas.h
208+
# Function to add a nanobind module with include directories
209+
function(add_nanobind_module module_name source_file)
210+
nanobind_add_module(${module_name} STABLE_ABI NB_STATIC ${source_file})
211+
212+
target_include_directories(${module_name} PRIVATE
213+
${CGAL_INCLUDE_DIR}
214+
${BOOST_INCLUDE_DIR}
215+
${EIGEN_INCLUDE_DIR}
254216
)
255-
endif()
256217

257-
# Install directive for scikit-build-core
258-
install(TARGETS booleans_ext LIBRARY DESTINATION compas_cgal)
259-
install(TARGETS meshing_ext LIBRARY DESTINATION compas_cgal)
218+
add_dependencies(${module_name} external_downloads)
219+
220+
if (ENABLE_PRECOMPILED_HEADERS)
221+
target_precompile_headers(${module_name} PRIVATE src/compas.h)
222+
endif()
223+
224+
install(TARGETS ${module_name} LIBRARY DESTINATION compas_cgal)
225+
endfunction()
226+
227+
# Add new modules here
228+
add_nanobind_module(booleans_ext src/booleans.cpp)
229+
add_nanobind_module(meshing_ext src/meshing.cpp)

0 commit comments

Comments
 (0)