boostorg / cmake

CMake support infrastructure Boost submodule
87 stars 26 forks source link

Building folly with cmake fails with boost 1.85-cmake tarball #66

Closed soro closed 3 months ago

soro commented 3 months ago

Hi, I have been trying to build folly with cmake via the bazel package rules_foreign_cc. Boost does build fine, and the files get copied and paths set up correctly, but the configure step fails to discover boost_assert while trying to configure boost_context.

Here are error and call stack:

-- setting C++ standard to C++17
-- Found Boost 1.85.0 at /home/dev/.cache/bazel/_bazel_dev/15902ddbe5afade2111503033c667920/sandbox/processwrapper-sandbox/28/execroot/cpp/bazel-out/k8-fastbuild/bin/external/com_github_facebook_folly/facebook_folly.ext_build_deps/boost/lib/cmake/Boost-1.85.0
--   Requested configuration: QUIET REQUIRED COMPONENTS context;filesystem;program_options;regex;system;thread
-- BoostConfig: find_package(boost_headers 1.85.0 EXACT CONFIG REQUIRED QUIET HINTS /home/dev/.cache/bazel/_bazel_dev/15902ddbe5afade2111503033c667920/sandbox/processwrapper-sandbox/28/execroot/cpp/bazel-out/k8-fastbuild/bin/external/com_github_facebook_folly/facebook_folly.ext_build_deps/boost/lib/cmake)
-- BoostConfig: find_package(boost_context 1.85.0 EXACT CONFIG REQUIRED QUIET HINTS /home/dev/.cache/bazel/_bazel_dev/15902ddbe5afade2111503033c667920/sandbox/processwrapper-sandbox/28/execroot/cpp/bazel-out/k8-fastbuild/bin/external/com_github_facebook_folly/facebook_folly.ext_build_deps/boost/lib/cmake)
CMake Error at /usr/share/cmake-3.18/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
  By not providing "Findboost_assert.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "boost_assert", but CMake did not find one.

  Could not find a package configuration file provided by "boost_assert"
  (requested version 1.85.0) with any of the following names:

    boost_assertConfig.cmake
    boost_assert-config.cmake

  Add the installation prefix of "boost_assert" to CMAKE_PREFIX_PATH or set
  "boost_assert_DIR" to a directory containing one of the above files.  If
  "boost_assert" provides a separate development package or SDK, be sure it
  has been installed.
Call Stack (most recent call first):
  /home/dev/.cache/bazel/_bazel_dev/15902ddbe5afade2111503033c667920/sandbox/processwrapper-sandbox/28/execroot/cpp/bazel-out/k8-fastbuild/bin/external/com_github_facebook_folly/facebook_folly.ext_build_deps/boost/lib/cmake/boost_context-1.85.0/boost_context-config.cmake:6 (find_dependency)
  /home/dev/.cache/bazel/_bazel_dev/15902ddbe5afade2111503033c667920/sandbox/processwrapper-sandbox/28/execroot/cpp/bazel-out/k8-fastbuild/bin/external/com_github_facebook_folly/facebook_folly.ext_build_deps/boost/lib/cmake/Boost-1.85.0/BoostConfig.cmake:67 (find_package)
  /home/dev/.cache/bazel/_bazel_dev/15902ddbe5afade2111503033c667920/sandbox/processwrapper-sandbox/28/execroot/cpp/bazel-out/k8-fastbuild/bin/external/com_github_facebook_folly/facebook_folly.ext_build_deps/boost/lib/cmake/Boost-1.85.0/BoostConfig.cmake:128 (boostcfg_find_component)
  /usr/share/cmake-3.18/Modules/FindBoost.cmake:448 (find_package)

Notably, it does look like the header cmake config is found correctly, and the path set. This is what is generated for boost_context-config.cmake:

# Generated by BoostInstall.cmake for boost_context-1.85.0

include(CMakeFindDependencyMacro)

if(NOT boost_assert_FOUND)
  find_dependency(boost_assert 1.85.0 EXACT)
endif()
if(NOT boost_config_FOUND)
  find_dependency(boost_config 1.85.0 EXACT)
endif()
if(NOT boost_core_FOUND)
  find_dependency(boost_core 1.85.0 EXACT)
endif()
if(NOT boost_mp11_FOUND)
  find_dependency(boost_mp11 1.85.0 EXACT)
endif()
if(NOT boost_pool_FOUND)
  find_dependency(boost_pool 1.85.0 EXACT)
endif()
if(NOT boost_predef_FOUND)
  find_dependency(boost_predef 1.85.0 EXACT)
endif()
if(NOT boost_smart_ptr_FOUND)
  find_dependency(boost_smart_ptr 1.85.0 EXACT)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/boost_context-targets.cmake")

It seems that these find_dependency calls aren't passed the correct directory hints?

I notice that in boostcfg_find_component, the hint is explicitly set as

  find_package(boost_${__boost_comp_nv} ${Boost_VERSION} EXACT CONFIG ${_BOOST_REQUIRED} ${_BOOST_QUIET} HINTS ${_BOOST_CMAKEDIR})

Any advice for further investigation? Superficially, everything looks like it is set up correctly. The files are all there, directory structure looks fine:

~/.cache/bazel/_bazel_dev/15902ddbe5afade2111503033c667920/sandbox/processwrapper-sandbox/26/execroot/cpp/bazel-out/k8-fastbuild/bin/external/com_github_facebook_folly/facebook_folly.ext_build_deps/boost/lib$ ls -1a
cmake
libboost_atomic.a
libboost_charconv.a
libboost_chrono.a
libboost_cobalt.a
libboost_container.a
libboost_context.a
libboost_contract.a
libboost_coroutine.a
libboost_date_time.a
libboost_exception.a
libboost_fiber.a
libboost_fiber_numa.a
libboost_filesystem.a
libboost_graph.a
libboost_iostreams.a
libboost_json.a
libboost_locale.a
libboost_log.a
libboost_log_setup.a
libboost_nowide.a
libboost_program_options.a
libboost_random.a
libboost_serialization.a
libboost_stacktrace_addr2line.a
libboost_stacktrace_basic.a
libboost_stacktrace_noop.a
libboost_thread.a
libboost_timer.a
libboost_type_erasure.a
libboost_url.a
libboost_wave.a
libboost_wserialization.a

cmake dir:

~/.cache/bazel/_bazel_dev/15902ddbe5afade2111503033c667920/sandbox/processwrapper-sandbox/26/execroot/cpp/bazel-out/k8-fastbuild/bin/external/com_github_facebook_folly/facebook_folly.ext_build_deps/boost/lib/cmake$ ls -1a
Boost-1.85.0
boost_accumulators-1.85.0
boost_algorithm-1.85.0
boost_align-1.85.0
boost_any-1.85.0
boost_array-1.85.0
boost_asio-1.85.0
boost_assert-1.85.0
boost_assign-1.85.0
boost_atomic-1.85.0
boost_beast-1.85.0
boost_bimap-1.85.0
boost_bind-1.85.0
...[snip]

boost_assert-1.85.0 dir:

ls boost_assert-1.85.0
boost_assert-config.cmake  boost_assert-config-version.cmake  boost_assert-targets.cmake

I don't think this is due to incorrect copying of the cmake build output of boost? Can this be made more robust?

pdimov commented 3 months ago

How does the "root" find_package(Boost) find the appropriate lib/cmake directory with Boost-1.85.0 in it, but the nested find_dependency calls do not? Where is it issued?

I suppose we could change

if(NOT boost_assert_FOUND)
  find_dependency(boost_assert 1.85.0 EXACT)
endif()

to

if(NOT boost_assert_FOUND)
  find_dependency(boost_assert 1.85.0 EXACT HINTS "${CMAKE_CURRENT_LIST_DIR}/..")
endif()

(or should that be ../../..?)

One potential problem with that is that find_dependency only allows arguments different from version and EXACT starting from CMake 3.9, although I'm not sure that anyone will object to that; a CMake-installed Boost is a relatively new phenomenon so its users will probably be on 3.9 or newer.

pdimov commented 3 months ago

If you want to experiment with that locally, the line to change is

https://github.com/boostorg/cmake/blob/c9987a6d4191ec6683dcc153a9480211252e21b8/include/BoostInstall.cmake#L346

soro commented 3 months ago

Will give that a try and report back when I get a chance, thanks

soro commented 3 months ago

That change did indeed fix the build (adding HINTS "${CMAKE_CURRENT_LIST_DIR}/.."). Would it be a problem to make this change?

pdimov commented 3 months ago

Would you like to make a pull request?

soro commented 3 months ago

Sure, I can do that later today