Boost.cmake 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. set(_build_cmd ${_build_cmd}
  95. ${_boost_flags}
  96. -j${NPROC}
  97. ${_libs}
  98. --layout=${_boost_layout}
  99. --debug-configuration
  100. toolset=${_boost_toolset}
  101. address-model=${_bits}
  102. link=${_link}
  103. threading=multi
  104. boost.locale.icu=off
  105. --disable-icu
  106. ${_boost_variants}
  107. stage)
  108. set(_install_cmd ${_build_cmd} --prefix=${_prefix} install)
  109. ExternalProject_Add(
  110. dep_Boost
  111. URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz"
  112. URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a
  113. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Boost
  114. CONFIGURE_COMMAND "${_bootstrap_cmd}"
  115. PATCH_COMMAND ${_patch_command}
  116. BUILD_COMMAND "${_build_cmd}"
  117. BUILD_IN_SOURCE ON
  118. INSTALL_COMMAND "${_install_cmd}"
  119. )
  120. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  121. # Patch the boost::polygon library with a custom one.
  122. ExternalProject_Add(dep_boost_polygon
  123. EXCLUDE_FROM_ALL ON
  124. # GIT_REPOSITORY "https://github.com/prusa3d/polygon"
  125. # GIT_TAG prusaslicer_gmp
  126. URL https://github.com/prusa3d/polygon/archive/refs/heads/prusaslicer_gmp.zip
  127. URL_HASH SHA256=abeb9710f0a7069fb9b22181ae5c56f6066002f125db210e7ffb27032aed6824
  128. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/boost_polygon
  129. DEPENDS dep_Boost
  130. CONFIGURE_COMMAND ""
  131. BUILD_COMMAND ""
  132. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
  133. "${CMAKE_CURRENT_BINARY_DIR}/dep_boost_polygon-prefix/src/dep_boost_polygon/include/boost/polygon"
  134. "${DESTDIR}/usr/local/include/boost/polygon"
  135. )
  136. # Only override boost::Polygon Voronoi implementation with Vojtech's GMP hacks on 64bit platforms.
  137. list(APPEND _dep_list "dep_boost_polygon")
  138. endif ()