Boost.cmake 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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_flags "")
  62. if (UNIX)
  63. set(_boost_flags "cflags=-fPIC;cxxflags=-fPIC")
  64. endif ()
  65. if(APPLE)
  66. set(_boost_flags
  67. "cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
  68. "cxxflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
  69. "mflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
  70. "mmflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET}")
  71. endif()
  72. set(_boost_variants "")
  73. if(CMAKE_BUILD_TYPE)
  74. list(APPEND CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
  75. list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
  76. endif()
  77. list(FIND CMAKE_CONFIGURATION_TYPES "Release" _cfg_rel)
  78. list(FIND CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" _cfg_relwdeb)
  79. list(FIND CMAKE_CONFIGURATION_TYPES "MinSizeRel" _cfg_minsizerel)
  80. list(FIND CMAKE_CONFIGURATION_TYPES "Debug" _cfg_deb)
  81. if (_cfg_rel GREATER -1 OR _cfg_relwdeb GREATER -1 OR _cfg_minsizerel GREATER -1)
  82. list(APPEND _boost_variants release)
  83. endif()
  84. if (_cfg_deb GREATER -1 OR (MSVC AND ${DEP_DEBUG}) )
  85. list(APPEND _boost_variants debug)
  86. endif()
  87. if (NOT _boost_variants)
  88. set(_boost_variants release)
  89. endif()
  90. set(_boost_layout system)
  91. if (MSVC)
  92. set(_boost_layout versioned)
  93. endif ()
  94. if (IS_CROSS_COMPILE AND APPLE)
  95. if (${CMAKE_OSX_ARCHITECTURES} MATCHES "arm")
  96. message(STATUS "Compiling Boost for arm64.")
  97. message(STATUS "Compiling Boost with toolset ${_boost_toolset}.")
  98. message(STATUS "Compiling Boost with libs ${_libs}.")
  99. message(STATUS "Compiling Boost with variant ${_boost_variants}.")
  100. message(STATUS "Compiling Boost with _bootstrap_cmd ${_bootstrap_cmd}.")
  101. message(STATUS "_boost_linkflags = ${_boost_linkflags}")
  102. set(_arch_flags "-arch arm64")
  103. set(_boost_linkflags "linkflags=${_arch_flags}")
  104. message(STATUS "_cmake_args_osx_arch = '${_cmake_args_osx_arch}'")
  105. elseif (${CMAKE_OSX_ARCHITECTURES} MATCHES "x86_64")
  106. message(STATUS "Compiling Boost for x86_64.")
  107. set(_arch_flags "-arch x86_64")
  108. endif()
  109. set(_boost_linkflags "linkflags=${_arch_flags}")
  110. endif ()
  111. set(_build_cmd ${_build_cmd}
  112. ${_boost_flags}
  113. ${_boost_linkflags}
  114. -j${NPROC}
  115. ${_libs}
  116. --layout=${_boost_layout}
  117. --debug-configuration
  118. toolset=${_boost_toolset}
  119. address-model=${_bits}
  120. link=${_link}
  121. threading=multi
  122. boost.locale.icu=off
  123. --disable-icu
  124. ${_boost_variants}
  125. stage)
  126. set(_install_cmd ${_build_cmd} --prefix=${_prefix} install)
  127. if (NOT IS_CROSS_COMPILE OR NOT APPLE OR BUILD_SHARED_LIBS)
  128. message(STATUS "Standard boost build with bootstrap command '${_bootstrap_cmd}'")
  129. message(STATUS "Standard boost build with patch command '${_patch_command}'")
  130. message(STATUS "Standard boost build with build command '${_build_cmd}'")
  131. message(STATUS "Standard boost build with install command '${_install_cmd}'")
  132. ExternalProject_Add(
  133. dep_Boost
  134. # URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz"
  135. URL "https://github.com/supermerill/SuperSlicer_deps/releases/download/1.75/boost_1_75_0.tar.gz"
  136. URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a
  137. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Boost
  138. CONFIGURE_COMMAND "${_bootstrap_cmd}"
  139. PATCH_COMMAND ${_patch_command}
  140. BUILD_COMMAND "${_build_cmd}"
  141. BUILD_IN_SOURCE ON
  142. INSTALL_COMMAND "${_install_cmd}"
  143. )
  144. else()
  145. ExternalProject_Add(
  146. dep_Boost
  147. # URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz"
  148. URL "https://github.com/supermerill/SuperSlicer_deps/releases/download/1.75/boost_1_75_0.tar.gz"
  149. URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a
  150. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Boost
  151. CONFIGURE_COMMAND ./bootstrap.sh
  152. --with-toolset=clang
  153. --with-libraries=date_time,filesystem,iostreams,locale,log,regex,system,thread
  154. "--prefix=${DESTDIR}/usr/local"
  155. # PATCH_COMMAND ${_patch_command}
  156. BUILD_COMMAND "${_build_cmd}"
  157. BUILD_IN_SOURCE ON
  158. INSTALL_COMMAND "${_install_cmd}"
  159. )
  160. # message(STATUS "Old boost build")
  161. # ExternalProject_Add(dep_boost
  162. # # EXCLUDE_FROM_ALL ON
  163. # URL "https://github.com/supermerill/SuperSlicer_deps/releases/download/1.75/boost_1_75_0.tar.gz"
  164. # URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a
  165. # DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Boost
  166. # BUILD_IN_SOURCE ON
  167. # CONFIGURE_COMMAND ./bootstrap.sh
  168. # --with-toolset=clang
  169. # --with-libraries=date_time,filesystem,iostreams,locale,log,regex,system,thread
  170. # "--prefix=${DESTDIR}/usr/local"
  171. # BUILD_COMMAND ./b2
  172. # -j ${NPROC}
  173. # --reconfigure
  174. # toolset=clang
  175. # link=static
  176. # variant=release
  177. # threading=multi
  178. # boost.locale.icu=off
  179. # --disable-icu
  180. # "cflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}"
  181. # "cxxflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}"
  182. # "mflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}"
  183. # "mmflags=-fPIC ${_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}"
  184. # ${_boost_linkflags}
  185. # install
  186. # INSTALL_COMMAND "${_install_cmd}"
  187. # )
  188. endif()
  189. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  190. message(STATUS "Patch the boost::polygon library with a custom one.")
  191. # Patch the boost::polygon library with a custom one.
  192. ExternalProject_Add(dep_boost_polygon
  193. EXCLUDE_FROM_ALL ON
  194. # GIT_REPOSITORY "https://github.com/prusa3d/polygon"
  195. # GIT_TAG prusaslicer_gmp
  196. URL https://github.com/prusa3d/polygon/archive/refs/heads/prusaslicer_gmp.zip
  197. URL_HASH SHA256=abeb9710f0a7069fb9b22181ae5c56f6066002f125db210e7ffb27032aed6824
  198. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/boost_polygon
  199. DEPENDS dep_Boost
  200. CONFIGURE_COMMAND ""
  201. BUILD_COMMAND ""
  202. ${_cmake_args_osx_arch}
  203. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
  204. "${CMAKE_CURRENT_BINARY_DIR}/dep_boost_polygon-prefix/src/dep_boost_polygon/include/boost/polygon"
  205. "${DESTDIR}/usr/local/include/boost/polygon"
  206. )
  207. # Only override boost::Polygon Voronoi implementation with Vojtech's GMP hacks on 64bit platforms.
  208. list(APPEND _dep_list "dep_boost_polygon")
  209. endif ()