boost.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. if(TARGET Boost::boost)
  2. return()
  3. endif()
  4. message(STATUS "Third-party: creating targets 'Boost::boost'...")
  5. include(FetchContent)
  6. FetchContent_Declare(
  7. boost-cmake
  8. GIT_REPOSITORY https://github.com/Orphis/boost-cmake.git
  9. GIT_TAG 7f97a08b64bd5d2e53e932ddf80c40544cf45edf
  10. )
  11. set(PREVIOUS_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  12. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
  13. set(OLD_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
  14. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  15. # This guy will download boost using FetchContent
  16. FetchContent_GetProperties(boost-cmake)
  17. if(NOT boost-cmake_POPULATED)
  18. FetchContent_Populate(boost-cmake)
  19. # File lcid.cpp from Boost_locale.cpp doesn't compile on MSVC, so we exclude them from the default
  20. # targets being built by the project (only targets explicitly used by other targets will be built).
  21. add_subdirectory(${boost-cmake_SOURCE_DIR} ${boost-cmake_BINARY_DIR} EXCLUDE_FROM_ALL)
  22. endif()
  23. set(CMAKE_POSITION_INDEPENDENT_CODE ${OLD_CMAKE_POSITION_INDEPENDENT_CODE})
  24. set(CMAKE_CXX_FLAGS "${PREVIOUS_CMAKE_CXX_FLAGS}")
  25. # Set VS target folders
  26. set(boost_modules
  27. container
  28. regex
  29. atomic
  30. exception
  31. chrono
  32. wave
  33. context
  34. coroutine
  35. date_time
  36. fiber
  37. filesystem
  38. graph
  39. iostreams
  40. locale
  41. log
  42. log_setup
  43. unit_test_framework
  44. math
  45. program_options
  46. timer
  47. random
  48. serialization
  49. system
  50. thread
  51. type_erasure
  52. )
  53. foreach(module IN ITEMS ${boost_modules})
  54. if(TARGET Boost_${module})
  55. set_target_properties(Boost_${module} PROPERTIES FOLDER ThirdParty/Boost)
  56. endif()
  57. endforeach()