CMakeLists.txt 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. project(Slic3r-native)
  2. add_subdirectory(admesh)
  3. add_subdirectory(avrdude)
  4. # boost/nowide
  5. add_subdirectory(boost)
  6. add_subdirectory(clipper)
  7. add_subdirectory(miniz)
  8. add_subdirectory(glu-libtess)
  9. add_subdirectory(polypartition)
  10. add_subdirectory(poly2tri)
  11. add_subdirectory(qhull)
  12. add_subdirectory(Shiny)
  13. add_subdirectory(semver)
  14. add_subdirectory(imgui)
  15. # Adding libnest2d project for bin packing...
  16. set(LIBNEST2D_UNITTESTS ON CACHE BOOL "Force generating unittests for libnest2d")
  17. add_subdirectory(libnest2d)
  18. include_directories(${LIBDIR}/qhull/src)
  19. #message(STATUS ${LIBDIR}/qhull/src)
  20. # ##############################################################################
  21. # Configure rasterizer target
  22. # ##############################################################################
  23. find_package(PNG QUIET)
  24. option(RASTERIZER_FORCE_BUILTIN_LIBPNG "Force the usage of builting libpng instead of the system version." OFF)
  25. if(PNG_FOUND AND NOT RASTERIZER_FORCE_BUILTIN_LIBPNG)
  26. message(STATUS "Using system libpng.")
  27. else()
  28. set(ZLIB_LIBRARY "")
  29. message(WARNING "Using builtin libpng. This can cause crashes on some platforms.")
  30. set(SKIP_INSTALL_ALL 1) # Prevent png+zlib from creating install targets
  31. add_subdirectory(png/zlib)
  32. set(ZLIB_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/png/zlib ${CMAKE_CURRENT_BINARY_DIR}/png/zlib)
  33. include_directories(${ZLIB_INCLUDE_DIR})
  34. add_subdirectory(png/libpng)
  35. set_target_properties(zlibstatic PROPERTIES POSITION_INDEPENDENT_CODE ON)
  36. set_target_properties(png_static PROPERTIES POSITION_INDEPENDENT_CODE ON)
  37. set(PNG_LIBRARIES png_static zlibstatic)
  38. set(PNG_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/png/libpng ${CMAKE_CURRENT_BINARY_DIR}/png/libpng)
  39. endif()
  40. add_subdirectory(libslic3r)
  41. if (SLIC3R_GUI)
  42. if(WIN32)
  43. message(STATUS "WXWIN environment set to: $ENV{WXWIN}")
  44. elseif(UNIX)
  45. set(wxWidgets_USE_UNICODE ON)
  46. if(SLIC3R_STATIC)
  47. set(wxWidgets_USE_STATIC ON)
  48. else()
  49. set(wxWidgets_USE_STATIC OFF)
  50. endif()
  51. endif()
  52. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  53. if (SLIC3R_WX_STABLE)
  54. find_package(wxWidgets 3.0 REQUIRED COMPONENTS base core adv html gl)
  55. else ()
  56. find_package(wxWidgets 3.1 QUIET COMPONENTS base core adv html gl)
  57. if (NOT wxWidgets_FOUND)
  58. message(FATAL_ERROR "\nCould not find wxWidgets 3.1.\n"
  59. "Hint: On Linux you can set -DSLIC3R_WX_STABLE=1 to use wxWidgets 3.0\n")
  60. endif ()
  61. endif ()
  62. else ()
  63. find_package(wxWidgets 3.1 REQUIRED COMPONENTS base core adv html gl)
  64. endif ()
  65. if(UNIX)
  66. message(STATUS "wx-config path: ${wxWidgets_CONFIG_EXECUTABLE}")
  67. endif()
  68. include(${wxWidgets_USE_FILE})
  69. endif()
  70. add_subdirectory(slic3r)
  71. # Create a slic3r executable
  72. # Process mainfests for various platforms.
  73. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/platform/msw/slic3r.rc.in ${CMAKE_CURRENT_BINARY_DIR}/slic3r.rc @ONLY)
  74. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/platform/msw/slic3r.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/slic3r.manifest @ONLY)
  75. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/platform/osx/Info.plist.in ${CMAKE_CURRENT_BINARY_DIR}/Info.plist @ONLY)
  76. if (MSVC)
  77. add_library(slic3r SHARED slic3r.cpp slic3r.hpp)
  78. else ()
  79. add_executable(slic3r slic3r.cpp slic3r.hpp)
  80. endif ()
  81. if (NOT MSVC)
  82. if(SLIC3R_GUI)
  83. set_target_properties(slic3r PROPERTIES OUTPUT_NAME "slic3r-gui")
  84. else()
  85. set_target_properties(slic3r PROPERTIES OUTPUT_NAME "slic3r-console")
  86. endif()
  87. endif ()
  88. target_link_libraries(slic3r libslic3r)
  89. if (APPLE)
  90. # add_compile_options(-stdlib=libc++)
  91. # add_definitions(-DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE)
  92. # -liconv: boost links to libiconv by default
  93. target_link_libraries(slic3r "-liconv -framework IOKit" "-framework CoreFoundation" -lc++)
  94. elseif (MSVC)
  95. # Manifest is provided through slic3r.rc, don't generate your own.
  96. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
  97. else ()
  98. target_link_libraries(slic3r ${CMAKE_DL_LIBS} -lstdc++)
  99. endif ()
  100. # Add the Slic3r GUI library, libcurl, OpenGL and GLU libraries.
  101. if (SLIC3R_GUI)
  102. target_link_libraries(slic3r libslic3r_gui ${wxWidgets_LIBRARIES})
  103. # Configure libcurl & OpenSSL
  104. find_package(CURL REQUIRED)
  105. target_include_directories(slic3r PRIVATE ${CURL_INCLUDE_DIRS})
  106. target_link_libraries(slic3r CURL::libcurl)
  107. if (SLIC3R_STATIC)
  108. if (NOT APPLE)
  109. # libcurl is always linked dynamically to the system libcurl on OSX.
  110. # On other systems, libcurl is linked statically if SLIC3R_STATIC is set.
  111. target_compile_definitions(slic3r PRIVATE CURL_STATICLIB)
  112. endif()
  113. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  114. # As of now, our build system produces a statically linked libcurl,
  115. # which links the OpenSSL library dynamically.
  116. find_package(OpenSSL REQUIRED)
  117. message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
  118. message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
  119. target_include_directories(slic3r PRIVATE ${OPENSSL_INCLUDE_DIR})
  120. target_link_libraries(slic3r ${OPENSSL_LIBRARIES})
  121. endif()
  122. endif()
  123. if (MSVC)
  124. target_link_libraries(slic3r user32.lib Setupapi.lib OpenGL32.Lib GlU32.Lib)
  125. elseif (MINGW)
  126. target_link_libraries(slic3r -lopengl32)
  127. elseif (APPLE)
  128. target_link_libraries(slic3r "-framework OpenGL")
  129. else ()
  130. target_link_libraries(slic3r -ldl -lGL -lGLU)
  131. endif ()
  132. endif ()
  133. # On Windows, a shim application is required to produce a console / non console version of the Slic3r application.
  134. # Also the shim may load the Mesa software OpenGL renderer if the default renderer does not support OpenGL 2.0 and higher.
  135. if (MSVC)
  136. add_executable(slic3r_app_gui WIN32 slic3r_app_msvc.cpp ${CMAKE_CURRENT_BINARY_DIR}/slic3r.rc)
  137. target_compile_definitions(slic3r_app_gui PRIVATE -DSLIC3R_WRAPPER_NOCONSOLE)
  138. add_dependencies(slic3r_app_gui slic3r)
  139. set_target_properties(slic3r_app_gui PROPERTIES OUTPUT_NAME "slic3r")
  140. add_executable(slic3r_app_console slic3r_app_msvc.cpp ${CMAKE_CURRENT_BINARY_DIR}/slic3r.rc)
  141. target_compile_definitions(slic3r_app_console PRIVATE -DSLIC3R_WRAPPER_CONSOLE)
  142. add_dependencies(slic3r_app_console slic3r)
  143. set_target_properties(slic3r_app_console PROPERTIES OUTPUT_NAME "slic3r-console")
  144. endif ()
  145. # Link the resources dir to where Slic3r GUI expects it
  146. if (MSVC)
  147. if (CMAKE_CONFIGURATION_TYPES)
  148. foreach (CONF ${CMAKE_CONFIGURATION_TYPES})
  149. file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CONF}" WIN_CONF_OUTPUT_DIR)
  150. file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CONF}/resources" WIN_RESOURCES_SYMLINK)
  151. add_custom_command(TARGET slic3r POST_BUILD
  152. COMMAND if exist "${WIN_CONF_OUTPUT_DIR}" "("
  153. if not exist "${WIN_RESOURCES_SYMLINK}" "("
  154. mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}"
  155. ")"
  156. ")"
  157. COMMENT "Symlinking the resources directory into the build tree"
  158. VERBATIM
  159. )
  160. endforeach ()
  161. else ()
  162. file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/resources" WIN_RESOURCES_SYMLINK)
  163. add_custom_command(TARGET slic3r POST_BUILD
  164. COMMAND if not exist "${WIN_RESOURCES_SYMLINK}" "(" mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" ")"
  165. COMMENT "Symlinking the resources directory into the build tree"
  166. VERBATIM
  167. )
  168. endif ()
  169. elseif (XCODE)
  170. # Because of Debug/Release/etc. configurations (similar to MSVC) the slic3r binary is located in an extra level
  171. add_custom_command(TARGET slic3r POST_BUILD
  172. COMMAND ln -sf "${SLIC3R_RESOURCES_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/resources"
  173. COMMENT "Symlinking the resources directory into the build tree"
  174. VERBATIM
  175. )
  176. else ()
  177. add_custom_command(TARGET slic3r POST_BUILD
  178. COMMAND ln -sf "${SLIC3R_RESOURCES_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/../resources"
  179. COMMENT "Symlinking the resources directory into the build tree"
  180. VERBATIM
  181. )
  182. endif()
  183. # Slic3r binary install target
  184. if (WIN32)
  185. install(TARGETS slic3r RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}")
  186. if (MSVC)
  187. install(TARGETS slic3r_app_gui RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}")
  188. install(TARGETS slic3r_app_console RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}")
  189. endif ()
  190. else ()
  191. install(TARGETS slic3r RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
  192. endif ()