CMakeLists.txt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. cmake_minimum_required(VERSION 3.8)
  2. project(Slic3r-native)
  3. add_subdirectory(build-utils)
  4. add_subdirectory(admesh)
  5. add_subdirectory(avrdude)
  6. # boost/nowide
  7. add_subdirectory(boost)
  8. add_subdirectory(clipper)
  9. add_subdirectory(miniz)
  10. add_subdirectory(glu-libtess)
  11. add_subdirectory(polypartition)
  12. add_subdirectory(poly2tri)
  13. add_subdirectory(qhull)
  14. add_subdirectory(Shiny)
  15. add_subdirectory(semver)
  16. add_subdirectory(libigl)
  17. # Adding libnest2d project for bin packing...
  18. add_subdirectory(libnest2d)
  19. add_subdirectory(libslic3r)
  20. if (SLIC3R_GUI)
  21. add_subdirectory(imgui)
  22. add_subdirectory(hidapi)
  23. include_directories(hidapi/include)
  24. if(WIN32)
  25. message(STATUS "WXWIN environment set to: $ENV{WXWIN}")
  26. elseif(UNIX)
  27. set(wxWidgets_USE_UNICODE ON)
  28. if(SLIC3R_STATIC)
  29. set(wxWidgets_USE_STATIC ON)
  30. else()
  31. set(wxWidgets_USE_STATIC OFF)
  32. endif()
  33. endif()
  34. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  35. set (wxWidgets_CONFIG_OPTIONS "--toolkit=gtk${SLIC3R_GTK}")
  36. if (SLIC3R_WX_STABLE)
  37. find_package(wxWidgets 3.0 REQUIRED COMPONENTS base core adv html gl stc)
  38. else ()
  39. find_package(wxWidgets 3.1 QUIET COMPONENTS base core adv html gl stc)
  40. if (NOT wxWidgets_FOUND)
  41. message(FATAL_ERROR "\nCould not find wxWidgets 3.1.\n"
  42. "Hint: On Linux you can set -DSLIC3R_WX_STABLE=1 to use wxWidgets 3.0\n")
  43. endif ()
  44. endif ()
  45. else ()
  46. find_package(wxWidgets 3.1 REQUIRED COMPONENTS html adv gl core base stc scintilla)
  47. endif ()
  48. if(UNIX)
  49. message(STATUS "wx-config path: ${wxWidgets_CONFIG_EXECUTABLE}")
  50. endif()
  51. include(${wxWidgets_USE_FILE})
  52. # list(REMOVE_ITEM wxWidgets_LIBRARIES oleacc)
  53. message(STATUS "wx libs: ${wxWidgets_LIBRARIES}")
  54. add_subdirectory(slic3r)
  55. endif()
  56. # Create a slic3r executable
  57. # Process mainfests for various platforms.
  58. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/platform/msw/PrusaSlicer.rc.in ${CMAKE_CURRENT_BINARY_DIR}/slic3r.rc @ONLY)
  59. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/platform/msw/PrusaSlicer.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/slic3r.manifest @ONLY)
  60. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/platform/osx/Info.plist.in ${CMAKE_CURRENT_BINARY_DIR}/Info.plist @ONLY)
  61. if (WIN32)
  62. add_library(slic3r SHARED PrusaSlicer.cpp PrusaSlicer.hpp)
  63. else ()
  64. add_executable(slic3r PrusaSlicer.cpp PrusaSlicer.hpp)
  65. endif ()
  66. if (MINGW)
  67. target_link_options(slic3r PUBLIC "-Wl,-allow-multiple-definition")
  68. set_target_properties(slic3r PROPERTIES PREFIX "")
  69. endif (MINGW)
  70. if (NOT WIN32)
  71. # Binary name on unix like systems (OSX, Linux)
  72. set_target_properties(slic3r PROPERTIES OUTPUT_NAME "superslicer")
  73. endif ()
  74. target_link_libraries(slic3r libslic3r cereal)
  75. if (APPLE)
  76. # add_compile_options(-stdlib=libc++)
  77. # add_definitions(-DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE)
  78. # -liconv: boost links to libiconv by default
  79. target_link_libraries(slic3r "-liconv -framework IOKit" "-framework CoreFoundation" -lc++)
  80. elseif (MSVC)
  81. # Manifest is provided through slic3r.rc, don't generate your own.
  82. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
  83. else ()
  84. # Boost on Raspberry-Pi does not link to pthreads explicitely.
  85. target_link_libraries(slic3r ${CMAKE_DL_LIBS} -lstdc++ Threads::Threads)
  86. endif ()
  87. # Add the Slic3r GUI library, libcurl, OpenGL and GLU libraries.
  88. if (SLIC3R_GUI)
  89. # target_link_libraries(PrusaSlicer ws2_32 uxtheme setupapi libslic3r_gui ${wxWidgets_LIBRARIES})
  90. target_link_libraries(slic3r libslic3r_gui)
  91. if (MSVC)
  92. # Generate debug symbols even in release mode.
  93. target_link_options(slic3r PUBLIC "$<$<CONFIG:RELEASE>:/DEBUG>")
  94. target_link_libraries(slic3r user32.lib Setupapi.lib)
  95. elseif (MINGW)
  96. target_link_libraries(slic3r ws2_32 uxtheme setupapi)
  97. elseif (APPLE)
  98. target_link_libraries(slic3r "-framework OpenGL")
  99. else ()
  100. target_link_libraries(slic3r -ldl)
  101. endif ()
  102. endif ()
  103. # On Windows, a shim application is required to produce a console / non console version of the Slic3r application.
  104. # Also the shim may load the Mesa software OpenGL renderer if the default renderer does not support OpenGL 2.0 and higher.
  105. if (WIN32)
  106. if (MINGW)
  107. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode")
  108. endif()
  109. add_executable(slic3r_app_gui WIN32 PrusaSlicer_app_msvc.cpp ${CMAKE_CURRENT_BINARY_DIR}/slic3r.rc)
  110. # Generate debug symbols even in release mode.
  111. if(MSVC)
  112. target_link_options(slic3r_app_gui PUBLIC "$<$<CONFIG:RELEASE>:/DEBUG>")
  113. endif()
  114. target_compile_definitions(slic3r_app_gui PRIVATE -DSLIC3R_WRAPPER_NOCONSOLE)
  115. add_dependencies(slic3r_app_gui slic3r)
  116. set_target_properties(slic3r_app_gui PROPERTIES OUTPUT_NAME "superslicer")
  117. target_link_libraries(slic3r_app_gui PRIVATE boost_headeronly)
  118. add_executable(slic3r_app_console PrusaSlicer_app_msvc.cpp ${CMAKE_CURRENT_BINARY_DIR}/slic3r.rc)
  119. # Generate debug symbols even in release mode.
  120. if (MSVC)
  121. target_link_options(slic3r_app_console PUBLIC "$<$<CONFIG:RELEASE>:/DEBUG>")
  122. endif ()
  123. target_compile_definitions(slic3r_app_console PRIVATE -DSLIC3R_WRAPPER_CONSOLE)
  124. add_dependencies(slic3r_app_console slic3r)
  125. set_target_properties(slic3r_app_console PROPERTIES OUTPUT_NAME "superslicer_console")
  126. target_link_libraries(slic3r_app_console PRIVATE boost_headeronly)
  127. endif ()
  128. # Link the resources dir to where Slic3r GUI expects it
  129. if (WIN32)
  130. if (CMAKE_CONFIGURATION_TYPES)
  131. foreach (CONF ${CMAKE_CONFIGURATION_TYPES})
  132. file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CONF}" WIN_CONF_OUTPUT_DIR)
  133. file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CONF}/resources" WIN_RESOURCES_SYMLINK)
  134. add_custom_command(TARGET slic3r POST_BUILD
  135. COMMAND if exist "${WIN_CONF_OUTPUT_DIR}" "("
  136. if not exist "${WIN_RESOURCES_SYMLINK}" "("
  137. mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}"
  138. ")"
  139. ")"
  140. COMMENT "Symlinking the resources directory into the build tree"
  141. VERBATIM
  142. )
  143. endforeach ()
  144. else ()
  145. file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/resources" WIN_RESOURCES_SYMLINK)
  146. add_custom_command(TARGET slic3r POST_BUILD
  147. COMMAND if not exist "${WIN_RESOURCES_SYMLINK}" "(" mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" ")"
  148. COMMENT "Symlinking the resources directory into the build tree"
  149. VERBATIM
  150. )
  151. endif ()
  152. # This has to be a separate target due to the windows command line lenght limits
  153. add_custom_target(slic3rDllsCopy ALL DEPENDS slic3r)
  154. prusaslicer_copy_dlls(slic3rDllsCopy)
  155. elseif (XCODE)
  156. # Because of Debug/Release/etc. configurations (similar to MSVC) the slic3r binary is located in an extra level
  157. add_custom_command(TARGET slic3r POST_BUILD
  158. COMMAND ln -sf "${SLIC3R_RESOURCES_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/resources"
  159. COMMENT "Symlinking the resources directory into the build tree"
  160. VERBATIM
  161. )
  162. else ()
  163. add_custom_command(TARGET slic3r POST_BUILD
  164. COMMAND ln -sf "${SLIC3R_RESOURCES_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/../resources"
  165. COMMENT "Symlinking the resources directory into the build tree"
  166. VERBATIM
  167. )
  168. endif()
  169. # Slic3r binary install target
  170. if (WIN32)
  171. install(TARGETS slic3r RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}")
  172. if (MSVC)
  173. install(TARGETS slic3r_app_gui RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}")
  174. install(TARGETS slic3r_app_console RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}")
  175. endif ()
  176. else ()
  177. install(TARGETS slic3r RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
  178. endif ()