Boost.cmake 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. elseif (MSVC_VERSION LESS 1940)
  29. # 1930-1939 = VS 17.0 (v143 toolset)
  30. set(_boost_toolset "msvc-14.3")
  31. else ()
  32. message(FATAL_ERROR "Unsupported MSVC version")
  33. endif ()
  34. elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  35. if (WIN32)
  36. set(_boost_toolset "clang-win")
  37. else()
  38. set(_boost_toolset "clang")
  39. endif()
  40. elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
  41. set(_boost_toolset "intel")
  42. elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
  43. set(_boost_toolset "clang")
  44. endif()
  45. message(STATUS "Deduced boost toolset: ${_boost_toolset} based on ${CMAKE_CXX_COMPILER_ID} compiler")
  46. set(_libs "")
  47. foreach(_comp ${DEP_Boost_COMPONENTS})
  48. list(APPEND _libs "--with-${_comp}")
  49. endforeach()
  50. if (BUILD_SHARED_LIBS)
  51. set(_link shared)
  52. else()
  53. set(_link static)
  54. endif()
  55. set(_bits "")
  56. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  57. set(_bits 64)
  58. elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  59. set(_bits 32)
  60. endif ()
  61. include(ProcessorCount)
  62. ProcessorCount(NPROC)
  63. file(TO_NATIVE_PATH ${DESTDIR}/usr/local/ _prefix)
  64. set(_boost_flags "")
  65. if (UNIX)
  66. set(_boost_flags "cflags=-fPIC;cxxflags=-fPIC")
  67. elseif(APPLE)
  68. set(_boost_flags
  69. "cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
  70. "cxxflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
  71. "mflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
  72. "mmflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET}")
  73. endif()
  74. set(_boost_variants "")
  75. if(CMAKE_BUILD_TYPE)
  76. list(APPEND CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
  77. list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
  78. endif()
  79. list(FIND CMAKE_CONFIGURATION_TYPES "Release" _cfg_rel)
  80. list(FIND CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" _cfg_relwdeb)
  81. list(FIND CMAKE_CONFIGURATION_TYPES "MinSizeRel" _cfg_minsizerel)
  82. list(FIND CMAKE_CONFIGURATION_TYPES "Debug" _cfg_deb)
  83. if (_cfg_rel GREATER -1 OR _cfg_relwdeb GREATER -1 OR _cfg_minsizerel GREATER -1)
  84. list(APPEND _boost_variants release)
  85. endif()
  86. if (_cfg_deb GREATER -1 OR (MSVC AND ${DEP_DEBUG}) )
  87. list(APPEND _boost_variants debug)
  88. endif()
  89. if (NOT _boost_variants)
  90. set(_boost_variants release)
  91. endif()
  92. set(_build_cmd ${_build_cmd}
  93. ${_boost_flags}
  94. -j${NPROC}
  95. ${_libs}
  96. --layout=versioned
  97. --debug-configuration
  98. toolset=${_boost_toolset}
  99. address-model=${_bits}
  100. link=${_link}
  101. threading=multi
  102. boost.locale.icu=off
  103. --disable-icu
  104. ${_boost_variants}
  105. stage)
  106. set(_install_cmd ${_build_cmd} --prefix=${_prefix} install)
  107. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  108. # When Clang is used with enabled UndefinedBehaviorSanitizer, it produces "undefined reference to '__muloti4'" when __int128 is used.
  109. # Because of that, UndefinedBehaviorSanitizer is disabled for those functions that use __int128.
  110. list(APPEND _patch_command COMMAND ${PATCH_CMD} ${CMAKE_CURRENT_LIST_DIR}/Boost.patch)
  111. endif ()
  112. ExternalProject_Add(
  113. dep_Boost
  114. URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz"
  115. URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a
  116. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Boost
  117. CONFIGURE_COMMAND "${_bootstrap_cmd}"
  118. PATCH_COMMAND ${_patch_command}
  119. BUILD_COMMAND "${_build_cmd}"
  120. BUILD_IN_SOURCE ON
  121. INSTALL_COMMAND "${_install_cmd}"
  122. )
  123. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  124. # Patch the boost::polygon library with a custom one.
  125. ExternalProject_Add(dep_boost_polygon
  126. EXCLUDE_FROM_ALL ON
  127. # GIT_REPOSITORY "https://github.com/prusa3d/polygon"
  128. # GIT_TAG prusaslicer_gmp
  129. URL https://github.com/prusa3d/polygon/archive/refs/heads/prusaslicer_gmp.zip
  130. URL_HASH SHA256=abeb9710f0a7069fb9b22181ae5c56f6066002f125db210e7ffb27032aed6824
  131. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/boost_polygon
  132. DEPENDS dep_Boost
  133. CONFIGURE_COMMAND ""
  134. BUILD_COMMAND ""
  135. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
  136. "${CMAKE_CURRENT_BINARY_DIR}/dep_boost_polygon-prefix/src/dep_boost_polygon/include/boost/polygon"
  137. "${DESTDIR}/usr/local/include/boost/polygon"
  138. )
  139. # Only override boost::Polygon Voronoi implementation with Vojtech's GMP hacks on 64bit platforms.
  140. list(APPEND _dep_list "dep_boost_polygon")
  141. endif ()