Skip to content

Commit ae5e1b0

Browse files
author
pv
committed
CMAKE simplify the fetch content and move install to cache section
1 parent 7a59bd3 commit ae5e1b0

File tree

1 file changed

+32
-43
lines changed

1 file changed

+32
-43
lines changed

CMakeLists.txt

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,15 @@ if(EXISTS "${EIGEN_DIR}")
4747
message(STATUS "Using existing Eigen from ${EIGEN_DIR}")
4848
set(eigen_SOURCE_DIR "${EIGEN_DIR}")
4949
set(eigen_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/eigen-build")
50-
FetchContent_Declare(
51-
eigen
52-
URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
53-
SOURCE_DIR "${eigen_SOURCE_DIR}"
54-
BINARY_DIR "${eigen_BINARY_DIR}"
55-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
56-
)
57-
else()
58-
FetchContent_Declare(
59-
eigen
60-
URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
61-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
62-
)
6350
endif()
51+
52+
FetchContent_Declare(
53+
eigen
54+
URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
55+
SOURCE_DIR "${eigen_SOURCE_DIR}"
56+
BINARY_DIR "${eigen_BINARY_DIR}"
57+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
58+
)
6459
FetchContent_MakeAvailable(eigen)
6560

6661
# === libigl ===
@@ -70,20 +65,15 @@ if(EXISTS "${LIBIGL_DIR}")
7065
message(STATUS "Using existing libigl from ${LIBIGL_DIR}")
7166
set(libigl_SOURCE_DIR "${LIBIGL_DIR}")
7267
set(libigl_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/libigl-build")
73-
FetchContent_Declare(
74-
libigl
75-
GIT_REPOSITORY https://github.com/libigl/libigl.git
76-
GIT_TAG main
77-
SOURCE_DIR "${libigl_SOURCE_DIR}"
78-
BINARY_DIR "${libigl_BINARY_DIR}"
79-
)
80-
else()
81-
FetchContent_Declare(
82-
libigl
83-
GIT_REPOSITORY https://github.com/libigl/libigl.git
84-
GIT_TAG main
85-
)
8668
endif()
69+
70+
FetchContent_Declare(
71+
libigl
72+
GIT_REPOSITORY https://github.com/libigl/libigl.git
73+
GIT_TAG main
74+
SOURCE_DIR "${libigl_SOURCE_DIR}"
75+
BINARY_DIR "${libigl_BINARY_DIR}"
76+
)
8777
FetchContent_MakeAvailable(libigl)
8878

8979
# === Clipper2 ===
@@ -93,20 +83,15 @@ if(EXISTS "${CLIPPER2_DIR}")
9383
message(STATUS "Using existing Clipper2 from ${CLIPPER2_DIR}")
9484
set(clipper2_SOURCE_DIR "${CLIPPER2_DIR}")
9585
set(clipper2_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/clipper2-build")
96-
FetchContent_Declare(
97-
clipper2
98-
URL https://github.com/AngusJohnson/Clipper2/releases/download/Clipper2_1.5.3/Clipper2_1.5.3.zip
99-
SOURCE_DIR "${clipper2_SOURCE_DIR}"
100-
BINARY_DIR "${clipper2_BINARY_DIR}"
101-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
102-
)
103-
else()
104-
FetchContent_Declare(
105-
clipper2
106-
URL https://github.com/AngusJohnson/Clipper2/releases/download/Clipper2_1.5.3/Clipper2_1.5.3.zip
107-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
108-
)
10986
endif()
87+
88+
FetchContent_Declare(
89+
clipper2
90+
URL https://github.com/AngusJohnson/Clipper2/releases/download/Clipper2_1.5.3/Clipper2_1.5.3.zip
91+
SOURCE_DIR "${clipper2_SOURCE_DIR}"
92+
BINARY_DIR "${clipper2_BINARY_DIR}"
93+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
94+
)
11095
FetchContent_MakeAvailable(clipper2)
11196

11297
# Build Clipper2 as a static library
@@ -116,6 +101,14 @@ add_library(clipper2_static STATIC ${CLIPPER2_SRC})
116101
target_include_directories(clipper2_static PUBLIC "${clipper2_SOURCE_DIR}/CPP/Clipper2Lib/include")
117102
set_target_properties(clipper2_static PROPERTIES POSITION_INDEPENDENT_CODE ON)
118103

104+
# Install clipper2 static lib and headers if not already installed
105+
set(CLIPPER2_HEADERS_DEST "${CMAKE_INSTALL_PREFIX}/include/clipper2")
106+
if(NOT EXISTS "${CLIPPER2_HEADERS_DEST}")
107+
message(STATUS "Installing Clipper2 headers and library")
108+
install(TARGETS clipper2_static ARCHIVE DESTINATION lib)
109+
install(DIRECTORY "${clipper2_SOURCE_DIR}/CPP/Clipper2Lib/include/clipper2" DESTINATION include)
110+
endif()
111+
119112
# === Include paths ===
120113
set(EIGEN_INCLUDE_DIR ${eigen_SOURCE_DIR})
121114
set(LIBIGL_INCLUDE_DIR ${libigl_SOURCE_DIR}/include)
@@ -169,7 +162,3 @@ add_nanobind_module(_meshing src/meshing.cpp)
169162
add_nanobind_module(_parametrisation src/parametrisation.cpp)
170163
add_nanobind_module(_planarize src/planarize.cpp)
171164
add_nanobind_module(_mapping src/mapping.cpp)
172-
173-
# === Install clipper2 static lib and headers ===
174-
install(TARGETS clipper2_static ARCHIVE DESTINATION lib)
175-
install(DIRECTORY "${clipper2_SOURCE_DIR}/CPP/Clipper2Lib/include/clipper2" DESTINATION include)

0 commit comments

Comments
 (0)