CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if (MSVC)
  41. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  42. message(STATUS "\nDetected 64-bit compiler => building 64-bit deps bundle\n")
  43. set(DEPS_BITS 64)
  44. include("deps-windows.cmake")
  45. elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  46. message(STATUS "\nDetected 32-bit compiler => building 32-bit deps bundle\n")
  47. set(DEPS_BITS 32)
  48. include("deps-windows.cmake")
  49. else ()
  50. message(FATAL_ERROR "Unable to detect architecture")
  51. endif ()
  52. elseif (APPLE)
  53. message("OS X SDK Path: ${CMAKE_OSX_SYSROOT}")
  54. if (CMAKE_OSX_DEPLOYMENT_TARGET)
  55. set(DEP_OSX_TARGET "${CMAKE_OSX_DEPLOYMENT_TARGET}")
  56. message("OS X Deployment Target: ${DEP_OSX_TARGET}")
  57. else ()
  58. # Attempt to infer the SDK version from the CMAKE_OSX_SYSROOT,
  59. # this is done because wxWidgets need the min version explicitly set
  60. string(REGEX MATCH "[0-9]+[.][0-9]+[.]sdk$" DEP_OSX_TARGET "${CMAKE_OSX_SYSROOT}")
  61. string(REGEX MATCH "^[0-9]+[.][0-9]+" DEP_OSX_TARGET "${DEP_OSX_TARGET}")
  62. if (NOT DEP_OSX_TARGET)
  63. message(FATAL_ERROR "Could not determine OS X SDK version. Please use -DCMAKE_OSX_DEPLOYMENT_TARGET=<version>")
  64. endif ()
  65. message("OS X Deployment Target (inferred from default): ${DEP_OSX_TARGET}")
  66. endif ()
  67. include("deps-macos.cmake")
  68. elseif (MINGW)
  69. message(STATUS "Building for MinGW...")
  70. include("deps-mingw.cmake")
  71. else()
  72. include("deps-linux.cmake")
  73. endif()
  74. if (MSVC)
  75. add_custom_target(deps ALL
  76. DEPENDS
  77. dep_boost
  78. dep_tbb
  79. dep_libcurl
  80. dep_wxwidgets
  81. dep_gtest
  82. dep_cereal
  83. dep_nlopt
  84. # dep_qhull # Experimental
  85. dep_zlib # on Windows we still need zlib
  86. )
  87. else()
  88. add_custom_target(deps ALL
  89. DEPENDS
  90. dep_boost
  91. dep_tbb
  92. dep_libcurl
  93. dep_wxwidgets
  94. dep_gtest
  95. dep_cereal
  96. dep_nlopt
  97. dep_qhull
  98. # dep_libigl # Not working, static build has different Eigen
  99. )
  100. endif()
  101. # Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands
  102. # because they seem to generate bogus build files (possibly a bug in ExternalProject).