CMakeLists.txt 6.1 KB

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