Boost.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. elseif(APPLE)
  65. set(_boost_flags
  66. "cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
  67. "cxxflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
  68. "mflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
  69. "mmflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET}")
  70. endif()
  71. set(_boost_variants "")
  72. if(CMAKE_BUILD_TYPE)
  73. list(APPEND CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
  74. list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
  75. endif()
  76. list(FIND CMAKE_CONFIGURATION_TYPES "Release" _cfg_rel)
  77. list(FIND CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" _cfg_relwdeb)
  78. list(FIND CMAKE_CONFIGURATION_TYPES "MinSizeRel" _cfg_minsizerel)
  79. list(FIND CMAKE_CONFIGURATION_TYPES "Debug" _cfg_deb)
  80. if (_cfg_rel GREATER -1 OR _cfg_relwdeb GREATER -1 OR _cfg_minsizerel GREATER -1)
  81. list(APPEND _boost_variants release)
  82. endif()
  83. if (_cfg_deb GREATER -1 OR (MSVC AND ${DEP_DEBUG}) )
  84. list(APPEND _boost_variants debug)
  85. endif()
  86. if (NOT _boost_variants)
  87. set(_boost_variants release)
  88. endif()
  89. set(_build_cmd ${_build_cmd}
  90. ${_boost_flags}
  91. -j${NPROC}
  92. ${_libs}
  93. --layout=versioned
  94. --debug-configuration
  95. toolset=${_boost_toolset}
  96. address-model=${_bits}
  97. link=${_link}
  98. threading=multi
  99. boost.locale.icu=off
  100. --disable-icu
  101. ${_boost_variants}
  102. stage)
  103. set(_install_cmd ${_build_cmd} --prefix=${_prefix} install)
  104. ExternalProject_Add(
  105. dep_Boost
  106. URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz"
  107. URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a
  108. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Boost
  109. CONFIGURE_COMMAND "${_bootstrap_cmd}"
  110. PATCH_COMMAND ${_patch_command}
  111. BUILD_COMMAND "${_build_cmd}"
  112. BUILD_IN_SOURCE ON
  113. INSTALL_COMMAND "${_install_cmd}"
  114. )
  115. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  116. # Patch the boost::polygon library with a custom one.
  117. ExternalProject_Add(dep_boost_polygon
  118. EXCLUDE_FROM_ALL ON
  119. # GIT_REPOSITORY "https://github.com/prusa3d/polygon"
  120. # GIT_TAG prusaslicer_gmp
  121. URL https://github.com/prusa3d/polygon/archive/refs/heads/prusaslicer_gmp.zip
  122. URL_HASH SHA256=abeb9710f0a7069fb9b22181ae5c56f6066002f125db210e7ffb27032aed6824
  123. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/boost_polygon
  124. DEPENDS dep_Boost
  125. CONFIGURE_COMMAND ""
  126. BUILD_COMMAND ""
  127. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
  128. "${CMAKE_CURRENT_BINARY_DIR}/dep_boost_polygon-prefix/src/dep_boost_polygon/include/boost/polygon"
  129. "${DESTDIR}/usr/local/include/boost/polygon"
  130. )
  131. # Only override boost::Polygon Voronoi implementation with Vojtech's GMP hacks on 64bit platforms.
  132. list(APPEND _dep_list "dep_boost_polygon")
  133. endif ()