Skip to content

Commit

Permalink
Merge pull request #169 from ValeevGroup/evaleev/feature/modularized-…
Browse files Browse the repository at this point in the history
…boost

modularized Boost
  • Loading branch information
evaleev authored Jan 19, 2024
2 parents bf0c376 + 960dd07 commit 86e4a21
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: |
sudo apt-get update
sudo apt-get install ninja-build g++-9 liblapack-dev libboost-dev libboost-serialization-dev libeigen3-dev openmpi-bin libopenmpi-dev libtbb-dev ccache
sudo apt-get install ninja-build g++-9 liblapack-dev libboost-dev libboost-serialization-dev libboost-random-dev libeigen3-dev openmpi-bin libopenmpi-dev libtbb-dev ccache
if [ "${{matrix.build_type}}" = "Release" ]; then
sudo apt-get install libclang1-9 libclang-cpp9 graphviz fonts-liberation
cd ${{github.workspace}}/build
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,11 @@ add_custom_target_subproject(btas install-config
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=btas-config -P ${PROJECT_BINARY_DIR}/cmake_install.cmake
COMMENT "Installing BTAS config components")

feature_summary(WHAT ALL
DESCRIPTION "=== BTAS Package/Feature Info ===")
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
feature_summary(WHAT ALL
DESCRIPTION "=== BTAS Package/Feature Info ===")
feature_summary(FILENAME ${CMAKE_CURRENT_BINARY_DIR}/features.log WHAT ALL)
endif()

###############################################################################
# appendix: misc details
Expand Down
39 changes: 1 addition & 38 deletions cmake/btas-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,7 @@ set(BTAS_EXT_VERSION "@BTAS_EXT_VERSION@")

@PACKAGE_INIT@

# import boost components, if any missing
set(Boost_BTAS_DEPS_LIBRARIES @Boost_BTAS_DEPS_LIBRARIES@)
foreach(_deplib ${Boost_BTAS_DEPS_LIBRARIES})
if (DEFINED Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK)
list(APPEND Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK OR)
endif()
list(APPEND Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK "NOT;TARGET;Boost::${_deplib}")
endforeach(_deplib)
if (NOT DEFINED Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK)
list(APPEND Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK "NOT;TARGET;Boost::boost")
endif (NOT DEFINED Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK)

if(${Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK})
set(Boost_USE_CONFIG @Boost_USE_CONFIG@)
# OPTIONAL_COMPONENTS in FindBoost available since 3.11
cmake_minimum_required(VERSION 3.11.0)
if (Boost_USE_CONFIG)
set(Boost_CONFIG @Boost_CONFIG@)
if (NOT Boost_CONFIG OR NOT EXISTS ${Boost_CONFIG})
message(FATAL_ERROR "Expected Boost config file at ${Boost_CONFIG}; directory moved since BTAS configuration?")
endif()
get_filename_component(Boost_DIR ${Boost_CONFIG} DIRECTORY)
find_package(Boost CONFIG QUIET REQUIRED OPTIONAL_COMPONENTS ${Boost_BTAS_DEPS_LIBRARIES} PATHS ${Boost_DIR} NO_DEFAULT_PATH)
else (Boost_USE_CONFIG)
set(BOOST_INCLUDEDIR @Boost_INCLUDE_DIR@)
set(BOOST_LIBRARYDIR @Boost_LIBRARY_DIR_RELEASE@)
if (NOT BOOST_LIBRARYDIR OR NOT EXISTS ${BOOST_LIBRARYDIR})
set(BOOST_LIBRARYDIR @Boost_LIBRARY_DIR_DEBUG@)
endif()
set(Boost_NO_SYSTEM_PATHS OFF)
if (BOOST_LIBRARYDIR AND BOOST_INCLUDEDIR)
if (EXISTS ${BOOST_LIBRARYDIR} AND EXISTS ${BOOST_INCLUDEDIR})
set(Boost_NO_SYSTEM_PATHS ON)
endif()
endif()
find_package(Boost QUIET REQUIRED OPTIONAL_COMPONENTS ${Boost_BTAS_DEPS_LIBRARIES})
endif (Boost_USE_CONFIG)
endif(${Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK})
@Boost_CONFIG_FILE_CONTENTS@

# find linalgpp dependencies
if(NOT TARGET blaspp)
Expand Down
25 changes: 0 additions & 25 deletions cmake/modules/FindOrFetchBoost.cmake

This file was deleted.

84 changes: 31 additions & 53 deletions external/boost.cmake
Original file line number Diff line number Diff line change
@@ -1,63 +1,41 @@
# -*- mode: cmake -*-

# Limit scope of the search if BOOST_ROOT or BOOST_INCLUDEDIR is provided.
if (BOOST_ROOT OR BOOST_INCLUDEDIR)
set(Boost_NO_SYSTEM_PATHS TRUE)
endif()

# make sure Boost::boost is available, and look for optional serialization component
if (NOT TARGET Boost::boost OR NOT TARGET Boost::serialization)
list(APPEND Boost_BTAS_DEPS_LIBRARIES serialization)

# detect which Boost targets I already have
foreach(tgt boost;headers;${Boost_BTAS_DEPS_LIBRARIES})
if (TARGET Boost::${tgt})
set(btas_imported_boost_${tgt} 0)
else()
set(btas_imported_boost_${tgt} 1)
endif()
endforeach()

# try config first
# OPTIONAL_COMPONENTS in FindBoost available since 3.11
cmake_minimum_required(VERSION 3.11.0)
find_package(Boost ${BTAS_TRACKED_BOOST_VERSION} CONFIG OPTIONAL_COMPONENTS ${Boost_BTAS_DEPS_LIBRARIES})
if (NOT TARGET Boost::boost)
find_package(Boost ${BTAS_TRACKED_BOOST_VERSION} OPTIONAL_COMPONENTS ${Boost_BTAS_DEPS_LIBRARIES})
if (TARGET Boost::boost)
set(Boost_USE_CONFIG FALSE)
endif(TARGET Boost::boost)
# Boost can be discovered by every (sub)package but only the top package can build it ...
# if we are the top package need to include the list of Boost components to be built
if("${CMAKE_PROJECT_NAME}" STREQUAL "${PROJECT_NAME}")
set(required_components
headers # BTAS
container # BTAS
iterator # BTAS
random # BTAS
)
if (DEFINED Boost_REQUIRED_COMPONENTS)
list(APPEND Boost_REQUIRED_COMPONENTS ${required_components})
list(REMOVE_DUPLICATES Boost_REQUIRED_COMPONENTS)
else()
set(Boost_USE_CONFIG TRUE)
set(Boost_REQUIRED_COMPONENTS "${required_components}" CACHE STRING "Required components of Boost to discovered or built")
endif()
set(optional_components
serialization # BTAS
)
if (DEFINED Boost_OPTIONAL_COMPONENTS)
list(APPEND Boost_OPTIONAL_COMPONENTS ${optional_components})
list(REMOVE_DUPLICATES Boost_OPTIONAL_COMPONENTS)
else()
set(Boost_OPTIONAL_COMPONENTS "${optional_components}" CACHE STRING "Optional components of Boost to discovered or built")
endif()
endif()

# Boost::* targets by default are not GLOBAL, so to allow users of LINALG_LIBRARIES to safely use them we need to make them global
# more discussion here: https://gitlab.kitware.com/cmake/cmake/-/issues/17256
foreach(tgt boost;headers;${Boost_BTAS_DEPS_LIBRARIES})
if (TARGET Boost::${tgt} AND btas_imported_boost_${tgt})
get_target_property(_boost_tgt_${tgt}_is_imported_global Boost::${tgt} IMPORTED_GLOBAL)
if (NOT _boost_tgt_${tgt}_is_imported_global)
set_target_properties(Boost::${tgt} PROPERTIES IMPORTED_GLOBAL TRUE)
endif()
unset(_boost_tgt_${tgt}_is_imported_global)
endif()
endforeach()

endif (NOT TARGET Boost::boost OR NOT TARGET Boost::serialization)

# if Boost not found, and BTAS_BUILD_DEPS_FROM_SOURCE=ON, use FetchContent to build it
set(BTAS_BUILT_BOOST_FROM_SOURCE 0)
if (NOT TARGET Boost::boost)
if (BTAS_BUILD_DEPS_FROM_SOURCE)
include(${PROJECT_SOURCE_DIR}/cmake/modules/FindOrFetchBoost.cmake)
set(BTAS_BUILT_BOOST_FROM_SOURCE 1)
else(BTAS_BUILD_DEPS_FROM_SOURCE)
message(FATAL_ERROR "Boost is a required prerequisite of BTAS, but not found; install Boost or set BTAS_BUILD_DEPS_FROM_SOURCE=ON to obtain from source")
endif(BTAS_BUILD_DEPS_FROM_SOURCE)
endif (NOT TARGET Boost::boost)
if (BTAS_BUILD_DEPS_FROM_SOURCE AND NOT DEFINED Boost_FETCH_IF_MISSING)
set(Boost_FETCH_IF_MISSING 1)
endif()
include(${vg_cmake_kit_SOURCE_DIR}/modules/FindOrFetchBoost.cmake)
if (DEFINED Boost_SOURCE_DIR)
set(BTAS_BUILT_BOOST_FROM_SOURCE 1)
endif()

# make BTAS depend on Boost
set(Boost_LIBRARIES Boost::boost)
set(Boost_LIBRARIES Boost::headers;Boost::random)
if (TARGET Boost::serialization)
list(APPEND Boost_LIBRARIES Boost::serialization)
target_compile_definitions(BTAS INTERFACE -DBTAS_HAS_BOOST_SERIALIZATION=1)
Expand Down
2 changes: 1 addition & 1 deletion external/versions.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(BTAS_TRACKED_VGCMAKEKIT_TAG d6746098e63deab4032309c4455bb084a17ff51a)
set(BTAS_TRACKED_VGCMAKEKIT_TAG 8713beb71ff6b7d4b1c758e9e1c7d814bd97b0af)

# likely can use earlier, but
# - as of oct 2023 tested with 1.71 and up only
Expand Down

0 comments on commit 86e4a21

Please sign in to comment.