CMakeLists.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #
  2. # This CMake project downloads, configures and builds Slic3r++ dependencies on Unix and Windows.
  3. #
  4. # When using this script, it's recommended to perform an out-of-source build using CMake.
  5. #
  6. # All the dependencies are installed in a `destdir` directory in the root of the build directory,
  7. # in a traditional Unix-style prefix structure. The destdir can be used directly by CMake
  8. # when building Slic3r - to do this, set the CMAKE_PREFIX_PATH to ${destdir}/usr/local.
  9. # Warning: On UNIX/Linux, you also need to set -DSlic3r_STATIC=1 when building Slic3r.
  10. #
  11. # For better clarity of console output, it's recommended to _not_ use a parallelized build
  12. # for the top-level command, ie. use `make -j 1` or `ninja -j 1` to force single-threaded top-level
  13. # build. This doesn't degrade performance as individual dependencies are built in parallel fashion
  14. # if supported by the dependency.
  15. #
  16. # On Windows, architecture (64 vs 32 bits) is judged based on the compiler variant.
  17. # To build dependencies for either 64 or 32 bit OS, use the respective compiler command line.
  18. #
  19. # WARNING: On UNIX platforms wxWidgets hardcode the destdir path into its `wx-conffig` utility,
  20. # therefore, unfortunatelly, the installation cannot be copied/moved elsewhere without re-installing wxWidgets.
  21. #
  22. project(Slic3r-deps)
  23. cmake_minimum_required(VERSION 3.2)
  24. include(ExternalProject)
  25. include(ProcessorCount)
  26. ProcessorCount(NPROC)
  27. if (NPROC EQUAL 0)
  28. set(NPROC 1)
  29. endif ()
  30. set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir" CACHE PATH "Destination directory")
  31. option(DEP_DEBUG "Build debug variants (only applicable on Windows)" ON)
  32. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  33. option(DEP_WX_GTK3 "Build wxWidgets against GTK3" OFF)
  34. endif()
  35. # On developer machines, it can be enabled to speed up compilation and suppress warnings coming from IGL.
  36. # FIXME:
  37. # Enabling this option is not safe. IGL will compile itself with its own version of Eigen while
  38. # Slic3r compiles with a different version which will cause runtime errors.
  39. # option(DEP_BUILD_IGL_STATIC "Build IGL as a static library. Might cause link errors and increase binary size." OFF)
  40. message(STATUS "Slic3r deps DESTDIR: ${DESTDIR}")
  41. message(STATUS "Slic3r deps debug build: ${DEP_DEBUG}")
  42. find_package(Git REQUIRED)
  43. get_property(_is_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  44. function(prusaslicer_add_cmake_project projectname)
  45. cmake_parse_arguments(P_ARGS "" "INSTALL_DIR;BUILD_COMMAND;INSTALL_COMMAND" "CMAKE_ARGS" ${ARGN})
  46. set(_configs_line -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE})
  47. if (_is_multi OR MSVC)
  48. set(_configs_line "")
  49. endif ()
  50. set(_gen "")
  51. set(_build_j "-j${NPROC}")
  52. if (MSVC)
  53. set(_gen CMAKE_GENERATOR "${DEP_MSVC_GEN}" CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}")
  54. set(_build_j "/m")
  55. endif ()
  56. ExternalProject_Add(
  57. dep_${projectname}
  58. EXCLUDE_FROM_ALL ON
  59. INSTALL_DIR ${DESTDIR}/usr/local
  60. ${_gen}
  61. CMAKE_ARGS
  62. -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR}/usr/local
  63. -DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/../cmake/modules
  64. -DCMAKE_PREFIX_PATH:STRING=${DESTDIR}/usr/local
  65. -DCMAKE_DEBUG_POSTFIX:STRING=d
  66. -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
  67. -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
  68. -DBUILD_SHARED_LIBS:BOOL=OFF
  69. "${_configs_line}"
  70. ${DEP_CMAKE_OPTS}
  71. ${P_ARGS_CMAKE_ARGS}
  72. ${P_ARGS_UNPARSED_ARGUMENTS}
  73. BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release -- ${_build_j}
  74. INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config Release
  75. )
  76. endfunction(prusaslicer_add_cmake_project)
  77. if (MSVC)
  78. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  79. message(STATUS "\nDetected 64-bit compiler => building 64-bit deps bundle\n")
  80. set(DEPS_BITS 64)
  81. include("deps-windows.cmake")
  82. elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  83. message(STATUS "\nDetected 32-bit compiler => building 32-bit deps bundle\n")
  84. set(DEPS_BITS 32)
  85. include("deps-windows.cmake")
  86. else ()
  87. message(FATAL_ERROR "Unable to detect architecture")
  88. endif ()
  89. elseif (APPLE)
  90. message("OS X SDK Path: ${CMAKE_OSX_SYSROOT}")
  91. if (CMAKE_OSX_DEPLOYMENT_TARGET)
  92. set(DEP_OSX_TARGET "${CMAKE_OSX_DEPLOYMENT_TARGET}")
  93. message("OS X Deployment Target: ${DEP_OSX_TARGET}")
  94. else ()
  95. # Attempt to infer the SDK version from the CMAKE_OSX_SYSROOT,
  96. # this is done because wxWidgets need the min version explicitly set
  97. string(REGEX MATCH "[0-9]+[.][0-9]+[.]sdk$" DEP_OSX_TARGET "${CMAKE_OSX_SYSROOT}")
  98. string(REGEX MATCH "^[0-9]+[.][0-9]+" DEP_OSX_TARGET "${DEP_OSX_TARGET}")
  99. if (NOT DEP_OSX_TARGET)
  100. message(FATAL_ERROR "Could not determine OS X SDK version. Please use -DCMAKE_OSX_DEPLOYMENT_TARGET=<version>")
  101. endif ()
  102. message("OS X Deployment Target (inferred from SDK): ${DEP_OSX_TARGET}")
  103. endif ()
  104. include("deps-macos.cmake")
  105. elseif (MINGW)
  106. message(STATUS "Building for MinGW...")
  107. include("deps-mingw.cmake")
  108. else()
  109. include("deps-linux.cmake")
  110. endif()
  111. set(ZLIB_PKG "")
  112. if (NOT ZLIB_FOUND)
  113. include(ZLIB/ZLIB.cmake)
  114. set(ZLIB_PKG dep_ZLIB)
  115. endif ()
  116. set(PNG_PKG "")
  117. if (NOT PNG_FOUND)
  118. include(PNG/PNG.cmake)
  119. set(PNG_PKG dep_PNG)
  120. endif ()
  121. set(EXPAT_PKG "")
  122. if (NOT EXPAT_FOUND)
  123. include(EXPAT/EXPAT.cmake)
  124. set(EXPAT_PKG dep_EXPAT)
  125. endif ()
  126. include(GLEW/GLEW.cmake)
  127. include(OpenCSG/OpenCSG.cmake)
  128. include(GMP/GMP.cmake)
  129. include(MPFR/MPFR.cmake)
  130. include(CGAL/CGAL.cmake)
  131. include(wxWidgets/wxWidgets.cmake)
  132. if (NOT "${ZLIB_PKG}" STREQUAL "")
  133. add_dependencies(dep_blosc ${ZLIB_PKG})
  134. add_dependencies(dep_openexr ${ZLIB_PKG})
  135. endif ()
  136. set(_dep_list
  137. dep_boost
  138. dep_tbb
  139. dep_libcurl
  140. dep_wxWidgets
  141. dep_gtest
  142. dep_cereal
  143. dep_nlopt
  144. dep_openvdb
  145. dep_OpenCSG
  146. dep_CGAL
  147. ${PNG_PKG}
  148. ${ZLIB_PKG}
  149. ${EXPAT_PKG}
  150. )
  151. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  152. # Patch the boost::polygon library with a custom one.
  153. ExternalProject_Add(dep_boost_polygon
  154. EXCLUDE_FROM_ALL ON
  155. GIT_REPOSITORY "https://github.com/prusa3d/polygon"
  156. GIT_TAG prusaslicer_gmp
  157. DEPENDS dep_boost
  158. CONFIGURE_COMMAND ""
  159. BUILD_COMMAND ""
  160. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
  161. "${CMAKE_CURRENT_BINARY_DIR}/dep_boost_polygon-prefix/src/dep_boost_polygon/include/boost/polygon"
  162. "${DESTDIR}/usr/local/include/boost/polygon"
  163. )
  164. # Only override boost::Polygon Voronoi implementation with Vojtech's GMP hacks on 64bit platforms.
  165. list(APPEND _dep_list "dep_boost_polygon")
  166. endif ()
  167. if (MSVC)
  168. # Experimental
  169. #list(APPEND _dep_list "dep_qhull")
  170. else()
  171. list(APPEND _dep_list "dep_qhull")
  172. # Not working, static build has different Eigen
  173. #list(APPEND _dep_list "dep_libigl")
  174. endif()
  175. add_custom_target(deps ALL DEPENDS ${_dep_list})
  176. # Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands
  177. # because they seem to generate bogus build files (possibly a bug in ExternalProject).