stlab / libraries

ASL libraries will be migrated here in the stlab namespace, new libraries will be created here.
https://stlab.cc
Boost Software License 1.0
660 stars 65 forks source link

Upgrade to 1.7.1 now requires Qt and Boost #508

Closed mnesarco closed 1 year ago

mnesarco commented 1 year ago

Hello Friends, I have a project using 1.6.2, I am not using Qt at all. I tried to upgrade it to 1.7.1 today and apparently Qt5 is now required and also Boost.


[cmake] -- Could NOT find Boost (missing: Boost_INCLUDE_DIR) (Required is at least version "1.74.0")
[cmake] -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
[cmake] -- Could NOT find libdispatch (missing: libdispatch_LIBRARY libdispatch_INCLUDE_DIR) 
[cmake] CMake Warning at 3rdparty/stlab/CMakeLists.txt:13 (find_package):
[cmake]   By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
[cmake]   asked CMake to find a package configuration file provided by "Qt6", but
[cmake]   CMake did not find one.
[cmake] 
[cmake]   Could not find a package configuration file provided by "Qt6" with any of
[cmake]   the following names:
[cmake] 
[cmake]     Qt6Config.cmake
[cmake]     qt6-config.cmake
[cmake] 
[cmake]   Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
[cmake]   to a directory containing one of the above files.  If "Qt6" provides a
[cmake]   separate development package or SDK, be sure it has been installed.
[cmake] 
[cmake] 
[cmake] -- Performing Test STLAB_HAVE_FUNCTIONAL_VARIANT_OPTIONAL
[cmake] -- Performing Test STLAB_HAVE_FUNCTIONAL_VARIANT_OPTIONAL - Success
[cmake] -- Performing Test STLAB_HAVE_FUNCTIONAL_COROUTINES
[cmake] -- Performing Test STLAB_HAVE_FUNCTIONAL_COROUTINES - Success
[cmake] -- Could NOT find libdispatch (missing: libdispatch_LIBRARY libdispatch_INCLUDE_DIR) 
[cmake] -- Could NOT find libdispatch (missing: libdispatch_LIBRARY libdispatch_INCLUDE_DIR) 
[cmake] CMake Error at 3rdparty/stlab/CMakeLists.txt:33 (message):
[cmake]   BUILD_TESTING is enabled, but an installation of Boost.Test was not found.
[cmake] 
[cmake] 
[cmake] CMake Error: File /home/mnesarco/devel/projects/Marz/marzd4/stlab/config.hpp.in does not exist.
[cmake] CMake Error at 3rdparty/stlab/cmake/StlabUtil.cmake:203 (configure_file):
[cmake]   configure_file Problem configuring file
[cmake] Call Stack (most recent call first):
[cmake]   3rdparty/stlab/stlab/CMakeLists.txt:44 (stlab_generate_config_file)
[cmake] 
[cmake] 
[cmake] -- stlab: Use Boost C++17 Shims: OFF
[cmake] -- stlab: Disable Coroutines: FALSE
[cmake] -- stlab: Thread System: pthread
[cmake] -- stlab: Task System: portable
[cmake] -- stlab: Main Executor: none

How can I avoid these new dependencies? In my cmake project I just include stlab folder:

add_subdirectory(3rdparty/stlab)

It used to work. I am very bad at cmake but I upgraded stlab before without issues just replacing the folder with a new version.

mnesarco commented 1 year ago

I love this library because it provides cancel-able, detachable, and split-able futures. But if Qt and boost are now required dependencies, I am afraid I cannot use it anymore and there are no alternatives :( Very sad.

sean-parent commented 1 year ago

The requirements have not changed. Boost is required if you are building the tests (which use boost test) or if you require boost optional/variant (because you don't have C++17). QT is optional if you are trying to use the QT schedulers.

cmake is only being used to generate the config.hpp if you are not building tests file (you can also provide one manually). What is your cmake command? To test I just uninstalled boost and tried this:

cmake -S . -B ../builds/noboost -DCMAKE_CXX_STANDARD=17 -DBUILD_TESTING=OFF

And it worked fine.

mnesarco commented 1 year ago

Hi @sean-parent thank you for looking into this. I can build the lib appart and it works if BUILD_TESTING=OFF, but in my project I am using the lib with add_subdirectory(3rdparty/stlab) and I don´t want to set BUILD_TESTING=OFF for the whole project. Is there a way to disable tests only for stlab? something like STLAB_BUILD_TESTING=OFF ?

mnesarco commented 1 year ago

Even with BUILD_TESTING=OFF it does not work with add_subdirectory(3rdparty/stlab)

[cmake] CMake Error: File /xxx/stlab/config.hpp.in does not exist.
[cmake] CMake Error at 3rdparty/stlab/cmake/StlabUtil.cmake:203 (configure_file):
[cmake]   configure_file Problem configuring file
[cmake] Call Stack (most recent call first):
[cmake]   3rdparty/stlab/stlab/CMakeLists.txt:44 (stlab_generate_config_file)

It works out of the box with 1.6.2

mnesarco commented 1 year ago

Special treatment for add_subdirectory was present in 1.6.2's CMakeLists.txt

https://github.com/stlab/libraries/blob/0a7232a4120c2daf8ddb6621ec13f313a029e495/CMakeLists.txt#L32

But it was removed in 1.7.1 Maybe it is related.

sean-parent commented 1 year ago

@camio Issue may be fixed by recent PR? Can you take a look?

mnesarco commented 1 year ago

Issue is present in main branch

mnesarco commented 1 year ago

Oh something was merged some minutes ago. I will retry.

mnesarco commented 1 year ago

Ok https://github.com/stlab/libraries/commit/9a75c3decbb12fca58c996be604a03b8184fc332 fixed the build. Thank you @laserallan @camio

BUILD_TESTING=OFF is still required to avoid boost, the former option to disable tests was definitively removed. so basically now it is all or nothing.

Another strange thing is this error on program termination (in 1.7.1 not present in 1.6.2):

libc++abi: terminating
Aborted (core dumped)
mnesarco commented 1 year ago

The termination exception is from priority_task_system destructor:

    ~priority_task_system() {
        assert(_q.empty() && "stlab: Thread pool not joined prior to destruction.");
    }

Is there any lifecycle management required in 1.7.1 that was not required in 1.6.2?

mnesarco commented 1 year ago

Termination exception solved by calling stlab::pre_exit(); before returning from main. I am sorry, it was clearly specified in CHANGES.md 🤦🏼‍♂️

camio commented 1 year ago

Is there a way to disable tests only for stlab?

Setting BUILD_TESTING=OFF before calling add_subdirectory should work I believe.

mnesarco commented 1 year ago

BUILD_TESTING=OFF affects other subprojects. I only want to disable tests of stlab to avoid boost dependency. A possible solution: https://github.com/stlab/libraries/pull/509 ?

camio commented 1 year ago

See the set documentation. As long as the variable isn't a CACHE variable, which it shouldn't be, then set will apply only to the current directory scope and not impact other parts of your project.

So if you keep your stuff in 3rdparty, 3rdparty/CMakeLists.txt would look like this:

set(BUILD_TESTING OFF)
add_subdirectory(stlab)
# ...
mnesarco commented 1 year ago
# set(BUILD_TESTING OFF)  <--- affects all below
add_subdirectory(3rdparty/stlab)
add_subdirectory(3rdparty/imgui)
add_subdirectory(3rdparty/sqlite3)
add_subdirectory(3rdparty/nlohmann/json)
add_subdirectory(3rdparty/stb)
add_subdirectory(3rdparty/rapidxml_ns)
add_subdirectory(3rdparty/tigl-partial)

What you are proposing is something like this?:

set(BUILD_TESTING OFF)
add_subdirectory(3rdparty/stlab)
set(BUILD_TESTING ON)

add_subdirectory(3rdparty/imgui)
add_subdirectory(3rdparty/sqlite3)
add_subdirectory(3rdparty/nlohmann/json)
add_subdirectory(3rdparty/stb)
add_subdirectory(3rdparty/rapidxml_ns)
add_subdirectory(3rdparty/tigl-partial)
camio commented 1 year ago

I was assuming you don't want to enable testing for any of your 3rdparty libraries. If you only want to disable it for stlab then your second snippet looks right.

mnesarco commented 1 year ago

Those are only part of the 3rdparty submodules, others are own projects but included as 3rdparty in this specific project and some of them need to run tests that depend on config.

I will try the second snipped. Thank your for the info.

mnesarco commented 1 year ago

@camio It worked. Thank you, I am sorry for all the noise.

For reference:

set(GLOBAL_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING OFF)

add_subdirectory(3rdparty/stlab)

set(BUILD_TESTING ${GLOBAL_BUILD_TESTING})
unset(GLOBAL_BUILD_TESTING)
camio commented 1 year ago

FWIW I think that can be simplified to this:

block()
  set(BUILD_TESTING OFF)
  add_subdirectory(3rdparty/stlab)
endblock()
mnesarco commented 1 year ago

block() looks good, but it requires cmake 3.25.