Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/cad/cura-engine/files/CMakeLists.txt
16462 views
1
#Copyright (c) 2020 Ultimaker B.V.
2
#CuraEngine is released under the terms of the AGPLv3 or higher.
3
4
cmake_minimum_required(VERSION 3.8.0)
5
6
project(CuraEngine)
7
8
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
9
10
option(ENABLE_ARCUS "Enable support for ARCUS" ON)
11
12
if (MSVC)
13
option(MSVC_STATIC_RUNTIME "Link the MSVC runtime statically" OFF)
14
endif()
15
16
if(ENABLE_ARCUS)
17
message(STATUS "Building with Arcus")
18
# We want to have access to protobuf_generate_cpp and other FindProtobuf features.
19
# However, if ProtobufConfig is used instead, there is a CMake option that controls
20
# this, which defaults to OFF. We need to force this option to ON instead.
21
set(protobuf_MODULE_COMPATIBLE ON CACHE INTERNAL "" FORCE)
22
find_package(Protobuf 3.0.0 REQUIRED)
23
find_package(Arcus REQUIRED)
24
add_definitions(-DARCUS)
25
find_program(PROTOC "protoc")
26
if(${PROTOC} STREQUAL "PROTOC-NOTFOUND")
27
message(FATAL_ERROR "Protobuf compiler missing")
28
endif()
29
endif()
30
31
#For reading image files.
32
find_package(Stb REQUIRED)
33
include_directories(${Stb_INCLUDE_DIRS})
34
35
option(USE_SYSTEM_LIBS "Use the system libraries if available" OFF)
36
if(USE_SYSTEM_LIBS)
37
find_package(RapidJSON CONFIG REQUIRED)
38
find_package(Polyclipping REQUIRED)
39
endif()
40
41
# convert build type to upper case letters
42
if(CMAKE_BUILD_TYPE)
43
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
44
endif()
45
46
if(CMAKE_BUILD_TYPE_UPPER MATCHES "DEBUG")
47
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG_INIT}")
48
else()
49
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE_INIT}")
50
endif()
51
52
set(CMAKE_CXX_STANDARD 20)
53
54
if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
55
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
56
endif()
57
58
OPTION(SET_RPATH ON)
59
60
if(SET_RPATH)
61
if(NOT DEFINED LIB_SUFFIX)
62
set(LIB_SUFFIX "")
63
endif()
64
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
65
endif()
66
67
set(CURA_ENGINE_VERSION "master" CACHE STRING "Version name of Cura")
68
69
option(BUILD_TESTS OFF)
70
71
# Add a compiler flag to check the output for insane values if we are in debug mode.
72
if(CMAKE_BUILD_TYPE_UPPER MATCHES "DEBUG" OR CMAKE_BUILD_TYPE_UPPER MATCHES "RELWITHDEBINFO")
73
message(STATUS "Building debug release of CuraEngine.")
74
if (NOT MSVC)
75
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -O0 -g -fno-omit-frame-pointer")
76
endif()
77
add_definitions(-DASSERT_INSANE_OUTPUT)
78
add_definitions(-DUSE_CPU_TIME)
79
add_definitions(-DDEBUG)
80
endif()
81
82
if (MSVC)
83
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive- /Zc:twoPhase- /EHsc /W3")
84
if (MSVC_STATIC_RUNTIME)
85
foreach(flag_var
86
CMAKE_CXX_FLAGS
87
CMAKE_CXX_FLAGS_DEBUG
88
CMAKE_CXX_FLAGS_RELEASE
89
CMAKE_CXX_FLAGS_MINSIZEREL
90
CMAKE_CXX_FLAGS_RELWITHDEBINFO
91
)
92
if(${flag_var} MATCHES "/MD")
93
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
94
endif()
95
endforeach()
96
endif()
97
else()
98
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") # Add warnings
99
endif()
100
101
option (ENABLE_MORE_COMPILER_OPTIMIZATION_FLAGS
102
"Enable more optimization flags" ON)
103
if (ENABLE_MORE_COMPILER_OPTIMIZATION_FLAGS AND NOT (CMAKE_BUILD_TYPE_UPPER MATCHES "DEBUG"))
104
message (STATUS "Compile with more optimization flags")
105
if (MSVC)
106
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /fp:fast")
107
else()
108
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Ofast -funroll-loops")
109
endif()
110
endif ()
111
112
#if(NOT APPLE AND NOT WIN32)
113
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++")
114
#endif()
115
116
if (WIN32)
117
add_definitions(-DNOMINMAX)
118
endif()
119
120
add_definitions(-DSPDLOG_FMT_EXTERNAL)
121
122
option (ENABLE_OPENMP
123
"Use OpenMP for parallel code" ON)
124
125
if (ENABLE_OPENMP)
126
FIND_PACKAGE( OpenMP )
127
if( OPENMP_FOUND )
128
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
129
endif()
130
endif()
131
132
if(USE_SYSTEM_LIBS)
133
include_directories(${Polyclipping_INCLUDE_DIRS} "${CMAKE_BINARY_DIR}" ${RAPIDJSON_INCLUDE_DIRS} include)
134
else()
135
include_directories("${CMAKE_CURRENT_BINARY_DIR}" libs libs/clipper include)
136
add_library(clipper STATIC libs/clipper/clipper.cpp)
137
endif()
138
139
set(engine_SRCS # Except main.cpp.
140
src/Application.cpp
141
src/ConicalOverhang.cpp
142
src/ExtruderPlan.cpp
143
src/ExtruderTrain.cpp
144
src/FffGcodeWriter.cpp
145
src/FffPolygonGenerator.cpp
146
src/FffProcessor.cpp
147
src/GCodePathConfig.cpp
148
src/InsetOrderOptimizer.cpp
149
src/InterlockingGenerator.cpp
150
src/LayerPlan.cpp
151
src/LayerPlanBuffer.cpp
152
src/MeshGroup.cpp
153
src/Mold.cpp
154
src/PathOrderPath.cpp
155
src/Preheat.cpp
156
src/PrimeTower.cpp
157
src/Scene.cpp
158
src/SkeletalTrapezoidation.cpp
159
src/SkeletalTrapezoidationGraph.cpp
160
src/SkirtBrim.cpp
161
src/Slice.cpp
162
src/SupportInfillPart.cpp
163
src/TopSurface.cpp
164
src/TreeModelVolumes.cpp
165
src/TreeSupport.cpp
166
src/TreeSupportTipGenerator.cpp
167
src/WallToolPaths.cpp
168
src/WallsComputation.cpp
169
src/bridge.cpp
170
src/gcodeExport.cpp
171
src/infill.cpp
172
src/layerPart.cpp
173
src/main.cpp
174
src/mesh.cpp
175
src/multiVolumes.cpp
176
src/raft.cpp
177
src/skin.cpp
178
src/sliceDataStorage.cpp
179
src/slicer.cpp
180
src/support.cpp
181
src/timeEstimate.cpp
182
183
src/BeadingStrategy/BeadingStrategy.cpp
184
src/BeadingStrategy/BeadingStrategyFactory.cpp
185
src/BeadingStrategy/DistributedBeadingStrategy.cpp
186
src/BeadingStrategy/LimitedBeadingStrategy.cpp
187
src/BeadingStrategy/OuterWallInsetBeadingStrategy.cpp
188
src/BeadingStrategy/RedistributeBeadingStrategy.cpp
189
src/BeadingStrategy/WideningBeadingStrategy.cpp
190
191
src/communication/ArcusCommunication.cpp
192
src/communication/ArcusCommunicationPrivate.cpp
193
src/communication/CommandLine.cpp
194
src/communication/Listener.cpp
195
196
src/infill/GyroidInfill.cpp
197
src/infill/ImageBasedDensityProvider.cpp
198
src/infill/LightningDistanceField.cpp
199
src/infill/LightningGenerator.cpp
200
src/infill/LightningLayer.cpp
201
src/infill/LightningTreeNode.cpp
202
src/infill/NoZigZagConnectorProcessor.cpp
203
src/infill/SierpinskiFill.cpp
204
src/infill/SierpinskiFillProvider.cpp
205
src/infill/SubDivCube.cpp
206
src/infill/ZigzagConnectorProcessor.cpp
207
208
src/pathPlanning/Comb.cpp
209
src/pathPlanning/GCodePath.cpp
210
src/pathPlanning/LinePolygonsCrossings.cpp
211
src/pathPlanning/NozzleTempInsert.cpp
212
src/pathPlanning/SpeedDerivatives.cpp
213
214
src/progress/Progress.cpp
215
src/progress/ProgressStageEstimator.cpp
216
217
src/settings/AdaptiveLayerHeights.cpp
218
src/settings/FlowTempGraph.cpp
219
src/settings/MeshPathConfigs.cpp
220
src/settings/PathConfigStorage.cpp
221
src/settings/Settings.cpp
222
src/settings/ZSeamConfig.cpp
223
224
src/utils/AABB.cpp
225
src/utils/AABB3D.cpp
226
src/utils/Date.cpp
227
src/utils/ExtrusionJunction.cpp
228
src/utils/ExtrusionLine.cpp
229
src/utils/ExtrusionSegment.cpp
230
src/utils/LinearAlg2D.cpp
231
src/utils/ListPolyIt.cpp
232
src/utils/Matrix4x3D.cpp
233
src/utils/MinimumSpanningTree.cpp
234
src/utils/Point3LL.cpp
235
src/utils/PolygonConnector.cpp
236
src/utils/PolygonsPointIndex.cpp
237
src/utils/PolygonsSegmentIndex.cpp
238
src/utils/PolylineStitcher.cpp
239
src/utils/SVG.cpp
240
src/utils/Simplify.cpp
241
src/utils/SquareGrid.cpp
242
src/utils/ThreadPool.cpp
243
src/utils/ToolpathVisualizer.cpp
244
src/utils/VoronoiUtils.cpp
245
src/utils/VoxelUtils.cpp
246
src/utils/channel.cpp
247
src/utils/gettime.cpp
248
src/utils/polygon.cpp
249
src/utils/polygonUtils.cpp
250
)
251
252
# List of tests. For each test there must be a file tests/${NAME}.cpp.
253
set(engine_TEST
254
GCodeExportTest
255
InfillTest
256
LayerPlanTest
257
MergeInfillLinesTest
258
PathOrderMonotonicTest
259
TimeEstimateCalculatorTest
260
)
261
set(engine_TEST_INTEGRATION
262
SlicePhaseTest
263
)
264
set(engine_TEST_SETTINGS
265
SettingsTest
266
)
267
if (ENABLE_ARCUS)
268
set(engine_TEST_ARCUS
269
ArcusCommunicationTest
270
ArcusCommunicationPrivateTest
271
)
272
endif ()
273
set(engine_TEST_UTILS
274
AABBTest
275
AABB3DTest
276
IntPointTest
277
LinearAlg2DTest
278
MinimumSpanningTreeTest
279
PolygonConnectorTest
280
PolygonTest
281
PolygonUtilsTest
282
SparseGridTest
283
StringTest
284
UnionFindTest
285
)
286
287
# Helper classes for some tests.
288
set(engine_TEST_ARCUS_HELPERS
289
tests/arcus/MockSocket.cpp
290
)
291
set(engine_TEST_HELPERS
292
tests/ReadTestPolygons.cpp
293
)
294
295
# Generating ProtoBuf protocol
296
if (ENABLE_ARCUS)
297
protobuf_generate_cpp(engine_PB_SRCS engine_PB_HEADERS Cura.proto)
298
endif ()
299
300
# Compiling CuraEngine itself.
301
add_library(_CuraEngine STATIC ${engine_SRCS} ${engine_PB_SRCS}) #First compile all of CuraEngine as library, allowing this to be re-used for tests.
302
303
if (CuraEngine_Download_Stb)
304
add_dependencies(_CuraEngine stb)
305
endif()
306
if(USE_SYSTEM_LIBS)
307
target_link_libraries(_CuraEngine ${Polyclipping_LIBRARIES})
308
else()
309
target_link_libraries(_CuraEngine clipper)
310
endif()
311
312
if (ENABLE_ARCUS)
313
target_link_libraries(_CuraEngine Arcus)
314
endif ()
315
316
target_link_libraries(_CuraEngine fmt absl_log_internal_message absl_log_internal_check_op)
317
318
set_target_properties(_CuraEngine PROPERTIES COMPILE_DEFINITIONS "VERSION=\"${CURA_ENGINE_VERSION}\"")
319
320
if(WIN32)
321
message(STATUS "Using windres")
322
set(RES_FILES "CuraEngine.rc")
323
ENABLE_LANGUAGE(RC)
324
if(NOT MSVC)
325
SET(CMAKE_RC_COMPILER_INIT windres)
326
SET(CMAKE_RC_COMPILE_OBJECT
327
"<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>"
328
)
329
endif()
330
endif(WIN32)
331
332
if (UNIX)
333
target_link_libraries(_CuraEngine pthread)
334
endif()
335
336
if (NOT WIN32)
337
add_executable(CuraEngine src/main.cpp) # Then compile main.cpp as separate executable, and link the library to it.
338
else()
339
add_executable(CuraEngine src/main.cpp ${RES_FILES}) # ..., but don't forget the glitter!
340
endif(NOT WIN32)
341
342
target_link_libraries(CuraEngine _CuraEngine)
343
set_target_properties(CuraEngine PROPERTIES COMPILE_DEFINITIONS "VERSION=\"${CURA_ENGINE_VERSION}\"")
344
345
# Compiling the test environment.
346
if (BUILD_TESTS)
347
include(CTest)
348
349
message(STATUS "Building tests...")
350
set(GTEST_USE_STATIC_LIBS true)
351
set(GMOCK_ROOT "${CMAKE_CURRENT_BINARY_DIR}/gmock")
352
set(GMOCK_VER "1.8.0")
353
find_package(GMock REQUIRED)
354
include_directories(${GTEST_INCLUDE_DIRS})
355
include_directories(${GMOCK_INCLUDE_DIRS})
356
add_dependencies(_CuraEngine GTest::GTest GTest::Main GMock::GMock GMock::Main)
357
add_definitions(-DBUILD_TESTS)
358
359
target_compile_definitions(_CuraEngine PUBLIC BUILD_TESTS=1)
360
361
#To make sure that the tests are built before running them, add the building of these tests as an additional test.
362
add_custom_target(build_all_tests)
363
add_test(BuildTests "${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}" --target build_all_tests)
364
365
foreach (test ${engine_TEST})
366
add_executable(${test} tests/main.cpp ${engine_TEST_HELPERS} tests/${test}.cpp)
367
target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})
368
add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
369
add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.
370
endforeach()
371
foreach (test ${engine_TEST_INFILL})
372
add_executable(${test} tests/main.cpp tests/infill/${test}.cpp)
373
target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})
374
add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
375
add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.
376
endforeach()
377
foreach (test ${engine_TEST_INTEGRATION})
378
add_executable(${test} tests/main.cpp tests/integration/${test}.cpp)
379
target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})
380
add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
381
add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.
382
endforeach()
383
foreach (test ${engine_TEST_SETTINGS})
384
add_executable(${test} tests/main.cpp tests/settings/${test}.cpp)
385
target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})
386
add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
387
add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.
388
endforeach()
389
if (ENABLE_ARCUS)
390
foreach (test ${engine_TEST_ARCUS})
391
add_executable(${test} tests/main.cpp ${engine_TEST_ARCUS_HELPERS} tests/arcus/${test}.cpp)
392
target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})
393
add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
394
add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.
395
endforeach()
396
endif ()
397
foreach (test ${engine_TEST_UTILS})
398
add_executable(${test} tests/main.cpp tests/utils/${test}.cpp)
399
target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})
400
add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
401
add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.
402
endforeach()
403
endif()
404
405
# Installing CuraEngine.
406
include(GNUInstallDirs)
407
install(TARGETS CuraEngine DESTINATION "${CMAKE_INSTALL_BINDIR}")
408
# For MinGW64 cross compiling on Debian, we create a ZIP package instead of a DEB
409
# Because it's the Windows build system that should install the files.
410
if (CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME MATCHES "Windows")
411
message(STATUS "Include MinGW64 posix DLLs for installation.")
412
install(FILES
413
/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/libgcc_s_seh-1.dll
414
/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/libgomp-1.dll
415
/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/libstdc++-6.dll
416
DESTINATION bin
417
COMPONENT runtime)
418
endif ()
419
include(CPackConfig.cmake)
420
421