mne-tools / mne-cpp

MNE-CPP: A Framework for Electrophysiology
https://mne-cpp.org/
BSD 3-Clause "New" or "Revised" License
151 stars 137 forks source link

Change how Qt dependecies are specified #934

Closed gabrielbmotta closed 1 year ago

gabrielbmotta commented 1 year ago

Currently we list out the Qt dependencies twice, and then the library names once, for a total of three times. If these need to be added to, removed, or changed, currently this requires three places to be changed.

This PR changes it to being specified once, and the required syntax differences are done programmatically.

OLD WAY:

find_packages(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Your Dependencies Go Here)
find_packages(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Your Dependencies Go Here)

*** lots of cmake in between***

target_link_libraries(${PROJECT_NAME} PRIVATE
    Qt${QT_VERSION_MAJOR}::Your
    Qt${QT_VERSION_MAJOR}::Dependencies
    Qt${QT_VERSION_MAJOR}::Go
    Qt${QT_VERSION_MAJOR}::Here

NEW WAY:

set(QT_REQUIRED_COMPONENTS Your Dependencies Go Here)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS ${QT_REQUIRED_COMPONENTS})
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${QT_REQUIRED_COMPONENTS})

*** lots of cmake in between***

set(QT_REQUIRED_COMPONENT_LIBS ${QT_REQUIRED_COMPONENTS})
list(TRANSFORM QT_REQUIRED_COMPONENT_LIBS PREPEND "Qt${QT_VERSION_MAJOR}::")

target_link_libraries(${PROJECT_NAME} PRIVATE
    ${QT_REQUIRED_COMPONENT_LIBS}