CMakeLists.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. function(prusaslicer_add_cmake_project projectname)
  49. cmake_parse_arguments(P_ARGS "" "INSTALL_DIR;BUILD_COMMAND;INSTALL_COMMAND" "CMAKE_ARGS" ${ARGN})
  50. set(_configs_line -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE})
  51. if (_is_multi OR MSVC)
  52. set(_configs_line "")
  53. endif ()
  54. set(_gen "")
  55. set(_build_j "-j${NPROC}")
  56. if (MSVC)
  57. set(_gen CMAKE_GENERATOR "${DEP_MSVC_GEN}" CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}")
  58. set(_build_j "/m")
  59. endif ()
  60. ExternalProject_Add(
  61. dep_${projectname}
  62. EXCLUDE_FROM_ALL ON
  63. INSTALL_DIR ${DESTDIR}/usr/local
  64. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/${projectname}
  65. ${_gen}
  66. CMAKE_ARGS
  67. -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR}/usr/local
  68. -DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/../cmake/modules
  69. -DCMAKE_PREFIX_PATH:STRING=${DESTDIR}/usr/local
  70. -DCMAKE_DEBUG_POSTFIX:STRING=d
  71. -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
  72. -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
  73. -DCMAKE_TOOLCHAIN_FILE:STRING=${CMAKE_TOOLCHAIN_FILE}
  74. -DBUILD_SHARED_LIBS:BOOL=OFF
  75. "${_configs_line}"
  76. ${DEP_CMAKE_OPTS}
  77. ${P_ARGS_CMAKE_ARGS}
  78. ${P_ARGS_UNPARSED_ARGUMENTS}
  79. BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release -- ${_build_j}
  80. INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config Release
  81. )
  82. endfunction(prusaslicer_add_cmake_project)
  83. if (MSVC)
  84. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  85. message(STATUS "\nDetected 64-bit compiler => building 64-bit deps bundle\n")
  86. set(DEPS_BITS 64)
  87. include("deps-windows.cmake")
  88. elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  89. message(STATUS "\nDetected 32-bit compiler => building 32-bit deps bundle\n")
  90. set(DEPS_BITS 32)
  91. include("deps-windows.cmake")
  92. else ()
  93. message(FATAL_ERROR "Unable to detect architecture")
  94. endif ()
  95. elseif (APPLE)
  96. message("OS X SDK Path: ${CMAKE_OSX_SYSROOT}")
  97. if (CMAKE_OSX_DEPLOYMENT_TARGET)
  98. set(DEP_OSX_TARGET "${CMAKE_OSX_DEPLOYMENT_TARGET}")
  99. message("OS X Deployment Target: ${DEP_OSX_TARGET}")
  100. else ()
  101. # Attempt to infer the SDK version from the CMAKE_OSX_SYSROOT,
  102. # this is done because wxWidgets need the min version explicitly set
  103. string(REGEX MATCH "[0-9]+[.][0-9]+[.]sdk$" DEP_OSX_TARGET "${CMAKE_OSX_SYSROOT}")
  104. string(REGEX MATCH "^[0-9]+[.][0-9]+" DEP_OSX_TARGET "${DEP_OSX_TARGET}")
  105. if (NOT DEP_OSX_TARGET)
  106. message(FATAL_ERROR "Could not determine OS X SDK version. Please use -DCMAKE_OSX_DEPLOYMENT_TARGET=<version>")
  107. endif ()
  108. message("OS X Deployment Target (inferred from SDK): ${DEP_OSX_TARGET}")
  109. endif ()
  110. include("deps-macos.cmake")
  111. elseif (MINGW)
  112. message(STATUS "Building for MinGW...")
  113. include("deps-mingw.cmake")
  114. else()
  115. include("deps-linux.cmake")
  116. endif()
  117. set(ZLIB_PKG "")
  118. if (NOT ZLIB_FOUND)
  119. include(ZLIB/ZLIB.cmake)
  120. set(ZLIB_PKG dep_ZLIB)
  121. endif ()
  122. set(PNG_PKG "")
  123. if (NOT PNG_FOUND)
  124. include(PNG/PNG.cmake)
  125. set(PNG_PKG dep_PNG)
  126. endif ()
  127. set(EXPAT_PKG "")
  128. if (NOT EXPAT_FOUND)
  129. include(EXPAT/EXPAT.cmake)
  130. set(EXPAT_PKG dep_EXPAT)
  131. endif ()
  132. set(DEP_Boost_COMPONENTS system iostreams filesystem thread log locale regex date_time)
  133. include(Boost/Boost.cmake)
  134. # The order of includes respects the dependencies between libraries
  135. include(Cereal/Cereal.cmake)
  136. include(Qhull/Qhull.cmake)
  137. include(GLEW/GLEW.cmake)
  138. include(OpenCSG/OpenCSG.cmake)
  139. include(TBB/TBB.cmake)
  140. include(Blosc/Blosc.cmake)
  141. include(OpenEXR/OpenEXR.cmake)
  142. include(OpenVDB/OpenVDB.cmake)
  143. include(GMP/GMP.cmake)
  144. include(MPFR/MPFR.cmake)
  145. include(CGAL/CGAL.cmake)
  146. include(NLopt/NLopt.cmake)
  147. include(OpenSSL/OpenSSL.cmake)
  148. include(CURL/CURL.cmake)
  149. include(JPEG/JPEG.cmake)
  150. include(TIFF/TIFF.cmake)
  151. include(wxWidgets/wxWidgets.cmake)
  152. set(_dep_list
  153. dep_Boost
  154. dep_TBB
  155. dep_CURL
  156. dep_wxWidgets
  157. dep_Cereal
  158. dep_NLopt
  159. dep_OpenVDB
  160. dep_OpenCSG
  161. dep_CGAL
  162. ${PNG_PKG}
  163. ${ZLIB_PKG}
  164. ${EXPAT_PKG}
  165. )
  166. if (MSVC)
  167. # Experimental
  168. #list(APPEND _dep_list "dep_qhull")
  169. else()
  170. list(APPEND _dep_list "dep_Qhull")
  171. # Not working, static build has different Eigen
  172. #list(APPEND _dep_list "dep_libigl")
  173. endif()
  174. add_custom_target(deps ALL DEPENDS ${_dep_list})
  175. # Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands
  176. # because they seem to generate bogus build files (possibly a bug in ExternalProject).