Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static deal.II (Windows) cannot be configured with external shared Boost #16447

Open
vdilecce opened this issue Jan 10, 2024 · 9 comments
Open

Comments

@vdilecce
Copy link

vdilecce commented Jan 10, 2024

The following was tested with:

  • Windows 10
  • Visual Studio 2022
  • Boost 1.82
  • Deal.II 9.5.1
  • CMake 3.27.9

Boost

I configured, built, and installed Boost 1.82 as follows:

# STATIC

.\bootstrap.bat

.\b2 --prefix="C:\sw\boost\msvc-2022\1.82.0-static" --build-dir=.\build-static --layout=versioned --abbreviate-paths --hash --without-python --without-graph_parallel --without-mpi --without-stacktrace toolset=msvc-14.3 link=static runtime-link=static,shared variant=debug,release architecture=x86 address-model=64 cxxstd=17 cxxstd-dialect=ms install
# SHARED

.\bootstrap.bat

.\b2 --prefix="C:\sw\boost\msvc-2022\1.82.0-shared" --build-dir=.\build-shared --layout=versioned --abbreviate-paths --hash --without-python --without-graph_parallel --without-mpi --without-stacktrace toolset=msvc-14.3 link=shared runtime-link=shared variant=debug,release architecture=x86 address-model=64 cxxstd=17 cxxstd-dialect=ms install

deal.II

When deal.II is configured on Windows, BUILD_SHARED_LIBS is forced to OFF for size reasons.

In this scenario, in cmake/modules/FindDEAL_II_BOOST.cmake (cmake/modules/FindBOOST.cmake in deal.II 9.4) Boost_USE_STATIC_LIBS is first set to TRUE (i.e., search for Boost static); if Boost is not found, it is then set to FALSE (i.e., search for Boost shared).

I configured deal.II 9.5.1 with Boost SHARED as follows:

cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 -DCMAKE_INSTALL_PREFIX=C:/sw/dealii/msvc-2022/9.5.1 -DDEAL_II_CXX_FLAGS="/std:c++17" -DDEAL_II_ALLOW_AUTODETECTION=OFF -DBOOST_DIR=C:/sw/boost/msvc-2022/1.82.0-shared -DBoost_USE_STATIC_RUNTIME=OFF -DBoost_ARCHITECTURE=-x64 -DDEAL_II_WITH_TBB=OFF -S . -B build

In the output, I got the following:

-- Include C:/sw-dev/src/dealii-9.5.1/cmake/configure/configure_20_boost.cmake
-- Could NOT find Boost (missing: serialization system thread) (found suitable version "1.82.0", minimum required is "1.59")
-- Could NOT find Boost (missing: serialization system thread) (found suitable version "1.82.0", minimum required is "1.59")
-- Processing BOOST variables and targets
--   BOOST_LIBRARIES: *** Required variable "Boost_LIBRARIES" empty ***
-- Unable to process BOOST
-- DEAL_II_WITH_BOOST has unmet external dependencies.
-- Performing Test DEAL_II_HAVE_FLAG_Wno_unused_local_typedefs
-- Performing Test DEAL_II_HAVE_FLAG_Wno_unused_local_typedefs - Failed
-- DEAL_II_WITH_BOOST successfully set up with bundled packages.

and deal.II ended up configured with the bundled Boost.

I tried configuring deal.II with an external Boost STATIC and it picked it up correctly:

cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 -DCMAKE_INSTALL_PREFIX=C:/sw/dealii/msvc-2022/9.5.1 -DDEAL_II_CXX_FLAGS="/std:c++17" -DDEAL_II_ALLOW_AUTODETECTION=OFF -DBOOST_DIR=C:/sw/boost/msvc-2022/1.82.0-static -DBoost_USE_STATIC_RUNTIME=OFF -DBoost_ARCHITECTURE=-x64 -DDEAL_II_WITH_TBB=OFF -S . -B build

Is there a way to configure deal.II on Windows with an external shared Boost?

@tamiko
Copy link
Member

tamiko commented Jan 10, 2024

The (second) message

-- Could NOT find Boost (missing: serialization system thread) (found suitable version "1.82.0", minimum required is "1.59")

indicates that the CMake internal boost configuration thinks that neither the serialization, system, nor thread components are available in your boost packages. Can you check that they are indeed properly installed.

Secondly, just as a sanity check, would you mind to configure with
-DCMAKE_PREFIX_PATH="C:/sw/boost/msvc-2022/1.82.0-static;C:/sw/boost/msvc-2022/1.82.0-static" instead of BOOST_DIR=` and see what happens?

@tamiko
Copy link
Member

tamiko commented Jan 10, 2024

@vdilecce A quick question: Do you need to develop a native Windows application based on deal.II or do you just want to develop and use deal.II on Windows? If the latter, we had great success with VSCODE and an Ubuntu in WSL in the past. (I recommend this approach to all students with a Windows laptop when I teach a scientific computing course with deal.II).

@vdilecce
Copy link
Author

Scenario is native Windows application using both deal.II and Boost.

Test 1

-DCMAKE_PREFIX_PATH=C:/sw/boost/msvc-2022/1.82.0-shared:

Did not work (fallback to bundled Boost).

Test 2

-DCMAKE_PREFIX_PATH="C:/sw/boost/msvc-2022/1.82.0-static;C:/sw/boost/msvc-2022/1.82.0-shared"
or
-DCMAKE_PREFIX_PATH="C:/sw/boost/msvc-2022/1.82.0-shared;C:/sw/boost/msvc-2022/1.82.0-static":

-- Defining target: interface_boost
--     VERSION:             1.82.0
--     LINK_LIBRARIES:      C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_serialization-vc143-mt-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_serialization-vc143-mt-gd-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_system-vc143-mt-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_system-vc143-mt-gd-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_thread-vc143-mt-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_thread-vc143-mt-gd-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_chrono-vc143-mt-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_chrono-vc143-mt-gd-x64-1_82.lib;optimized;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_atomic-vc143-mt-x64-1_82.lib;debug;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_atomic-vc143-mt-gd-x64-1_82.lib
--     INCLUDE_DIRECTORIES: C:/sw/boost/msvc-2022/1.82.0-shared/include/boost-1_82
--
-- DEAL_II_WITH_BOOST successfully set up with external dependencies.

Weirdly, the latter picked libraries from the static Boost, but includes from the shared Boost.

@tamiko
Copy link
Member

tamiko commented Jan 12, 2024

@vdilecce Did it compile?

@marcfehling marcfehling added this to the Release 9.6 milestone Feb 11, 2024
@vdilecce
Copy link
Author

I put testing on hold because of #16413 (comment)

@vdilecce
Copy link
Author

I can provide some updates with Boost 1.82 for now (deal.II's current master branch).

Configure command (I set CMAKE_PREFIX_PATH to both shared and static Boost, in this order):

cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 -DCMAKE_INSTALL_PREFIX=C:/sw/dealii/msvc-2022/master -DDEAL_II_CXX_FLAGS="/std:c++17" -DDEAL_II_ALLOW_AUTODETECTION=OFF -DCMAKE_PREFIX_PATH="C:/sw/boost/msvc-2022/1.82.0-shared;C:/sw/boost/msvc-2022/1.82.0-static" -DBoost_USE_STATIC_RUNTIME=OFF -DBoost_ARCHITECTURE=-x64 -DDEAL_II_WITH_TBB=OFF -DDEAL_II_FORCE_BUNDLED_KOKKOS=ON -S . -B build

Link libraries are from the static Boost, whereas includes are from the shared Boost:

-- Include C:/sw-dev/src/dealii-master/cmake/configure/configure_20_boost.cmake
-- Found Boost: C:/sw/boost/msvc-2022/1.82.0-shared/include/boost-1_82 (found suitable version "1.82.0", minimum required is "1.59") found components: serialization system thread chrono atomic
-- Processing BOOST variables and targets
-- Processing BOOST variables and targets - Done
-- Performing Test DEAL_II_HAVE_FLAG_Wno_unused_local_typedefs
-- Performing Test DEAL_II_HAVE_FLAG_Wno_unused_local_typedefs - Failed
-- Performing Test DEAL_II_BOOST_HAS_BROKEN_HEADER_DEPRECATIONS_OK
-- Performing Test DEAL_II_BOOST_HAS_BROKEN_HEADER_DEPRECATIONS_OK - Success
-- Test successful, do not define DEAL_II_BOOST_HAS_BROKEN_HEADER_DEPRECATIONS

-- Defining target: interface_boost_debug
--     VERSION:             1.82.0
--     LINK_LIBRARIES:      C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_serialization-vc143-mt-gd-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_system-vc143-mt-gd-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_thread-vc143-mt-gd-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_chrono-vc143-mt-gd-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_atomic-vc143-mt-gd-x64-1_82.lib
--     INCLUDE_DIRECTORIES: C:/sw/boost/msvc-2022/1.82.0-shared/include/boost-1_82
--
-- Defining target: interface_boost_release
--     VERSION:             1.82.0
--     LINK_LIBRARIES:      C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_serialization-vc143-mt-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_system-vc143-mt-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_thread-vc143-mt-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_chrono-vc143-mt-x64-1_82.lib;C:/sw/boost/msvc-2022/1.82.0-static/lib/libboost_atomic-vc143-mt-x64-1_82.lib
--     INCLUDE_DIRECTORIES: C:/sw/boost/msvc-2022/1.82.0-shared/include/boost-1_82

NOTE: if I replace CMAKE_PREFIX_PATH with BOOST_DIR in the configuration command, even the includes are from the static Boost.

It seems like deal.II initially finds the shared Boost, but then some tests fail, it resorts to the static Boost (for which tests succeed), and thus above result.

NOTE: I tried adding the Boost DLLs to the PATH but it didn't work.

I didn't try compiling deal.II since it will just link to the static Boost, which is not what I am trying to achieve.

@vdilecce
Copy link
Author

I found the problem! It is in file cmake/modules/FindDEAL_II_BOOST.cmake.

find_package(Boost) is called a first time at line 57/61. CMake's FindBoost.cmake module considers variable Boost_LIB_PREFIX as it is set (or unset) when the module is called (see source). Either way, after the module has been called once, Boost_LIB_PREFIX is set (if it was initially unset it is set through an introspection).

If find_package(Boost) is called again (which is the case for my scenario) at line 75/77, it will have Boost_LIB_PREFIX already set from the previous call, and that's potentially different from what the user wanted.

It seems that CMake's FindBoost.cmake is not meant to be called more than once subsequently, unless some solution is put in place. In FindDEAL_II_BOOST.cmake, when the if() at line 69 is entered, variable Boost_LIB_PREFIX should be restored to the state it was before the first find_package(Boost) call (say, at line 55): that is, if it was originally set it must be restored to that value, and if it was originally unset it must be unset again.

@masterleinad
Copy link
Member

n FindDEAL_II_BOOST.cmake, when the if() at line 69 is entered, variable Boost_LIB_PREFIX should be restored to the state it was before the first find_package(Boost) call (say, at line 55): that is, if it was originally set it must be restored to that value, and if it was originally unset it must be unset again.

Do you want to create a pull request that does that?

@vdilecce
Copy link
Author

I don't feel like proceeding myself, given how little I know about deal.II's CMake project (which I have never contributed to): I'd rather leave it to some other developer with better knowledge of this project.

As a side note, variable Boost_NAMESPACE should most likely be treated the same way as Boost_LIB_PREFIX too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants