-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
244 lines (162 loc) · 5.45 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
cmake_minimum_required(VERSION 3.15)
project(pyclipr VERSION 0.1.0)
# Set c++ to use cx17 as a requirement defined in ClipperLib2
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ version selection")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cMake")
# Copy the include directory if specified
set(INCLUDE_INSTALL_DIR "${INCLUDE_INSTALL_DIR}/pyclipr")
# Generate DLL Pragma for creating shared libraries in Windows
include (GenerateExportHeader)
add_definitions("-DPROJECT_VERSION=\"${PROJECT_VERSION}\"" )
add_definitions("-DNOMINMAX -DFMT_HEADER_ONLY")
# removed -DCPU86
option(BUILD_PYTHON "Builds a python extension" ON)
FUNCTION(PREPEND var prefix)
SET(listVar "")
FOREACH(f ${ARGN})
LIST(APPEND listVar "${prefix}/${f}")
ENDFOREACH(f)
SET(${var} "${listVar}" PARENT_SCOPE)
ENDFUNCTION(PREPEND)
if(WIN32)
# Remove Security definitions for the library
# Remove run time checks for windows
if(MSVC)
set(COMMON_LANGUAGE_RUNTIME "")
set(EIGEN3_INCLUDE_DIR external/eigen)
#target_compile_options(Clipper2 PRIVATE /W4 /WX)
add_compile_options("/GS-"
"/INCREMENTAL:NO")
endif(MSVC)
# Copy the shared libraries and libs to the main directory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
else(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
#target_compile_options(Clipper2 PRIVATE -Wall -Wextra -Wpedantic -Werror)
#target_link_libraries(Clipper2 PUBLIC -lm)
# Find Required packages
find_package(Eigen3 3.3 REQUIRED)
endif(WIN32)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
message(STATUS "Found OpenMP")
set(CLIPR_LIBRARIES
OpenMP::OpenMP_CXX
)
endif(OpenMP_CXX_FOUND)
# Set the base directory for cxx clipperLib2
set(CLIPPER2_INCLUDE_DIR
external/clipper2/CPP
)
# Use the replacement of Boost::filesystem from a git submodule provided by WJakob
# in order to reduce compile time dependencies
# https://github.com/wjakob/filesystem
set(CPP_FILESYSTEM
external/filesystem
)
## A replacement library for std::Format
set(CPP_FMT
external/fmt/include
)
add_definitions(-DUSINGZ=1)
link_directories(
)
if(BUILD_PYTHON)
message(STATUS "Building PyClipr Python Module")
add_subdirectory(external/pybind11)
set(PYBIND11_CPP_STANDARD /std:c++17)
endif(BUILD_PYTHON)
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_BINARY_DIR}
${EIGEN3_INCLUDE_DIR}
${CLIPPER2_INCLUDE_DIR}
${CLIPPER2_INCLUDE_DIR}/Clipper2Lib/include
${CPP_FMT}
)
link_directories(
)
set(CLIPPER2_INC
Clipper2Lib/include/clipper2/clipper.h
Clipper2Lib/include/clipper2/clipper.core.h
Clipper2Lib/include/clipper2/clipper.engine.h
Clipper2Lib/include/clipper2/clipper.export.h
Clipper2Lib/include/clipper2/clipper.minkowski.h
Clipper2Lib/include/clipper2/clipper.offset.h
Clipper2Lib/include/clipper2/clipper.rectclip.h
)
set(CLIPPER2_SRCS
Clipper2Lib/src/clipper.engine.cpp
Clipper2Lib/src/clipper.offset.cpp
Clipper2Lib/src/clipper.rectclip.cpp
)
set(APP_SRCS
${CLIPPER2_INC}
${CLIPPER2_SRCS}
)
PREPEND(APP_SRCS "${CLIPPER2_INCLUDE_DIR}/" ${APP_SRCS})
SOURCE_GROUP("App" FILES
${APP_SRCS}
)
set(LIBCLIPR_SRCS
${APP_SRCS}
)
set(PYCLIPR_LIBS
${CLIPR_LIBRARIES}
)
if(BUILD_PYTHON)
# Add the library
message(STATUS "Building PyClipr Python - Static Library")
add_definitions("-DCLIPR_BUILT_AS_STATIC")
add_library(clipr_static STATIC ${LIBCLIPR_SRCS})
target_link_libraries(clipr_static PRIVATE ${PYCLIPR_LIBS})
GENERATE_EXPORT_HEADER(clipr_static
BASE_NAME CLIPR
EXPORT_MACRO_NAME CLIPR_EXPORT
EXPORT_FILE_NAME CLIPR_Export.h
STATIC_DEFINE CLIPR_BUILT_AS_STATIC)
else(BUILD_PYTHON)
message(STATUS "Building PyClipr Module Standalone - Dynamic Library")
add_library(clipr SHARED ${LIBCLIPR_SRCS})
target_link_libraries(clipr ${PYCLIPR_LIBS})
GENERATE_EXPORT_HEADER(clipr
BASE_NAME CLIPR
EXPORT_MACRO_NAME CLIPR_EXPORT
EXPORT_FILE_NAME CLIPR_Export.h
STATIC_DEFINE CLIPR_BUILT_AS_STATIC)
endif(BUILD_PYTHON)
set(App_SRCS
main.cpp
)
SOURCE_GROUP("App" FILES ${App_SRCS})
if(BUILD_PYTHON)
set(PYCLIPR_SRCS
python/pyclipr/module.cpp
)
SOURCE_GROUP("Python" FILES ${PYCLIPR_SRCS})
pybind11_add_module(pyclipr ${PYCLIPR_SRCS})
#add_library(example MODULE main.cpp)
target_link_libraries(pyclipr PRIVATE pybind11::module clipr_static ${PYCLIPR_LIBS})
set_target_properties(pyclipr PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")
install(TARGETS pyclipr DESTINATION lib/pyclipr)
else(BUILD_PYTHON)
add_executable(main ${App_SRCS})
target_link_libraries(main clipr ${PYCLIPR_LIBS})
#install(TARGETS mpir DESTINATION )
endif(BUILD_PYTHON)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/CLIPR_Export.h
${APP_H_SRCS}
DESTINATION include/pyclipr
)