Path: blob/main/cad/cura-engine/files/CMakeLists.txt
16462 views
#Copyright (c) 2020 Ultimaker B.V.1#CuraEngine is released under the terms of the AGPLv3 or higher.23cmake_minimum_required(VERSION 3.8.0)45project(CuraEngine)67list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")89option(ENABLE_ARCUS "Enable support for ARCUS" ON)1011if (MSVC)12option(MSVC_STATIC_RUNTIME "Link the MSVC runtime statically" OFF)13endif()1415if(ENABLE_ARCUS)16message(STATUS "Building with Arcus")17# We want to have access to protobuf_generate_cpp and other FindProtobuf features.18# However, if ProtobufConfig is used instead, there is a CMake option that controls19# this, which defaults to OFF. We need to force this option to ON instead.20set(protobuf_MODULE_COMPATIBLE ON CACHE INTERNAL "" FORCE)21find_package(Protobuf 3.0.0 REQUIRED)22find_package(Arcus REQUIRED)23add_definitions(-DARCUS)24find_program(PROTOC "protoc")25if(${PROTOC} STREQUAL "PROTOC-NOTFOUND")26message(FATAL_ERROR "Protobuf compiler missing")27endif()28endif()2930#For reading image files.31find_package(Stb REQUIRED)32include_directories(${Stb_INCLUDE_DIRS})3334option(USE_SYSTEM_LIBS "Use the system libraries if available" OFF)35if(USE_SYSTEM_LIBS)36find_package(RapidJSON CONFIG REQUIRED)37find_package(Polyclipping REQUIRED)38endif()3940# convert build type to upper case letters41if(CMAKE_BUILD_TYPE)42string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)43endif()4445if(CMAKE_BUILD_TYPE_UPPER MATCHES "DEBUG")46set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG_INIT}")47else()48set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE_INIT}")49endif()5051set(CMAKE_CXX_STANDARD 20)5253if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")54set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")55endif()5657OPTION(SET_RPATH ON)5859if(SET_RPATH)60if(NOT DEFINED LIB_SUFFIX)61set(LIB_SUFFIX "")62endif()63set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")64endif()6566set(CURA_ENGINE_VERSION "master" CACHE STRING "Version name of Cura")6768option(BUILD_TESTS OFF)6970# Add a compiler flag to check the output for insane values if we are in debug mode.71if(CMAKE_BUILD_TYPE_UPPER MATCHES "DEBUG" OR CMAKE_BUILD_TYPE_UPPER MATCHES "RELWITHDEBINFO")72message(STATUS "Building debug release of CuraEngine.")73if (NOT MSVC)74set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -O0 -g -fno-omit-frame-pointer")75endif()76add_definitions(-DASSERT_INSANE_OUTPUT)77add_definitions(-DUSE_CPU_TIME)78add_definitions(-DDEBUG)79endif()8081if (MSVC)82set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive- /Zc:twoPhase- /EHsc /W3")83if (MSVC_STATIC_RUNTIME)84foreach(flag_var85CMAKE_CXX_FLAGS86CMAKE_CXX_FLAGS_DEBUG87CMAKE_CXX_FLAGS_RELEASE88CMAKE_CXX_FLAGS_MINSIZEREL89CMAKE_CXX_FLAGS_RELWITHDEBINFO90)91if(${flag_var} MATCHES "/MD")92string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")93endif()94endforeach()95endif()96else()97set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") # Add warnings98endif()99100option (ENABLE_MORE_COMPILER_OPTIMIZATION_FLAGS101"Enable more optimization flags" ON)102if (ENABLE_MORE_COMPILER_OPTIMIZATION_FLAGS AND NOT (CMAKE_BUILD_TYPE_UPPER MATCHES "DEBUG"))103message (STATUS "Compile with more optimization flags")104if (MSVC)105set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /fp:fast")106else()107set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Ofast -funroll-loops")108endif()109endif ()110111#if(NOT APPLE AND NOT WIN32)112# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++")113#endif()114115if (WIN32)116add_definitions(-DNOMINMAX)117endif()118119add_definitions(-DSPDLOG_FMT_EXTERNAL)120121option (ENABLE_OPENMP122"Use OpenMP for parallel code" ON)123124if (ENABLE_OPENMP)125FIND_PACKAGE( OpenMP )126if( OPENMP_FOUND )127set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )128endif()129endif()130131if(USE_SYSTEM_LIBS)132include_directories(${Polyclipping_INCLUDE_DIRS} "${CMAKE_BINARY_DIR}" ${RAPIDJSON_INCLUDE_DIRS} include)133else()134include_directories("${CMAKE_CURRENT_BINARY_DIR}" libs libs/clipper include)135add_library(clipper STATIC libs/clipper/clipper.cpp)136endif()137138set(engine_SRCS # Except main.cpp.139src/Application.cpp140src/ConicalOverhang.cpp141src/ExtruderPlan.cpp142src/ExtruderTrain.cpp143src/FffGcodeWriter.cpp144src/FffPolygonGenerator.cpp145src/FffProcessor.cpp146src/GCodePathConfig.cpp147src/InsetOrderOptimizer.cpp148src/InterlockingGenerator.cpp149src/LayerPlan.cpp150src/LayerPlanBuffer.cpp151src/MeshGroup.cpp152src/Mold.cpp153src/PathOrderPath.cpp154src/Preheat.cpp155src/PrimeTower.cpp156src/Scene.cpp157src/SkeletalTrapezoidation.cpp158src/SkeletalTrapezoidationGraph.cpp159src/SkirtBrim.cpp160src/Slice.cpp161src/SupportInfillPart.cpp162src/TopSurface.cpp163src/TreeModelVolumes.cpp164src/TreeSupport.cpp165src/TreeSupportTipGenerator.cpp166src/WallToolPaths.cpp167src/WallsComputation.cpp168src/bridge.cpp169src/gcodeExport.cpp170src/infill.cpp171src/layerPart.cpp172src/main.cpp173src/mesh.cpp174src/multiVolumes.cpp175src/raft.cpp176src/skin.cpp177src/sliceDataStorage.cpp178src/slicer.cpp179src/support.cpp180src/timeEstimate.cpp181182src/BeadingStrategy/BeadingStrategy.cpp183src/BeadingStrategy/BeadingStrategyFactory.cpp184src/BeadingStrategy/DistributedBeadingStrategy.cpp185src/BeadingStrategy/LimitedBeadingStrategy.cpp186src/BeadingStrategy/OuterWallInsetBeadingStrategy.cpp187src/BeadingStrategy/RedistributeBeadingStrategy.cpp188src/BeadingStrategy/WideningBeadingStrategy.cpp189190src/communication/ArcusCommunication.cpp191src/communication/ArcusCommunicationPrivate.cpp192src/communication/CommandLine.cpp193src/communication/Listener.cpp194195src/infill/GyroidInfill.cpp196src/infill/ImageBasedDensityProvider.cpp197src/infill/LightningDistanceField.cpp198src/infill/LightningGenerator.cpp199src/infill/LightningLayer.cpp200src/infill/LightningTreeNode.cpp201src/infill/NoZigZagConnectorProcessor.cpp202src/infill/SierpinskiFill.cpp203src/infill/SierpinskiFillProvider.cpp204src/infill/SubDivCube.cpp205src/infill/ZigzagConnectorProcessor.cpp206207src/pathPlanning/Comb.cpp208src/pathPlanning/GCodePath.cpp209src/pathPlanning/LinePolygonsCrossings.cpp210src/pathPlanning/NozzleTempInsert.cpp211src/pathPlanning/SpeedDerivatives.cpp212213src/progress/Progress.cpp214src/progress/ProgressStageEstimator.cpp215216src/settings/AdaptiveLayerHeights.cpp217src/settings/FlowTempGraph.cpp218src/settings/MeshPathConfigs.cpp219src/settings/PathConfigStorage.cpp220src/settings/Settings.cpp221src/settings/ZSeamConfig.cpp222223src/utils/AABB.cpp224src/utils/AABB3D.cpp225src/utils/Date.cpp226src/utils/ExtrusionJunction.cpp227src/utils/ExtrusionLine.cpp228src/utils/ExtrusionSegment.cpp229src/utils/LinearAlg2D.cpp230src/utils/ListPolyIt.cpp231src/utils/Matrix4x3D.cpp232src/utils/MinimumSpanningTree.cpp233src/utils/Point3LL.cpp234src/utils/PolygonConnector.cpp235src/utils/PolygonsPointIndex.cpp236src/utils/PolygonsSegmentIndex.cpp237src/utils/PolylineStitcher.cpp238src/utils/SVG.cpp239src/utils/Simplify.cpp240src/utils/SquareGrid.cpp241src/utils/ThreadPool.cpp242src/utils/ToolpathVisualizer.cpp243src/utils/VoronoiUtils.cpp244src/utils/VoxelUtils.cpp245src/utils/channel.cpp246src/utils/gettime.cpp247src/utils/polygon.cpp248src/utils/polygonUtils.cpp249)250251# List of tests. For each test there must be a file tests/${NAME}.cpp.252set(engine_TEST253GCodeExportTest254InfillTest255LayerPlanTest256MergeInfillLinesTest257PathOrderMonotonicTest258TimeEstimateCalculatorTest259)260set(engine_TEST_INTEGRATION261SlicePhaseTest262)263set(engine_TEST_SETTINGS264SettingsTest265)266if (ENABLE_ARCUS)267set(engine_TEST_ARCUS268ArcusCommunicationTest269ArcusCommunicationPrivateTest270)271endif ()272set(engine_TEST_UTILS273AABBTest274AABB3DTest275IntPointTest276LinearAlg2DTest277MinimumSpanningTreeTest278PolygonConnectorTest279PolygonTest280PolygonUtilsTest281SparseGridTest282StringTest283UnionFindTest284)285286# Helper classes for some tests.287set(engine_TEST_ARCUS_HELPERS288tests/arcus/MockSocket.cpp289)290set(engine_TEST_HELPERS291tests/ReadTestPolygons.cpp292)293294# Generating ProtoBuf protocol295if (ENABLE_ARCUS)296protobuf_generate_cpp(engine_PB_SRCS engine_PB_HEADERS Cura.proto)297endif ()298299# Compiling CuraEngine itself.300add_library(_CuraEngine STATIC ${engine_SRCS} ${engine_PB_SRCS}) #First compile all of CuraEngine as library, allowing this to be re-used for tests.301302if (CuraEngine_Download_Stb)303add_dependencies(_CuraEngine stb)304endif()305if(USE_SYSTEM_LIBS)306target_link_libraries(_CuraEngine ${Polyclipping_LIBRARIES})307else()308target_link_libraries(_CuraEngine clipper)309endif()310311if (ENABLE_ARCUS)312target_link_libraries(_CuraEngine Arcus)313endif ()314315target_link_libraries(_CuraEngine fmt absl_log_internal_message absl_log_internal_check_op)316317set_target_properties(_CuraEngine PROPERTIES COMPILE_DEFINITIONS "VERSION=\"${CURA_ENGINE_VERSION}\"")318319if(WIN32)320message(STATUS "Using windres")321set(RES_FILES "CuraEngine.rc")322ENABLE_LANGUAGE(RC)323if(NOT MSVC)324SET(CMAKE_RC_COMPILER_INIT windres)325SET(CMAKE_RC_COMPILE_OBJECT326"<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>"327)328endif()329endif(WIN32)330331if (UNIX)332target_link_libraries(_CuraEngine pthread)333endif()334335if (NOT WIN32)336add_executable(CuraEngine src/main.cpp) # Then compile main.cpp as separate executable, and link the library to it.337else()338add_executable(CuraEngine src/main.cpp ${RES_FILES}) # ..., but don't forget the glitter!339endif(NOT WIN32)340341target_link_libraries(CuraEngine _CuraEngine)342set_target_properties(CuraEngine PROPERTIES COMPILE_DEFINITIONS "VERSION=\"${CURA_ENGINE_VERSION}\"")343344# Compiling the test environment.345if (BUILD_TESTS)346include(CTest)347348message(STATUS "Building tests...")349set(GTEST_USE_STATIC_LIBS true)350set(GMOCK_ROOT "${CMAKE_CURRENT_BINARY_DIR}/gmock")351set(GMOCK_VER "1.8.0")352find_package(GMock REQUIRED)353include_directories(${GTEST_INCLUDE_DIRS})354include_directories(${GMOCK_INCLUDE_DIRS})355add_dependencies(_CuraEngine GTest::GTest GTest::Main GMock::GMock GMock::Main)356add_definitions(-DBUILD_TESTS)357358target_compile_definitions(_CuraEngine PUBLIC BUILD_TESTS=1)359360#To make sure that the tests are built before running them, add the building of these tests as an additional test.361add_custom_target(build_all_tests)362add_test(BuildTests "${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}" --target build_all_tests)363364foreach (test ${engine_TEST})365add_executable(${test} tests/main.cpp ${engine_TEST_HELPERS} tests/${test}.cpp)366target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})367add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")368add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.369endforeach()370foreach (test ${engine_TEST_INFILL})371add_executable(${test} tests/main.cpp tests/infill/${test}.cpp)372target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})373add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")374add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.375endforeach()376foreach (test ${engine_TEST_INTEGRATION})377add_executable(${test} tests/main.cpp tests/integration/${test}.cpp)378target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})379add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")380add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.381endforeach()382foreach (test ${engine_TEST_SETTINGS})383add_executable(${test} tests/main.cpp tests/settings/${test}.cpp)384target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})385add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")386add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.387endforeach()388if (ENABLE_ARCUS)389foreach (test ${engine_TEST_ARCUS})390add_executable(${test} tests/main.cpp ${engine_TEST_ARCUS_HELPERS} tests/arcus/${test}.cpp)391target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})392add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")393add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.394endforeach()395endif ()396foreach (test ${engine_TEST_UTILS})397add_executable(${test} tests/main.cpp tests/utils/${test}.cpp)398target_link_libraries(${test} _CuraEngine ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})399add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests/")400add_dependencies(build_all_tests ${test}) #Make sure that this gets built as part of the build_all_tests target.401endforeach()402endif()403404# Installing CuraEngine.405include(GNUInstallDirs)406install(TARGETS CuraEngine DESTINATION "${CMAKE_INSTALL_BINDIR}")407# For MinGW64 cross compiling on Debian, we create a ZIP package instead of a DEB408# Because it's the Windows build system that should install the files.409if (CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME MATCHES "Windows")410message(STATUS "Include MinGW64 posix DLLs for installation.")411install(FILES412/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/libgcc_s_seh-1.dll413/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/libgomp-1.dll414/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/libstdc++-6.dll415DESTINATION bin416COMPONENT runtime)417endif ()418include(CPackConfig.cmake)419420421