Skip to content

Commit

Permalink
Add qt5 main executor and fix stlabConfig.cmake defects (#524)
Browse files Browse the repository at this point in the history
Support was added for a qt5 main executor since some users need more time to upgrade to qt6 and the complexity increase isn't high.

`stlabConfig.cmake` did not conditionally import dependencies when required by a build configuration. This was fixed as part of this work.
  • Loading branch information
touraill-adobe authored May 5, 2023
1 parent 109872d commit 7e5dc8a
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 20 deletions.
24 changes: 18 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ include( StlabUtil )

find_package( Boost 1.74.0 OPTIONAL_COMPONENTS unit_test_framework )
find_package( libdispatch )
find_package( Qt5 QUIET COMPONENTS Core )
find_package( Qt6 QUIET COMPONENTS Core )
find_package( Threads )
find_package( Qt6 COMPONENTS Core )


cmake_dependent_option( stlab.coverage
"Enable binary instrumentation to collect test coverage information in the DEBUG configuration"
Expand All @@ -27,7 +29,7 @@ stlab_detect_task_system(STLAB_DEFAULT_TASK_SYSTEM)
set(STLAB_TASK_SYSTEM ${STLAB_DEFAULT_TASK_SYSTEM} CACHE STRING "Task system to use (portable|libdispatch|windows).")

stlab_detect_main_executor(STLAB_DEFAULT_MAIN_EXECUTOR)
set(STLAB_MAIN_EXECUTOR ${STLAB_DEFAULT_MAIN_EXECUTOR} CACHE STRING "Main executor to use (qt|libdispatch|emscripten|none).")
set(STLAB_MAIN_EXECUTOR ${STLAB_DEFAULT_MAIN_EXECUTOR} CACHE STRING "Main executor to use (qt5|qt6|libdispatch|emscripten|none).")

if( BUILD_TESTING AND NOT Boost_unit_test_framework_FOUND )
message( SEND_ERROR "BUILD_TESTING is enabled, but an installation of Boost.Test was not found." )
Expand All @@ -49,8 +51,12 @@ if( (STLAB_MAIN_EXECUTOR STREQUAL "libdispatch") AND NOT libdispatch_FOUND )
message( SEND_ERROR "STLAB_MAIN_EXECUTOR is set to \"libdispatch\", but a libdispatch installation was not found." )
endif()

if( (STLAB_MAIN_EXECUTOR STREQUAL "qt") AND NOT Qt6Core_FOUND )
message( SEND_ERROR "STLAB_MAIN_EXECUTOR is set to \"qt\", but a Qt6 installation was not found." )
if( (STLAB_MAIN_EXECUTOR STREQUAL "qt5") AND NOT Qt5Core_FOUND )
message( SEND_ERROR "STLAB_MAIN_EXECUTOR is set to \"qt5\", but a Qt5 installation was not found." )
endif()

if( (STLAB_MAIN_EXECUTOR STREQUAL "qt6") AND NOT Qt6Core_FOUND )
message( SEND_ERROR "STLAB_MAIN_EXECUTOR is set to \"qt6\", but a Qt6 installation was not found." )
endif()

#
Expand Down Expand Up @@ -97,7 +103,9 @@ endif()

if (STLAB_MAIN_EXECUTOR STREQUAL "libdispatch")
target_link_libraries(stlab INTERFACE libdispatch::libdispatch)
elseif (STLAB_MAIN_EXECUTOR STREQUAL "qt")
elseif (STLAB_MAIN_EXECUTOR STREQUAL "qt5")
target_link_libraries( stlab INTERFACE Qt5::Core )
elseif (STLAB_MAIN_EXECUTOR STREQUAL "qt6")
target_link_libraries( stlab INTERFACE Qt6::Core )
endif()

Expand Down Expand Up @@ -185,8 +193,12 @@ install( EXPORT stlabTargets
# `$INSTALL_DIR/${CMAKE_INSTALL_PREFIX}` is an element of the
# `CMAKE_PREFIX_PATH` environment variable.
#
configure_file(
"${stlab_SOURCE_DIR}/cmake/stlabConfig.cmake.in"
"${stlab_BINARY_DIR}/stlabConfig.cmake"
@ONLY )
install( FILES
"${stlab_SOURCE_DIR}/cmake/stlabConfig.cmake"
"${stlab_BINARY_DIR}/stlabConfig.cmake"
"${stlab_BINARY_DIR}/stlabConfigVersion.cmake"
DESTINATION share/cmake/stlab )

Expand Down
14 changes: 9 additions & 5 deletions cmake/StlabUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,20 @@ endfunction()
# |--------------+--------------------------------------------|
# | libdispatch | libdispatch (aka. Grand Central Dispatch ) |
# | emscripten | Emscripten's executor |
# | qt | Qt's event framework |
# | qt5 | Qt's event framework (Qt5) |
# | qt6 | Qt's event framework (Qt6) |
# | none | None |
function( stlab_detect_main_executor result_var )
find_package(Qt6 QUIET COMPONENTS Core)
stlab_detect_task_system( task_system )

if( task_system STREQUAL "libdispatch" )
set( result "libdispatch")
elseif( CMAKE_SYSTEM_NAME STREQUAL "Emscripten" )
set( result "emscripten")
elseif( Qt6Core_FOUND )
set( result "qt")
set( result "qt6")
elseif( Qt5Core_FOUND )
set( result "qt5")
else()
set( result "none")
endif()
Expand Down Expand Up @@ -194,8 +196,10 @@ function( stlab_generate_config_file )
set( STLAB_MAIN_EXECUTOR_LIBDISPATCH TRUE )
elseif (STLAB_MAIN_EXECUTOR STREQUAL "emscripten")
set( STLAB_MAIN_EXECUTOR_EMSCRIPTEN TRUE )
elseif (STLAB_MAIN_EXECUTOR STREQUAL "qt")
set( STLAB_MAIN_EXECUTOR_QT TRUE )
elseif (STLAB_MAIN_EXECUTOR STREQUAL "qt5")
set( STLAB_MAIN_EXECUTOR_QT5 TRUE )
elseif (STLAB_MAIN_EXECUTOR STREQUAL "qt6")
set( STLAB_MAIN_EXECUTOR_QT6 TRUE )
elseif (STLAB_MAIN_EXECUTOR STREQUAL "none")
set( STLAB_MAIN_EXECUTOR_NONE TRUE )
endif()
Expand Down
4 changes: 0 additions & 4 deletions cmake/stlabConfig.cmake

This file was deleted.

21 changes: 21 additions & 0 deletions cmake/stlabConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include( CMakeFindDependencyMacro )

if ( @STLAB_USE_BOOST_CPP17_SHIMS@ )
find_dependency( Boost 1.74.0 )
endif()

if ( @STLAB_TASK_SYSTEM@ STREQUAL "libdispatch" )
find_dependency( libdispatch )
endif()

if ( @STLAB_MAIN_EXECUTOR@ STREQUAL "qt5" )
find_dependency( Qt5 COMPONENTS Core )
elseif ( @STLAB_MAIN_EXECUTOR@ STREQUAL "qt6" )
find_dependency( Qt6 COMPONENTS Core )
endif()

if ( NOT @STLAB_THREAD_SYSTEM@ STREQUAL "none" )
find_dependency( Threads )
endif()

include( "${CMAKE_CURRENT_LIST_DIR}/stlabTargets.cmake" )
2 changes: 1 addition & 1 deletion docs/libraries/concurrency/executor/main_executor/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description: |
All tasks that are passed to an instance of this instance are executed in-order on the application's main loop.
Upon destruction of the main_executor, the underlying main loop is _not_ destroyed. Likewise, all functions submitted to the executor will be executed regardless of destruction state.
So far no main_executor is implemented for Windows. If QT_CORE_LIB is defined and not STLAB_DISABLE_QT_MAIN_EXECUTOR, a main executor is instantiated that executes the tasks on the Qt main loop.
So far no main_executor is implemented for Windows. If STLAB_MAIN_EXECUTOR is qt5 or qt6, a main executor is instantiated that executes the tasks on the Qt main loop.
member-types:
- type: result_type
definition: void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ All tasks that are passed to an instance of this instance are executed in-order

Upon destruction of the main_executor, the underlying main loop is _not_ destroyed. Likewise, all functions submitted to the executor will be executed regardless of destruction state.

So far no main_executor is implemented for Windows. If `QT_CORE_LIB` is defined and not `STLAB_DISABLE_QT_MAIN_EXECUTOR`, a main executor is instantiated that executes the tasks on the Qt main loop.
So far no main_executor is implemented for Windows. If `STLAB_MAIN_EXECUTOR` is `qt5` or `qt6`, a main executor is instantiated that executes the tasks on the Qt main loop.
9 changes: 7 additions & 2 deletions stlab/concurrency/main_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

#include <stlab/config.hpp>

#if STLAB_MAIN_EXECUTOR(QT)
#if STLAB_MAIN_EXECUTOR(QT5) || STLAB_MAIN_EXECUTOR(QT6)
#include <QtGlobal>
#if (STLAB_MAIN_EXECUTOR(QT5) && (QT_VERSION < QT_VERSION_CHECK(5,0,0) || QT_VERSION >= QT_VERSION_CHECK(6,0,0)) || \
STLAB_MAIN_EXECUTOR(QT6) && (QT_VERSION < QT_VERSION_CHECK(6,0,0) || QT_VERSION >= QT_VERSION_CHECK(7,0,0)))
#error "Mismatching Qt versions"
#endif
#include <QCoreApplication>
#include <QEvent>
#include <stlab/concurrency/task.hpp>
Expand All @@ -38,7 +43,7 @@ namespace detail {

/**************************************************************************************************/

#if STLAB_MAIN_EXECUTOR(QT)
#if STLAB_MAIN_EXECUTOR(QT5) || STLAB_MAIN_EXECUTOR(QT6)

class main_executor_type {
using result_type = void;
Expand Down
3 changes: 2 additions & 1 deletion stlab/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#define STLAB_MAIN_EXECUTOR(X) (STLAB_MAIN_EXECUTOR_##X())
#cmakedefine01 STLAB_MAIN_EXECUTOR_LIBDISPATCH()
#cmakedefine01 STLAB_MAIN_EXECUTOR_EMSCRIPTEN()
#cmakedefine01 STLAB_MAIN_EXECUTOR_QT()
#cmakedefine01 STLAB_MAIN_EXECUTOR_QT5()
#cmakedefine01 STLAB_MAIN_EXECUTOR_QT6()
#cmakedefine01 STLAB_MAIN_EXECUTOR_NONE()

// Various functionality macros
Expand Down

0 comments on commit 7e5dc8a

Please sign in to comment.