CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. option(DEP_DEBUG "Build debug variants (only applicable on Windows)" ON)
  32. option(DEP_WX_STABLE "Build against wxWidgets stable 3.0 as opposed to default 3.1 (Linux only)" OFF)
  33. # On developer machines, it can be enabled to speed up compilation and suppress warnings coming from IGL.
  34. # FIXME:
  35. # Enabling this option is not safe. IGL will compile itself with its own version of Eigen while
  36. # Slic3r compiles with a different version which will cause runtime errors.
  37. # option(DEP_BUILD_IGL_STATIC "Build IGL as a static library. Might cause link errors and increase binary size." OFF)
  38. message(STATUS "PrusaSlicer deps DESTDIR: ${DESTDIR}")
  39. message(STATUS "PrusaSlicer deps debug build: ${DEP_DEBUG}")
  40. find_package(Git REQUIRED)
  41. function(prusaslicer_add_cmake_project projectname)
  42. cmake_parse_arguments(P_ARGS "" "INSTALL_DIR;BUILD_COMMAND;INSTALL_COMMAND" "CMAKE_ARGS" ${ARGN})
  43. set(_configs_line -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE})
  44. if (_is_multi OR MSVC)
  45. set(_configs_line "")
  46. endif ()
  47. set(_gen "")
  48. set(_build_j "-j${NPROC}")
  49. if (MSVC)
  50. set(_gen CMAKE_GENERATOR "${DEP_MSVC_GEN}")
  51. set(_build_j "/m")
  52. endif ()
  53. ExternalProject_Add(
  54. dep_${projectname}
  55. EXCLUDE_FROM_ALL ON
  56. INSTALL_DIR ${DESTDIR}/usr/local
  57. ${_gen}
  58. CMAKE_ARGS
  59. -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR}/usr/local
  60. -DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/../cmake/modules
  61. -DCMAKE_PREFIX_PATH:STRING=${DESTDIR}/usr/local
  62. -DCMAKE_DEBUG_POSTFIX:STRING=d
  63. -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
  64. -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
  65. -DBUILD_SHARED_LIBS:BOOL=OFF
  66. "${_configs_line}"
  67. ${DEP_CMAKE_OPTS}
  68. ${P_ARGS_CMAKE_ARGS}
  69. ${P_ARGS_UNPARSED_ARGUMENTS}
  70. BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release -- ${_build_j}
  71. INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config Release
  72. )
  73. endfunction(prusaslicer_add_cmake_project)
  74. if (MSVC)
  75. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  76. message(STATUS "\nDetected 64-bit compiler => building 64-bit deps bundle\n")
  77. set(DEPS_BITS 64)
  78. include("deps-windows.cmake")
  79. elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  80. message(STATUS "\nDetected 32-bit compiler => building 32-bit deps bundle\n")
  81. set(DEPS_BITS 32)
  82. include("deps-windows.cmake")
  83. else ()
  84. message(FATAL_ERROR "Unable to detect architecture")
  85. endif ()
  86. elseif (APPLE)
  87. message("OS X SDK Path: ${CMAKE_OSX_SYSROOT}")
  88. if (CMAKE_OSX_DEPLOYMENT_TARGET)
  89. set(DEP_OSX_TARGET "${CMAKE_OSX_DEPLOYMENT_TARGET}")
  90. message("OS X Deployment Target: ${DEP_OSX_TARGET}")
  91. else ()
  92. # Attempt to infer the SDK version from the CMAKE_OSX_SYSROOT,
  93. # this is done because wxWidgets need the min version explicitly set
  94. string(REGEX MATCH "[0-9]+[.][0-9]+[.]sdk$" DEP_OSX_TARGET "${CMAKE_OSX_SYSROOT}")
  95. string(REGEX MATCH "^[0-9]+[.][0-9]+" DEP_OSX_TARGET "${DEP_OSX_TARGET}")
  96. if (NOT DEP_OSX_TARGET)
  97. message(FATAL_ERROR "Could not determine OS X SDK version. Please use -DCMAKE_OSX_DEPLOYMENT_TARGET=<version>")
  98. endif ()
  99. message("OS X Deployment Target (inferred from SDK): ${DEP_OSX_TARGET}")
  100. endif ()
  101. include("deps-macos.cmake")
  102. elseif (MINGW)
  103. message(STATUS "Building for MinGW...")
  104. include("deps-mingw.cmake")
  105. else()
  106. include("deps-linux.cmake")
  107. endif()
  108. include(GLEW/GLEW.cmake)
  109. include(OpenCSG/OpenCSG.cmake)
  110. include(GMP/GMP.cmake)
  111. include(MPFR/MPFR.cmake)
  112. include(CGAL/CGAL.cmake)
  113. if (MSVC)
  114. add_custom_target(deps ALL
  115. DEPENDS
  116. dep_boost
  117. dep_tbb
  118. dep_libcurl
  119. dep_wxwidgets
  120. dep_gtest
  121. dep_cereal
  122. dep_nlopt
  123. # dep_qhull # Experimental
  124. dep_ZLIB # on Windows we still need zlib
  125. dep_openvdb
  126. dep_OpenCSG
  127. dep_CGAL
  128. )
  129. else()
  130. add_custom_target(deps ALL
  131. DEPENDS
  132. dep_boost
  133. dep_tbb
  134. dep_libcurl
  135. dep_wxwidgets
  136. dep_gtest
  137. dep_cereal
  138. dep_nlopt
  139. dep_qhull
  140. dep_openvdb
  141. dep_OpenCSG
  142. dep_CGAL
  143. # dep_libigl # Not working, static build has different Eigen
  144. )
  145. endif()
  146. # Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands
  147. # because they seem to generate bogus build files (possibly a bug in ExternalProject).