CMakeLists.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #
  2. # This CMake project downloads, configures and builds PrusaSlicer 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 PrusaSlicer - 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 PrusaSlicer.
  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(PrusaSlicer-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. set(DEP_DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Path for downloaded source packages.")
  32. option(DEP_DEBUG "Build debug variants (only applicable on Windows)" ON)
  33. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  34. option(DEP_WX_GTK3 "Build wxWidgets against GTK3" OFF)
  35. endif()
  36. # On developer machines, it can be enabled to speed up compilation and suppress warnings coming from IGL.
  37. # FIXME:
  38. # Enabling this option is not safe. IGL will compile itself with its own version of Eigen while
  39. # Slic3r compiles with a different version which will cause runtime errors.
  40. # option(DEP_BUILD_IGL_STATIC "Build IGL as a static library. Might cause link errors and increase binary size." OFF)
  41. message(STATUS "PrusaSlicer deps DESTDIR: ${DESTDIR}")
  42. message(STATUS "PrusaSlicer dowload dir for source packages: ${DEP_DOWNLOAD_DIR}")
  43. message(STATUS "PrusaSlicer deps debug build: ${DEP_DEBUG}")
  44. find_package(Git REQUIRED)
  45. # The default command line for patching. Only works for newer
  46. set(PATCH_CMD ${GIT_EXECUTABLE} apply --verbose --ignore-space-change --whitespace=fix)
  47. get_property(_is_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  48. if (NOT _is_multi AND NOT CMAKE_BUILD_TYPE)
  49. set(CMAKE_BUILD_TYPE Release)
  50. message(STATUS "Forcing CMAKE_BUILD_TYPE to Release as it was not specified.")
  51. endif ()
  52. function(prusaslicer_add_cmake_project projectname)
  53. cmake_parse_arguments(P_ARGS "" "INSTALL_DIR;BUILD_COMMAND;INSTALL_COMMAND" "CMAKE_ARGS" ${ARGN})
  54. set(_configs_line -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE})
  55. if (_is_multi OR MSVC)
  56. set(_configs_line "")
  57. endif ()
  58. set(_gen "")
  59. set(_build_j "-j${NPROC}")
  60. if (MSVC)
  61. set(_gen CMAKE_GENERATOR "${DEP_MSVC_GEN}" CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}")
  62. set(_build_j "/m")
  63. endif ()
  64. ExternalProject_Add(
  65. dep_${projectname}
  66. EXCLUDE_FROM_ALL ON
  67. INSTALL_DIR ${DESTDIR}/usr/local
  68. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/${projectname}
  69. ${_gen}
  70. CMAKE_ARGS
  71. -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR}/usr/local
  72. -DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/../cmake/modules
  73. -DCMAKE_PREFIX_PATH:STRING=${DESTDIR}/usr/local
  74. -DCMAKE_DEBUG_POSTFIX:STRING=d
  75. -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
  76. -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
  77. -DCMAKE_TOOLCHAIN_FILE:STRING=${CMAKE_TOOLCHAIN_FILE}
  78. -DBUILD_SHARED_LIBS:BOOL=OFF
  79. "${_configs_line}"
  80. ${DEP_CMAKE_OPTS}
  81. ${P_ARGS_CMAKE_ARGS}
  82. ${P_ARGS_UNPARSED_ARGUMENTS}
  83. BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release -- ${_build_j}
  84. INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config Release
  85. )
  86. endfunction(prusaslicer_add_cmake_project)
  87. if (MSVC)
  88. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  89. message(STATUS "\nDetected 64-bit compiler => building 64-bit deps bundle\n")
  90. set(DEPS_BITS 64)
  91. include("deps-windows.cmake")
  92. elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  93. message(STATUS "\nDetected 32-bit compiler => building 32-bit deps bundle\n")
  94. set(DEPS_BITS 32)
  95. include("deps-windows.cmake")
  96. else ()
  97. message(FATAL_ERROR "Unable to detect architecture")
  98. endif ()
  99. elseif (APPLE)
  100. message("OS X SDK Path: ${CMAKE_OSX_SYSROOT}")
  101. if (CMAKE_OSX_DEPLOYMENT_TARGET)
  102. set(DEP_OSX_TARGET "${CMAKE_OSX_DEPLOYMENT_TARGET}")
  103. message("OS X Deployment Target: ${DEP_OSX_TARGET}")
  104. else ()
  105. # Attempt to infer the SDK version from the CMAKE_OSX_SYSROOT,
  106. # this is done because wxWidgets need the min version explicitly set
  107. string(REGEX MATCH "[0-9]+[.][0-9]+[.]sdk$" DEP_OSX_TARGET "${CMAKE_OSX_SYSROOT}")
  108. string(REGEX MATCH "^[0-9]+[.][0-9]+" DEP_OSX_TARGET "${DEP_OSX_TARGET}")
  109. if (NOT DEP_OSX_TARGET)
  110. message(FATAL_ERROR "Could not determine OS X SDK version. Please use -DCMAKE_OSX_DEPLOYMENT_TARGET=<version>")
  111. endif ()
  112. message("OS X Deployment Target (inferred from SDK): ${DEP_OSX_TARGET}")
  113. endif ()
  114. include("deps-macos.cmake")
  115. elseif (MINGW)
  116. message(STATUS "Building for MinGW...")
  117. include("deps-mingw.cmake")
  118. else()
  119. include("deps-linux.cmake")
  120. endif()
  121. set(ZLIB_PKG "")
  122. if (NOT ZLIB_FOUND)
  123. include(ZLIB/ZLIB.cmake)
  124. set(ZLIB_PKG dep_ZLIB)
  125. endif ()
  126. set(PNG_PKG "")
  127. if (NOT PNG_FOUND)
  128. include(PNG/PNG.cmake)
  129. set(PNG_PKG dep_PNG)
  130. endif ()
  131. set(EXPAT_PKG "")
  132. if (NOT EXPAT_FOUND)
  133. include(EXPAT/EXPAT.cmake)
  134. set(EXPAT_PKG dep_EXPAT)
  135. endif ()
  136. set(DEP_Boost_COMPONENTS system iostreams filesystem thread log locale regex date_time)
  137. include(Boost/Boost.cmake)
  138. # The order of includes respects the dependencies between libraries
  139. include(Cereal/Cereal.cmake)
  140. include(Qhull/Qhull.cmake)
  141. include(GLEW/GLEW.cmake)
  142. include(OpenCSG/OpenCSG.cmake)
  143. include(TBB/TBB.cmake)
  144. include(Blosc/Blosc.cmake)
  145. include(OpenEXR/OpenEXR.cmake)
  146. include(OpenVDB/OpenVDB.cmake)
  147. include(GMP/GMP.cmake)
  148. include(MPFR/MPFR.cmake)
  149. include(CGAL/CGAL.cmake)
  150. include(NLopt/NLopt.cmake)
  151. include(OpenSSL/OpenSSL.cmake)
  152. include(CURL/CURL.cmake)
  153. include(JPEG/JPEG.cmake)
  154. include(TIFF/TIFF.cmake)
  155. include(wxWidgets/wxWidgets.cmake)
  156. set(_dep_list
  157. dep_Boost
  158. dep_TBB
  159. dep_CURL
  160. dep_wxWidgets
  161. dep_Cereal
  162. dep_NLopt
  163. dep_OpenVDB
  164. dep_OpenCSG
  165. dep_CGAL
  166. ${PNG_PKG}
  167. ${ZLIB_PKG}
  168. ${EXPAT_PKG}
  169. )
  170. if (MSVC)
  171. # Experimental
  172. #list(APPEND _dep_list "dep_qhull")
  173. else()
  174. list(APPEND _dep_list "dep_Qhull")
  175. # Not working, static build has different Eigen
  176. #list(APPEND _dep_list "dep_libigl")
  177. endif()
  178. add_custom_target(deps ALL DEPENDS ${_dep_list})
  179. # Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands
  180. # because they seem to generate bogus build files (possibly a bug in ExternalProject).