CMakeLists.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. # Enable C++11 language standard.
  2. set(CMAKE_CXX_STANDARD 11)
  3. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  4. # Add our own cmake module path.
  5. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/)
  6. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  7. # Workaround for an old CMake, which does not understand CMAKE_CXX_STANDARD.
  8. add_compile_options(-std=c++11 -Wall)
  9. endif()
  10. if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX)
  11. # Adding -fext-numeric-literals to enable GCC extensions on definitions of quad float literals, which are required by Boost.
  12. add_compile_options(-fext-numeric-literals)
  13. endif()
  14. # Where all the bundled libraries reside?
  15. set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/src/)
  16. # For the bundled boost libraries (boost::nowide)
  17. include_directories(${LIBDIR})
  18. # For libslic3r.h
  19. include_directories(${LIBDIR}/libslic3r)
  20. #set(CMAKE_INCLUDE_CURRENT_DIR ON)
  21. if(WIN32)
  22. # BOOST_ALL_NO_LIB: Avoid the automatic linking of Boost libraries on Windows. Rather rely on explicit linking.
  23. add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -DBOOST_ALL_NO_LIB)
  24. # -D_ITERATOR_DEBUG_LEVEL)
  25. endif()
  26. add_definitions(-DwxUSE_UNICODE -D_UNICODE -DUNICODE)
  27. add_library(libslic3r STATIC
  28. ${LIBDIR}/libslic3r/BoundingBox.cpp
  29. ${LIBDIR}/libslic3r/BoundingBox.hpp
  30. ${LIBDIR}/libslic3r/BridgeDetector.cpp
  31. ${LIBDIR}/libslic3r/BridgeDetector.hpp
  32. ${LIBDIR}/libslic3r/ClipperUtils.cpp
  33. ${LIBDIR}/libslic3r/ClipperUtils.hpp
  34. ${LIBDIR}/libslic3r/Config.cpp
  35. ${LIBDIR}/libslic3r/Config.hpp
  36. ${LIBDIR}/libslic3r/EdgeGrid.cpp
  37. ${LIBDIR}/libslic3r/EdgeGrid.hpp
  38. ${LIBDIR}/libslic3r/ExPolygon.cpp
  39. ${LIBDIR}/libslic3r/ExPolygon.hpp
  40. ${LIBDIR}/libslic3r/ExPolygonCollection.cpp
  41. ${LIBDIR}/libslic3r/ExPolygonCollection.hpp
  42. ${LIBDIR}/libslic3r/Extruder.cpp
  43. ${LIBDIR}/libslic3r/Extruder.hpp
  44. ${LIBDIR}/libslic3r/ExtrusionEntity.cpp
  45. ${LIBDIR}/libslic3r/ExtrusionEntity.hpp
  46. ${LIBDIR}/libslic3r/ExtrusionEntityCollection.cpp
  47. ${LIBDIR}/libslic3r/ExtrusionEntityCollection.hpp
  48. ${LIBDIR}/libslic3r/ExtrusionSimulator.cpp
  49. ${LIBDIR}/libslic3r/ExtrusionSimulator.hpp
  50. ${LIBDIR}/libslic3r/Fill/Fill.cpp
  51. ${LIBDIR}/libslic3r/Fill/Fill.hpp
  52. ${LIBDIR}/libslic3r/Fill/Fill3DHoneycomb.cpp
  53. ${LIBDIR}/libslic3r/Fill/Fill3DHoneycomb.hpp
  54. ${LIBDIR}/libslic3r/Fill/FillBase.cpp
  55. ${LIBDIR}/libslic3r/Fill/FillBase.hpp
  56. ${LIBDIR}/libslic3r/Fill/FillConcentric.cpp
  57. ${LIBDIR}/libslic3r/Fill/FillConcentric.hpp
  58. ${LIBDIR}/libslic3r/Fill/FillHoneycomb.cpp
  59. ${LIBDIR}/libslic3r/Fill/FillHoneycomb.hpp
  60. ${LIBDIR}/libslic3r/Fill/FillPlanePath.cpp
  61. ${LIBDIR}/libslic3r/Fill/FillPlanePath.hpp
  62. ${LIBDIR}/libslic3r/Fill/FillRectilinear.cpp
  63. ${LIBDIR}/libslic3r/Fill/FillRectilinear.hpp
  64. ${LIBDIR}/libslic3r/Fill/FillRectilinear2.cpp
  65. ${LIBDIR}/libslic3r/Fill/FillRectilinear2.hpp
  66. ${LIBDIR}/libslic3r/Fill/FillRectilinear3.cpp
  67. ${LIBDIR}/libslic3r/Fill/FillRectilinear3.hpp
  68. ${LIBDIR}/libslic3r/Flow.cpp
  69. ${LIBDIR}/libslic3r/Flow.hpp
  70. ${LIBDIR}/libslic3r/Format/AMF.cpp
  71. ${LIBDIR}/libslic3r/Format/AMF.hpp
  72. ${LIBDIR}/libslic3r/Format/OBJ.cpp
  73. ${LIBDIR}/libslic3r/Format/OBJ.hpp
  74. ${LIBDIR}/libslic3r/Format/objparser.cpp
  75. ${LIBDIR}/libslic3r/Format/objparser.hpp
  76. ${LIBDIR}/libslic3r/Format/PRUS.cpp
  77. ${LIBDIR}/libslic3r/Format/PRUS.hpp
  78. ${LIBDIR}/libslic3r/Format/STL.cpp
  79. ${LIBDIR}/libslic3r/Format/STL.hpp
  80. ${LIBDIR}/libslic3r/GCode/Analyzer.cpp
  81. ${LIBDIR}/libslic3r/GCode/Analyzer.hpp
  82. ${LIBDIR}/libslic3r/GCode/CoolingBuffer.cpp
  83. ${LIBDIR}/libslic3r/GCode/CoolingBuffer.hpp
  84. ${LIBDIR}/libslic3r/GCode/PressureEqualizer.cpp
  85. ${LIBDIR}/libslic3r/GCode/PressureEqualizer.hpp
  86. ${LIBDIR}/libslic3r/GCode/PrintExtents.cpp
  87. ${LIBDIR}/libslic3r/GCode/PrintExtents.hpp
  88. ${LIBDIR}/libslic3r/GCode/SpiralVase.cpp
  89. ${LIBDIR}/libslic3r/GCode/SpiralVase.hpp
  90. ${LIBDIR}/libslic3r/GCode/ToolOrdering.cpp
  91. ${LIBDIR}/libslic3r/GCode/ToolOrdering.hpp
  92. ${LIBDIR}/libslic3r/GCode/WipeTower.hpp
  93. ${LIBDIR}/libslic3r/GCode/WipeTowerPrusaMM.cpp
  94. ${LIBDIR}/libslic3r/GCode/WipeTowerPrusaMM.hpp
  95. ${LIBDIR}/libslic3r/GCode.cpp
  96. ${LIBDIR}/libslic3r/GCode.hpp
  97. ${LIBDIR}/libslic3r/GCodeReader.cpp
  98. ${LIBDIR}/libslic3r/GCodeReader.hpp
  99. ${LIBDIR}/libslic3r/GCodeSender.cpp
  100. ${LIBDIR}/libslic3r/GCodeSender.hpp
  101. ${LIBDIR}/libslic3r/GCodeTimeEstimator.cpp
  102. ${LIBDIR}/libslic3r/GCodeTimeEstimator.hpp
  103. ${LIBDIR}/libslic3r/GCodeWriter.cpp
  104. ${LIBDIR}/libslic3r/GCodeWriter.hpp
  105. ${LIBDIR}/libslic3r/Geometry.cpp
  106. ${LIBDIR}/libslic3r/Geometry.hpp
  107. ${LIBDIR}/libslic3r/Int128.hpp
  108. # ${LIBDIR}/libslic3r/KdTree.hpp
  109. ${LIBDIR}/libslic3r/Layer.cpp
  110. ${LIBDIR}/libslic3r/Layer.hpp
  111. ${LIBDIR}/libslic3r/LayerRegion.cpp
  112. ${LIBDIR}/libslic3r/libslic3r.h
  113. ${LIBDIR}/libslic3r/Line.cpp
  114. ${LIBDIR}/libslic3r/Line.hpp
  115. ${LIBDIR}/libslic3r/Model.cpp
  116. ${LIBDIR}/libslic3r/Model.hpp
  117. ${LIBDIR}/libslic3r/MotionPlanner.cpp
  118. ${LIBDIR}/libslic3r/MotionPlanner.hpp
  119. ${LIBDIR}/libslic3r/MultiPoint.cpp
  120. ${LIBDIR}/libslic3r/MultiPoint.hpp
  121. ${LIBDIR}/libslic3r/MutablePriorityQueue.hpp
  122. ${LIBDIR}/libslic3r/PerimeterGenerator.cpp
  123. ${LIBDIR}/libslic3r/PerimeterGenerator.hpp
  124. ${LIBDIR}/libslic3r/PlaceholderParser.cpp
  125. ${LIBDIR}/libslic3r/PlaceholderParser.hpp
  126. ${LIBDIR}/libslic3r/Point.cpp
  127. ${LIBDIR}/libslic3r/Point.hpp
  128. ${LIBDIR}/libslic3r/Polygon.cpp
  129. ${LIBDIR}/libslic3r/Polygon.hpp
  130. ${LIBDIR}/libslic3r/Polyline.cpp
  131. ${LIBDIR}/libslic3r/Polyline.hpp
  132. ${LIBDIR}/libslic3r/PolylineCollection.cpp
  133. ${LIBDIR}/libslic3r/PolylineCollection.hpp
  134. ${LIBDIR}/libslic3r/Print.cpp
  135. ${LIBDIR}/libslic3r/Print.hpp
  136. ${LIBDIR}/libslic3r/PrintConfig.cpp
  137. ${LIBDIR}/libslic3r/PrintConfig.hpp
  138. ${LIBDIR}/libslic3r/PrintObject.cpp
  139. ${LIBDIR}/libslic3r/PrintRegion.cpp
  140. ${LIBDIR}/libslic3r/Slicing.cpp
  141. ${LIBDIR}/libslic3r/Slicing.hpp
  142. ${LIBDIR}/libslic3r/SlicingAdaptive.cpp
  143. ${LIBDIR}/libslic3r/SlicingAdaptive.hpp
  144. ${LIBDIR}/libslic3r/SupportMaterial.cpp
  145. ${LIBDIR}/libslic3r/SupportMaterial.hpp
  146. ${LIBDIR}/libslic3r/Surface.cpp
  147. ${LIBDIR}/libslic3r/Surface.hpp
  148. ${LIBDIR}/libslic3r/SurfaceCollection.cpp
  149. ${LIBDIR}/libslic3r/SurfaceCollection.hpp
  150. ${LIBDIR}/libslic3r/SVG.cpp
  151. ${LIBDIR}/libslic3r/SVG.hpp
  152. ${LIBDIR}/libslic3r/TriangleMesh.cpp
  153. ${LIBDIR}/libslic3r/TriangleMesh.hpp
  154. # ${LIBDIR}/libslic3r/utils.cpp
  155. ${LIBDIR}/libslic3r/Utils.hpp
  156. )
  157. add_library(libslic3r_gui STATIC
  158. ${LIBDIR}/slic3r/GUI/AppConfig.cpp
  159. ${LIBDIR}/slic3r/GUI/AppConfig.hpp
  160. ${LIBDIR}/slic3r/GUI/3DScene.cpp
  161. ${LIBDIR}/slic3r/GUI/3DScene.hpp
  162. ${LIBDIR}/slic3r/GUI/GLShader.cpp
  163. ${LIBDIR}/slic3r/GUI/GLShader.hpp
  164. ${LIBDIR}/slic3r/GUI/Preset.cpp
  165. ${LIBDIR}/slic3r/GUI/Preset.hpp
  166. ${LIBDIR}/slic3r/GUI/PresetBundle.cpp
  167. ${LIBDIR}/slic3r/GUI/PresetBundle.hpp
  168. ${LIBDIR}/slic3r/GUI/PresetHints.cpp
  169. ${LIBDIR}/slic3r/GUI/PresetHints.hpp
  170. ${LIBDIR}/slic3r/GUI/GUI.cpp
  171. ${LIBDIR}/slic3r/GUI/GUI.hpp
  172. )
  173. add_library(admesh STATIC
  174. ${LIBDIR}/admesh/connect.cpp
  175. ${LIBDIR}/admesh/normals.cpp
  176. ${LIBDIR}/admesh/shared.cpp
  177. ${LIBDIR}/admesh/stl.h
  178. ${LIBDIR}/admesh/stl_io.cpp
  179. ${LIBDIR}/admesh/stlinit.cpp
  180. ${LIBDIR}/admesh/util.cpp
  181. )
  182. add_library(clipper STATIC
  183. ${LIBDIR}/clipper.cpp
  184. ${LIBDIR}/clipper.hpp
  185. )
  186. add_library(polypartition STATIC
  187. ${LIBDIR}/polypartition.cpp
  188. ${LIBDIR}/polypartition.h
  189. )
  190. add_library(poly2tri STATIC
  191. ${LIBDIR}/poly2tri/common/shapes.cc
  192. ${LIBDIR}/poly2tri/common/shapes.h
  193. ${LIBDIR}/poly2tri/common/utils.h
  194. ${LIBDIR}/poly2tri/poly2tri.h
  195. ${LIBDIR}/poly2tri/sweep/advancing_front.cc
  196. ${LIBDIR}/poly2tri/sweep/advancing_front.h
  197. ${LIBDIR}/poly2tri/sweep/cdt.cc
  198. ${LIBDIR}/poly2tri/sweep/cdt.h
  199. ${LIBDIR}/poly2tri/sweep/sweep.cc
  200. ${LIBDIR}/poly2tri/sweep/sweep.h
  201. ${LIBDIR}/poly2tri/sweep/sweep_context.cc
  202. ${LIBDIR}/poly2tri/sweep/sweep_context.h
  203. )
  204. add_library(nowide STATIC
  205. ${LIBDIR}/boost/nowide/args.hpp
  206. ${LIBDIR}/boost/nowide/cenv.hpp
  207. ${LIBDIR}/boost/nowide/config.hpp
  208. ${LIBDIR}/boost/nowide/convert.hpp
  209. ${LIBDIR}/boost/nowide/cstdio.hpp
  210. ${LIBDIR}/boost/nowide/cstdlib.hpp
  211. ${LIBDIR}/boost/nowide/filebuf.hpp
  212. ${LIBDIR}/boost/nowide/fstream.hpp
  213. ${LIBDIR}/boost/nowide/integration/filesystem.hpp
  214. ${LIBDIR}/boost/nowide/iostream.cpp
  215. ${LIBDIR}/boost/nowide/iostream.hpp
  216. ${LIBDIR}/boost/nowide/stackstring.hpp
  217. ${LIBDIR}/boost/nowide/system.hpp
  218. ${LIBDIR}/boost/nowide/utf8_codecvt.hpp
  219. ${LIBDIR}/boost/nowide/windows.hpp
  220. )
  221. add_library(Shiny STATIC
  222. ${LIBDIR}/Shiny/Shiny.h
  223. ${LIBDIR}/Shiny/ShinyConfig.h
  224. ${LIBDIR}/Shiny/ShinyData.h
  225. ${LIBDIR}/Shiny/ShinyMacros.h
  226. ${LIBDIR}/Shiny/ShinyManager.c
  227. ${LIBDIR}/Shiny/ShinyManager.h
  228. ${LIBDIR}/Shiny/ShinyNode.c
  229. ${LIBDIR}/Shiny/ShinyNode.h
  230. ${LIBDIR}/Shiny/ShinyNodePool.c
  231. ${LIBDIR}/Shiny/ShinyNodePool.h
  232. ${LIBDIR}/Shiny/ShinyNodeState.c
  233. ${LIBDIR}/Shiny/ShinyNodeState.h
  234. ${LIBDIR}/Shiny/ShinyOutput.c
  235. ${LIBDIR}/Shiny/ShinyOutput.h
  236. ${LIBDIR}/Shiny/ShinyPrereqs.h
  237. ${LIBDIR}/Shiny/ShinyTools.c
  238. ${LIBDIR}/Shiny/ShinyTools.h
  239. ${LIBDIR}/Shiny/ShinyVersion.h
  240. ${LIBDIR}/Shiny/ShinyZone.c
  241. ${LIBDIR}/Shiny/ShinyZone.h
  242. )
  243. # Generate the Slic3r Perl module (XS) typemap file.
  244. set(MyTypemap ${CMAKE_CURRENT_BINARY_DIR}/typemap)
  245. add_custom_command(
  246. OUTPUT ${MyTypemap}
  247. DEPENDS ${CMAKE_CURRENT_LIST_DIR}/xsp/my.map
  248. COMMAND ${PERL_EXECUTABLE} -MExtUtils::Typemaps -MExtUtils::Typemaps::Basic -e "$typemap = ExtUtils::Typemaps->new(file => \"${CMAKE_CURRENT_LIST_DIR}/xsp/my.map\"); $typemap->merge(typemap => ExtUtils::Typemaps::Basic->new); $typemap->write(file => \"${MyTypemap}\")"
  249. VERBATIM
  250. )
  251. # Generate the Slic3r Perl module (XS) main.xs file.
  252. set(XS_MAIN_XS ${CMAKE_CURRENT_BINARY_DIR}/main.xs)
  253. set(XSP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xsp)
  254. #FIXME list the dependecies explicitely, add dependency on the typemap.
  255. set(XS_XSP_FILES
  256. ${XSP_DIR}/BoundingBox.xsp
  257. ${XSP_DIR}/BridgeDetector.xsp
  258. ${XSP_DIR}/Clipper.xsp
  259. ${XSP_DIR}/Config.xsp
  260. ${XSP_DIR}/ExPolygon.xsp
  261. ${XSP_DIR}/ExPolygonCollection.xsp
  262. ${XSP_DIR}/ExtrusionEntityCollection.xsp
  263. ${XSP_DIR}/ExtrusionLoop.xsp
  264. ${XSP_DIR}/ExtrusionMultiPath.xsp
  265. ${XSP_DIR}/ExtrusionPath.xsp
  266. ${XSP_DIR}/ExtrusionSimulator.xsp
  267. ${XSP_DIR}/Filler.xsp
  268. ${XSP_DIR}/Flow.xsp
  269. ${XSP_DIR}/GCode.xsp
  270. ${XSP_DIR}/GCodeSender.xsp
  271. ${XSP_DIR}/Geometry.xsp
  272. ${XSP_DIR}/GUI.xsp
  273. ${XSP_DIR}/GUI_AppConfig.xsp
  274. ${XSP_DIR}/GUI_3DScene.xsp
  275. ${XSP_DIR}/GUI_Preset.xsp
  276. ${XSP_DIR}/Layer.xsp
  277. ${XSP_DIR}/Line.xsp
  278. ${XSP_DIR}/Model.xsp
  279. ${XSP_DIR}/MotionPlanner.xsp
  280. ${XSP_DIR}/PerimeterGenerator.xsp
  281. ${XSP_DIR}/PlaceholderParser.xsp
  282. ${XSP_DIR}/Point.xsp
  283. ${XSP_DIR}/Polygon.xsp
  284. ${XSP_DIR}/Polyline.xsp
  285. ${XSP_DIR}/PolylineCollection.xsp
  286. ${XSP_DIR}/Print.xsp
  287. ${XSP_DIR}/Surface.xsp
  288. ${XSP_DIR}/SurfaceCollection.xsp
  289. ${XSP_DIR}/TriangleMesh.xsp
  290. ${XSP_DIR}/XS.xsp
  291. )
  292. foreach (file ${XS_XSP_FILES})
  293. if (MSVC)
  294. # Visual Studio C compiler has issues with FILE pragmas containing quotes.
  295. set(INCLUDE_COMMANDS "${INCLUDE_COMMANDS}INCLUDE_COMMAND: $^X -MExtUtils::XSpp::Cmd -e xspp -- -t ${CMAKE_CURRENT_LIST_DIR}/xsp/typemap.xspt ${file}\n")
  296. else ()
  297. set(INCLUDE_COMMANDS "${INCLUDE_COMMANDS}INCLUDE_COMMAND: $^X -MExtUtils::XSpp::Cmd -e xspp -- -t \"${CMAKE_CURRENT_LIST_DIR}/xsp/typemap.xspt\" \"${file}\"\n")
  298. endif ()
  299. endforeach ()
  300. configure_file(main.xs.in ${XS_MAIN_XS} @ONLY) # Insert INCLUDE_COMMANDS into main.xs
  301. # Generate the Slic3r Perl module (XS) XS.cpp file.
  302. #FIXME add the dependency on main.xs and typemap.
  303. set(XS_MAIN_CPP ${CMAKE_CURRENT_BINARY_DIR}/XS.cpp)
  304. add_custom_command(
  305. OUTPUT ${XS_MAIN_CPP}
  306. DEPENDS ${MyTypemap} ${XS_XSP_FILES} ${CMAKE_CURRENT_LIST_DIR}/xsp/typemap.xspt
  307. COMMAND COMMAND xsubpp -typemap typemap -output ${XS_MAIN_CPP} -hiertype ${XS_MAIN_XS}
  308. )
  309. # Define the Perl XS shared library.
  310. if(APPLE)
  311. set(XS_SHARED_LIBRARY_TYPE MODULE)
  312. else()
  313. set(XS_SHARED_LIBRARY_TYPE SHARED)
  314. endif()
  315. add_library(XS ${XS_SHARED_LIBRARY_TYPE}
  316. ${XS_MAIN_CPP}
  317. ${LIBDIR}/libslic3r/utils.cpp
  318. ${LIBDIR}/slic3r/GUI/wxPerlIface.cpp
  319. ${LIBDIR}/perlglue.cpp
  320. ${LIBDIR}/ppport.h
  321. ${LIBDIR}/xsinit.h
  322. ${CMAKE_CURRENT_LIST_DIR}/xsp/my.map
  323. # mytype.map is empty. Is it required by Build.PL or the Perl xspp module?
  324. ${CMAKE_CURRENT_LIST_DIR}/xsp/mytype.map
  325. # Used by Perl xsubpp to generate XS.cpp
  326. ${CMAKE_CURRENT_LIST_DIR}/xsp/typemap.xspt
  327. )
  328. if(APPLE)
  329. set_target_properties(XS PROPERTIES BUNDLE TRUE)
  330. # Ignore undefined symbols of the perl interpreter, they will be found in the caller image.
  331. target_link_libraries(XS "-undefined dynamic_lookup")
  332. endif()
  333. target_link_libraries(XS libslic3r libslic3r_gui admesh clipper nowide polypartition poly2tri)
  334. if(SLIC3R_PROFILE)
  335. target_link_libraries(XS Shiny)
  336. endif()
  337. # Add the OpenGL and GLU libraries.
  338. if (SLIC3R_GUI)
  339. if (MSVC)
  340. target_link_libraries(XS OpenGL32.Lib GlU32.Lib)
  341. elseif (MINGW)
  342. target_link_libraries(XS -lopengl32)
  343. elseif (APPLE)
  344. target_link_libraries(XS "-framework OpenGL")
  345. else ()
  346. target_link_libraries(XS -lGL -lGLU)
  347. endif ()
  348. endif ()
  349. target_include_directories(XS PRIVATE src src/libslic3r) # Local include directories
  350. target_compile_definitions(XS PRIVATE -DSLIC3RXS)
  351. set_target_properties(XS PROPERTIES PREFIX "") # Prevent cmake from generating libXS.so instead of XS.so
  352. if (APPLE)
  353. # add_compile_options(-stdlib=libc++)
  354. # add_definitions(-DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE)
  355. target_link_libraries(XS "-framework IOKit" "-framework CoreFoundation" -lc++)
  356. elseif (MSVC)
  357. target_link_libraries(XS )
  358. else ()
  359. target_link_libraries(XS -lstdc++)
  360. endif ()
  361. # Windows specific stuff
  362. if (WIN32)
  363. target_compile_definitions(XS PRIVATE -DNOGDI -DNOMINMAX -DHAS_BOOL)
  364. endif ()
  365. ## Configuration flags
  366. if (SLIC3R_GUI)
  367. message("Slic3r will be built with GUI support")
  368. target_compile_definitions(XS PRIVATE -DSLIC3R_GUI)
  369. endif ()
  370. if (SLIC3R_PROFILE)
  371. message("Slic3r will be built with a Shiny invasive profiler")
  372. add_definitions(-DSLIC3R_PROFILE)
  373. endif ()
  374. if (SLIC3R_HAS_BROKEN_CROAK)
  375. target_compile_definitions(XS PRIVATE -DSLIC3R_HAS_BROKEN_CROAK)
  376. endif ()
  377. if (CMAKE_BUILD_TYPE MATCHES DEBUG)
  378. target_compile_definitions(XS PRIVATE -DSLIC3R_DEBUG -DDEBUG -D_DEBUG)
  379. else ()
  380. target_compile_definitions(XS PRIVATE -DNDEBUG)
  381. endif ()
  382. # Perl specific stuff
  383. find_package(PerlLibs REQUIRED)
  384. set(PerlEmbed_DEBUG 1)
  385. find_package(PerlEmbed REQUIRED)
  386. target_include_directories(XS PRIVATE ${PERL_INCLUDE_PATH})
  387. target_compile_options(XS PRIVATE ${PerlEmbed_CCFLAGS})
  388. # If the Perl is compiled with optimization off, disable optimization over the whole project.
  389. if (WIN32 AND ";${PerlEmbed_CCFLAGS};" MATCHES ";[-/]Od;")
  390. message(STATUS "Perl compiled without optimization. Disabling optimization for the Slic3r build.")
  391. message("Old CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
  392. message("Old CMAKE_CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELEASE}")
  393. message("Old CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS_RELEASE}")
  394. set(CMAKE_CXX_FLAGS_RELEASE "/MD /Od /Zi /EHsc /DNDEBUG")
  395. set(CMAKE_C_FLAGS_RELEASE "/MD /Od /Zi /DNDEBUG")
  396. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /Od /Zi /EHsc /DNDEBUG")
  397. set(CMAKE_C_FLAGS_RELWITHDEBINFO "/MD /Od /Zi /DNDEBUG")
  398. set(CMAKE_CXX_FLAGS "/MD /Od /Zi /EHsc /DNDEBUG")
  399. set(CMAKE_C_FLAGS "/MD /Od /Zi /DNDEBUG")
  400. endif()
  401. # The following line will add -fPIC on Linux to make the XS.so rellocable.
  402. add_definitions(${PerlEmbed_CCCDLFLAGS})
  403. if (WIN32)
  404. target_link_libraries(XS ${PERL_LIBRARY})
  405. endif()
  406. ## REQUIRED packages
  407. # Find and configure boost
  408. if(SLIC3R_STATIC)
  409. # Use static boost libraries.
  410. set(Boost_USE_STATIC_LIBS ON)
  411. # Use boost libraries linked statically to the C++ runtime.
  412. # set(Boost_USE_STATIC_RUNTIME ON)
  413. endif()
  414. find_package(Boost REQUIRED COMPONENTS system filesystem thread log locale regex)
  415. if(Boost_FOUND)
  416. include_directories(${Boost_INCLUDE_DIRS})
  417. target_link_libraries(XS ${Boost_LIBRARIES})
  418. if (APPLE)
  419. # BOOST_ASIO_DISABLE_KQUEUE : prevents a Boost ASIO bug on OS X: https://svn.boost.org/trac/boost/ticket/5339
  420. add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
  421. endif()
  422. if(NOT SLIC3R_STATIC)
  423. add_definitions(-DBOOST_LOG_DYN_LINK)
  424. endif()
  425. endif()
  426. # Find and configure intel-tbb
  427. if(SLIC3R_STATIC)
  428. set(TBB_STATIC 1)
  429. endif()
  430. set(TBB_DEBUG 1)
  431. find_package(TBB REQUIRED)
  432. include_directories(${TBB_INCLUDE_DIRS})
  433. add_definitions(${TBB_DEFINITIONS})
  434. if(MSVC)
  435. # Suppress implicit linking of the TBB libraries by the Visual Studio compiler.
  436. add_definitions(-D__TBB_NO_IMPLICIT_LINKAGE)
  437. endif()
  438. # The Intel TBB library will use the std::exception_ptr feature of C++11.
  439. add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0)
  440. target_link_libraries(XS ${TBB_LIBRARIES})
  441. # Find and configure wxWidgets
  442. if (SLIC3R_PRUSACONTROL)
  443. set(wxWidgets_UseAlienWx 1)
  444. if (wxWidgets_UseAlienWx)
  445. set(AlienWx_DEBUG 1)
  446. find_package(AlienWx REQUIRED COMPONENTS base core adv)
  447. include_directories(${AlienWx_INCLUDE_DIRS})
  448. #add_compile_options(${AlienWx_CXX_FLAGS})
  449. add_definitions(${AlienWx_DEFINITIONS})
  450. set(wxWidgets_LIBRARIES ${AlienWx_LIBRARIES})
  451. else ()
  452. find_package(wxWidgets REQUIRED COMPONENTS base core adv)
  453. include(${wxWidgets_USE_FILE})
  454. endif ()
  455. add_definitions(-DSLIC3R_GUI -DSLIC3R_PRUS)
  456. target_link_libraries(XS ${wxWidgets_LIBRARIES})
  457. endif()
  458. ## OPTIONAL packages
  459. # Find eigen3 or use bundled version
  460. if (NOT SLIC3R_STATIC)
  461. find_package(Eigen3)
  462. endif ()
  463. if (NOT Eigen3_FOUND)
  464. set(Eigen3_FOUND 1)
  465. set(EIGEN3_INCLUDE_DIR ${LIBDIR}/eigen/)
  466. endif ()
  467. include_directories(${EIGEN3_INCLUDE_DIR})
  468. # Find expat or use bundled version
  469. # Always use the system libexpat on Linux.
  470. if (NOT SLIC3R_STATIC OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
  471. find_package(EXPAT)
  472. endif ()
  473. if (NOT EXPAT_FOUND)
  474. add_library(expat STATIC
  475. ${LIBDIR}/expat/xmlparse.c
  476. ${LIBDIR}/expat/xmlrole.c
  477. ${LIBDIR}/expat/xmltok.c
  478. )
  479. set(EXPAT_FOUND 1)
  480. set(EXPAT_INCLUDE_DIRS ${LIBDIR}/expat/)
  481. set(EXPAT_LIBRARIES expat)
  482. endif ()
  483. include_directories(${EXPAT_INCLUDE_DIRS})
  484. target_link_libraries(XS ${EXPAT_LIBRARIES})
  485. # Find glew or use bundled version
  486. if (NOT SLIC3R_STATIC)
  487. find_package(GLEW)
  488. endif ()
  489. if (NOT GLEW_FOUND)
  490. add_library(glew STATIC ${LIBDIR}/glew/src/glew.c)
  491. set(GLEW_FOUND 1)
  492. set(GLEW_INCLUDE_DIRS ${LIBDIR}/glew/include/)
  493. set(GLEW_LIBRARIES glew)
  494. add_definitions(-DGLEW_STATIC)
  495. endif ()
  496. include_directories(${GLEW_INCLUDE_DIRS})
  497. target_link_libraries(XS ${GLEW_LIBRARIES})
  498. # Install the XS.pm and XS.{so,dll,bundle} into the local-lib directory.
  499. set(PERL_LOCAL_LIB_DIR "${PROJECT_SOURCE_DIR}/local-lib/lib/perl5/${PerlEmbed_ARCHNAME}")
  500. add_custom_command(
  501. TARGET XS
  502. POST_BUILD
  503. COMMAND ${CMAKE_COMMAND} -E make_directory "${PERL_LOCAL_LIB_DIR}/auto/Slic3r/XS/"
  504. COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:XS>" "${PERL_LOCAL_LIB_DIR}/auto/Slic3r/XS/"
  505. COMMAND ${CMAKE_COMMAND} -E make_directory "${PERL_LOCAL_LIB_DIR}/Slic3r/"
  506. COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/xs/lib/Slic3r/XS.pm" "${PERL_LOCAL_LIB_DIR}/Slic3r/"
  507. )
  508. if(APPLE)
  509. add_custom_command(
  510. TARGET XS
  511. POST_BUILD
  512. COMMAND ${CMAKE_COMMAND} -E rename "${PERL_LOCAL_LIB_DIR}/auto/Slic3r/XS/XS" "${PERL_LOCAL_LIB_DIR}/auto/Slic3r/XS/XS.bundle"
  513. )
  514. endif()
  515. # Create a slic3r executable
  516. add_executable(slic3r ${PROJECT_SOURCE_DIR}/src/slic3r.cpp)
  517. target_include_directories(XS PRIVATE src src/libslic3r)
  518. target_link_libraries(slic3r libslic3r libslic3r_gui admesh ${Boost_LIBRARIES} clipper ${EXPAT_LIBRARIES} ${GLEW_LIBRARIES} polypartition poly2tri ${TBB_LIBRARIES} ${wxWidgets_LIBRARIES})
  519. if(SLIC3R_PROFILE)
  520. target_link_libraries(Shiny)
  521. endif()
  522. if (APPLE)
  523. target_link_libraries(slic3r "-framework IOKit" "-framework CoreFoundation" -lc++)
  524. elseif (NOT MSVC)
  525. target_link_libraries(slic3r -lstdc++)
  526. endif ()
  527. # Installation
  528. install(TARGETS XS DESTINATION lib/slic3r-prusa3d/auto/Slic3r/XS)
  529. install(FILES lib/Slic3r/XS.pm DESTINATION lib/slic3r-prusa3d/Slic3r)