diff --git a/include/BoostRoot.cmake b/include/BoostRoot.cmake index 25bcbc4..3f58622 100644 --- a/include/BoostRoot.cmake +++ b/include/BoostRoot.cmake @@ -26,7 +26,7 @@ set(__boost_incompatible_libraries "") # Define cache variables if root project -if(CMAKE_SOURCE_DIR STREQUAL Boost_SOURCE_DIR) +if(1) # --with- set(BOOST_INCLUDE_LIBRARIES "" CACHE STRING @@ -217,6 +217,9 @@ function(__boost_scan_dependencies lib var sub_folder) # Libraries that define at least one library with a name like "_" set(prefix_names "asio" "dll" "fiber" "log" "regex" "stacktrace") set(result "") + set(required_components "") + set(optional_components "") + set(exclude_components "") set(cml_files "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${lib}") if(sub_folder) @@ -245,6 +248,11 @@ function(__boost_scan_dependencies lib var sub_folder) foreach(dep IN LISTS libs) string(REGEX REPLACE "^Boost::" "" dep ${dep}) + # Check if this dependency is optional in the original line + set(_is_optional OFF) + if(line MATCHES "\\$") + set(_is_optional ON) + endif() if(dep STREQUAL "headers" OR dep STREQUAL "boost" OR dep MATCHES "linking") continue() endif() @@ -263,11 +271,21 @@ function(__boost_scan_dependencies lib var sub_folder) endif() endforeach() endif() + + set(component_name ${dep}) + string(REGEX REPLACE "^numeric/" "numeric_" component_name ${component_name}) + if(NOT dep STREQUAL lib) if(type STREQUAL "Exclude") list(APPEND libs_to_exclude ${dep}) + list(APPEND exclude_components ${component_name}) else() list(APPEND result ${dep}) + if(_is_optional) + list(APPEND optional_components ${component_name}) + else() + list(APPEND required_components ${component_name}) + endif() endif() endif() endforeach() @@ -280,7 +298,19 @@ function(__boost_scan_dependencies lib var sub_folder) if(libs_to_exclude) list(REMOVE_ITEM result ${libs_to_exclude}) + list(REMOVE_ITEM optional_components ${exclude_components}) + list(REMOVE_ITEM required_components ${exclude_components}) + endif() + + list(REMOVE_DUPLICATES required_components) + list(REMOVE_DUPLICATES optional_components) + list(REMOVE_ITEM required_components boost ${lib}) + if(required_components OR optional_components) + message(STATUS "boost required: " ${required_components}) + message(STATUS "boost optional: " ${optional_components}) + find_package(Boost COMPONENTS ${required_components} OPTIONAL_COMPONENTS ${optional_components} REQUIRED CONFIG) endif() + list(REMOVE_DUPLICATES result) set(${var} ${result} PARENT_SCOPE) @@ -552,33 +582,3 @@ if(CMAKE_SKIP_INSTALL_RULES) return() endif() - -set(CONFIG_INSTALL_DIR "${BOOST_INSTALL_CMAKEDIR}/Boost-${BOOST_SUPERPROJECT_VERSION}") -set(CONFIG_FILE_NAME "${CMAKE_CURRENT_LIST_DIR}/../config/BoostConfig.cmake") - -install(FILES "${CONFIG_FILE_NAME}" DESTINATION "${CONFIG_INSTALL_DIR}") - -set(CONFIG_VERSION_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/tmpinst/BoostConfigVersion.cmake") - -if(NOT CMAKE_VERSION VERSION_LESS 3.14) - - write_basic_package_version_file("${CONFIG_VERSION_FILE_NAME}" COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT) - -else() - - set(OLD_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) - set(CMAKE_SIZEOF_VOID_P "") - - write_basic_package_version_file("${CONFIG_VERSION_FILE_NAME}" COMPATIBILITY SameMajorVersion) - - set(CMAKE_SIZEOF_VOID_P ${OLD_CMAKE_SIZEOF_VOID_P}) - -endif() - -install(FILES "${CONFIG_VERSION_FILE_NAME}" DESTINATION "${CONFIG_INSTALL_DIR}") - -set(CPACK_PACKAGE_VENDOR "Boost") -set(CPACK_GENERATOR "TGZ") -set(CPACK_RESOURCE_FILE_LICENSE "${Boost_SOURCE_DIR}/LICENSE_1_0.txt") -set(CPACK_RESOURCE_FILE_README "${Boost_SOURCE_DIR}/README.md") -include(CPack)