Boost.cmake 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. include(ExternalProject)
  2. if (WIN32)
  3. set(_bootstrap_cmd bootstrap.bat)
  4. set(_build_cmd b2.exe)
  5. else()
  6. set(_bootstrap_cmd ./bootstrap.sh)
  7. set(_build_cmd ./b2)
  8. endif()
  9. set(_patch_command ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/common.jam ./tools/build/src/tools/common.jam)
  10. if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  11. configure_file(${CMAKE_CURRENT_LIST_DIR}/user-config.jam boost-user-config.jam)
  12. set(_boost_toolset gcc)
  13. set(_patch_command ${_patch_command} && ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/boost-user-config.jam ./tools/build/src/tools/user-config.jam)
  14. elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  15. # https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
  16. if (MSVC_VERSION EQUAL 1800)
  17. # 1800 = VS 12.0 (v120 toolset)
  18. set(_boost_toolset "msvc-12.0")
  19. elseif (MSVC_VERSION EQUAL 1900)
  20. # 1900 = VS 14.0 (v140 toolset)
  21. set(_boost_toolset "msvc-14.0")
  22. elseif (MSVC_VERSION LESS 1920)
  23. # 1910-1919 = VS 15.0 (v141 toolset)
  24. set(_boost_toolset "msvc-14.1")
  25. elseif (MSVC_VERSION LESS 1930)
  26. # 1920-1929 = VS 16.0 (v142 toolset)
  27. set(_boost_toolset "msvc-14.2")
  28. else ()
  29. message(FATAL_ERROR "Unsupported MSVC version")
  30. endif ()
  31. elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  32. if (WIN32)
  33. set(_boost_toolset "clang-win")
  34. else()
  35. set(_boost_toolset "clang")
  36. endif()
  37. elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
  38. set(_boost_toolset "intel")
  39. elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
  40. set(_boost_toolset "clang")
  41. endif()
  42. message(STATUS "Deduced boost toolset: ${_boost_toolset} based on ${CMAKE_CXX_COMPILER_ID} compiler")
  43. set(_libs "")
  44. foreach(_comp ${DEP_Boost_COMPONENTS})
  45. list(APPEND _libs "--with-${_comp}")
  46. endforeach()
  47. if (BUILD_SHARED_LIBS)
  48. set(_link shared)
  49. else()
  50. set(_link static)
  51. endif()
  52. set(_bits "")
  53. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  54. set(_bits 64)
  55. elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  56. set(_bits 32)
  57. endif ()
  58. include(ProcessorCount)
  59. ProcessorCount(NPROC)
  60. file(TO_NATIVE_PATH ${DESTDIR}/usr/local/ _prefix)
  61. set(_boost_variants "")
  62. if(CMAKE_BUILD_TYPE)
  63. list(APPEND CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
  64. list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
  65. endif()
  66. list(FIND CMAKE_CONFIGURATION_TYPES "Release" _cfg_rel)
  67. list(FIND CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" _cfg_relwdeb)
  68. list(FIND CMAKE_CONFIGURATION_TYPES "MinSizeRel" _cfg_minsizerel)
  69. list(FIND CMAKE_CONFIGURATION_TYPES "Debug" _cfg_deb)
  70. if (_cfg_rel GREATER -1 OR _cfg_relwdeb GREATER -1 OR _cfg_minsizerel GREATER -1)
  71. list(APPEND _boost_variants release)
  72. endif()
  73. if (_cfg_deb GREATER -1 OR (MSVC AND ${DEP_DEBUG}) )
  74. list(APPEND _boost_variants debug)
  75. endif()
  76. if (NOT _boost_variants)
  77. set(_boost_variants release)
  78. endif()
  79. if (IS_CROSS_COMPILE AND APPLE)
  80. if (${CMAKE_OSX_ARCHITECTURES} MATCHES "arm")
  81. message(STATUS "Compiling Boost for arm64.")
  82. message(STATUS "Compiling Boost with toolset ${_boost_toolset}.")
  83. message(STATUS "Compiling Boost with libs ${_libs}.")
  84. message(STATUS "Compiling Boost with variant ${_boost_variants}.")
  85. message(STATUS "Compiling Boost with _bootstrap_cmd ${_bootstrap_cmd}.")
  86. message(STATUS "_boost_linkflags = ${_boost_linkflags}")
  87. set(_arch_flags "-arch arm64")
  88. set(_boost_linkflags "linkflags=${_arch_flags}")
  89. message(STATUS "_cmake_args_osx_arch = '${_cmake_args_osx_arch}'")
  90. elseif (${CMAKE_OSX_ARCHITECTURES} MATCHES "x86_64")
  91. message(STATUS "Compiling Boost for x86_64.")
  92. set(_arch_flags "-arch x86_64")
  93. endif()
  94. set(_boost_linkflags "linkflags=${_arch_flags}")
  95. endif ()
  96. set(_boost_flags "")
  97. if (UNIX)
  98. set(_boost_flags "cflags=-fPIC;cxxflags=-fPIC")
  99. elseif(APPLE)
  100. set(_boost_flags
  101. "cflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET};"
  102. "cxxflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET};"
  103. "mflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET};"
  104. "mmflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}")
  105. endif()
  106. set(_build_cmd ${_build_cmd}
  107. ${_boost_flags}
  108. ${_boost_linkflags}
  109. -j${NPROC}
  110. ${_libs}
  111. --layout=versioned
  112. --debug-configuration
  113. toolset=${_boost_toolset}
  114. address-model=${_bits}
  115. link=${_link}
  116. threading=multi
  117. boost.locale.icu=off
  118. --disable-icu
  119. ${_boost_variants}
  120. stage)
  121. set(_install_cmd ${_build_cmd} --prefix=${_prefix} install)
  122. if (NOT IS_CROSS_COMPILE OR NOT APPLE OR BUILD_SHARED_LIBS)
  123. message(STATUS "Standard boost build with bootstrap command '${_bootstrap_cmd}'")
  124. message(STATUS "Standard boost build with patch command '${_patch_command}'")
  125. message(STATUS "Standard boost build with build command '${_build_cmd}'")
  126. message(STATUS "Standard boost build with install command '${_install_cmd}'")
  127. ExternalProject_Add(
  128. dep_Boost
  129. # URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz"
  130. URL "https://github.com/supermerill/SuperSlicer_deps/releases/download/1.75/boost_1_75_0.tar.gz"
  131. URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a
  132. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Boost
  133. CONFIGURE_COMMAND "${_bootstrap_cmd}"
  134. PATCH_COMMAND ${_patch_command}
  135. BUILD_COMMAND "${_build_cmd}"
  136. BUILD_IN_SOURCE ON
  137. INSTALL_COMMAND "${_install_cmd}"
  138. )
  139. else()
  140. ExternalProject_Add(
  141. dep_Boost
  142. # URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz"
  143. URL "https://github.com/supermerill/SuperSlicer_deps/releases/download/1.75/boost_1_75_0.tar.gz"
  144. URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a
  145. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Boost
  146. CONFIGURE_COMMAND ./bootstrap.sh
  147. --with-toolset=clang
  148. --with-libraries=date_time,filesystem,iostreams,locale,log,regex,system,thread
  149. "--prefix=${DESTDIR}/usr/local"
  150. # PATCH_COMMAND ${_patch_command}
  151. BUILD_COMMAND "${_build_cmd}"
  152. BUILD_IN_SOURCE ON
  153. INSTALL_COMMAND "${_install_cmd}"
  154. )
  155. # message(STATUS "Old boost build")
  156. # ExternalProject_Add(dep_boost
  157. # # EXCLUDE_FROM_ALL ON
  158. # URL "https://github.com/supermerill/SuperSlicer_deps/releases/download/1.75/boost_1_75_0.tar.gz"
  159. # URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a
  160. # DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Boost
  161. # BUILD_IN_SOURCE ON
  162. # CONFIGURE_COMMAND ./bootstrap.sh
  163. # --with-toolset=clang
  164. # --with-libraries=date_time,filesystem,iostreams,locale,log,regex,system,thread
  165. # "--prefix=${DESTDIR}/usr/local"
  166. # BUILD_COMMAND ./b2
  167. # -j ${NPROC}
  168. # --reconfigure
  169. # toolset=clang
  170. # link=static
  171. # variant=release
  172. # threading=multi
  173. # boost.locale.icu=off
  174. # --disable-icu
  175. # "cflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}"
  176. # "cxxflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}"
  177. # "mflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}"
  178. # "mmflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}"
  179. # ${_boost_linkflags}
  180. # install
  181. # INSTALL_COMMAND "${_install_cmd}"
  182. # )
  183. endif()
  184. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  185. message(STATUS "Patch the boost::polygon library with a custom one.")
  186. # Patch the boost::polygon library with a custom one.
  187. ExternalProject_Add(dep_boost_polygon
  188. EXCLUDE_FROM_ALL ON
  189. # GIT_REPOSITORY "https://github.com/prusa3d/polygon"
  190. # GIT_TAG prusaslicer_gmp
  191. URL https://github.com/prusa3d/polygon/archive/refs/heads/prusaslicer_gmp.zip
  192. URL_HASH SHA256=abeb9710f0a7069fb9b22181ae5c56f6066002f125db210e7ffb27032aed6824
  193. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/boost_polygon
  194. DEPENDS dep_Boost
  195. CONFIGURE_COMMAND ""
  196. BUILD_COMMAND ""
  197. ${_cmake_args_osx_arch}
  198. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
  199. "${CMAKE_CURRENT_BINARY_DIR}/dep_boost_polygon-prefix/src/dep_boost_polygon/include/boost/polygon"
  200. "${DESTDIR}/usr/local/include/boost/polygon"
  201. )
  202. # Only override boost::Polygon Voronoi implementation with Vojtech's GMP hacks on 64bit platforms.
  203. list(APPEND _dep_list "dep_boost_polygon")
  204. endif ()