vcpkg/ports/boost-cmake/add-optional-deps.diff
Alexander Neumann bcf3d00d21
[Boost] use cmake build (#32309)
~~arm64-windows: boost-context builds are blocked by a cmake bug (see
https://gitlab.kitware.com/cmake/cmake/-/issues/24317)~~

closes #32274
closes https://github.com/Neumann-A/my-vcpkg-triplets/issues/5

Questions:
- [x] ~~Move cmake files to `share/cmake/<name>` ?~~ Not doing it
because it is just using `vcpkg_cmake_config_fixup()`
- [x] Fix weak dependencies (uwp|emscripten|android|arm)?
- [x] Fix library names on !x64 (currently hardcoded to x64 or x86;
failure in aricpp since it forces FindBoost module mode.)
- [x] ~~Fix arm64-windows boost-context builds -> requires CMake
(3.19.2?) update due to bug how the assembler is invoked.~~ (-> CI
baseline for now)

TODO:
- [x] adjust generate ports script
- [x] #37457

---------

Co-authored-by: Cheney-Wang <850426846@qq.com>
2024-04-29 15:27:41 -04:00

56 lines
2.2 KiB
Diff

diff --git a/include/BoostInstall.cmake b/include/BoostInstall.cmake
index f9342f1715..a6bd9c349a 100644
--- a/include/BoostInstall.cmake
+++ b/include/BoostInstall.cmake
@@ -315,6 +315,12 @@ function(boost_install_target)
string(APPEND CONFIG_FILE_CONTENTS " find_dependency(boost_${CMAKE_MATCH_1} ${__VERSION} EXACT)\n")
string(APPEND CONFIG_FILE_CONTENTS "endif()\n")
+ elseif(dep MATCHES "^\\$<TARGET_NAME_IF_EXISTS:Boost::(.*)>$")
+
+ string(APPEND CONFIG_FILE_CONTENTS "if(NOT boost_${CMAKE_MATCH_1}_FOUND)\n")
+ string(APPEND CONFIG_FILE_CONTENTS " find_package(boost_${CMAKE_MATCH_1} ${__VERSION} EXACT QUIET)\n")
+ string(APPEND CONFIG_FILE_CONTENTS "endif()\n")
+
elseif(dep STREQUAL "Threads::Threads")
string(APPEND CONFIG_FILE_CONTENTS "set(THREADS_PREFER_PTHREAD_FLAG ON)\n")
diff --git a/include/BoostRoot.cmake b/include/BoostRoot.cmake
index f356666739..1843f528cd 100644
--- a/include/BoostRoot.cmake
+++ b/include/BoostRoot.cmake
@@ -189,6 +189,7 @@ function(__boost_scan_dependencies lib var)
set(result "")
set(required_components "")
+ set(optional_components "")
if(EXISTS "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${lib}/CMakeLists.txt")
@@ -202,6 +203,12 @@ function(__boost_scan_dependencies lib var)
string(REGEX REPLACE "^numeric_" "numeric/" dep ${CMAKE_MATCH_1})
list(APPEND result ${dep})
+ elseif(line MATCHES "^[ ]*$<TARGET_NAME_IF_EXISTS:Boost::([A-Za-z0-9_]+)>[ ]*$")
+
+ list(APPEND optional_components ${CMAKE_MATCH_1})
+ string(REGEX REPLACE "^numeric_" "numeric/" dep ${CMAKE_MATCH_1})
+ list(APPEND result ${dep})
+
endif()
endforeach()
@@ -209,9 +216,10 @@ function(__boost_scan_dependencies lib var)
endif()
list(REMOVE_DUPLICATES required_components)
+ list(REMOVE_DUPLICATES optional_components)
list(REMOVE_ITEM required_components boost ${lib}) # due to property_tree and python
- if(required_components)
+ if(required_components OR optional_components)
- find_package(Boost COMPONENTS ${required_components} REQUIRED CONFIG)
+ find_package(Boost COMPONENTS ${required_components} OPTIONAL_COMPONENTS ${optional_components} REQUIRED CONFIG)
endif()
set(${var} ${result} PARENT_SCOPE)