summaryrefslogtreecommitdiffhomepage
path: root/cmake/opentrack-qt.cmake
blob: 8526acf7d5c28008b91033b554451b73cd594945 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
include_guard(GLOBAL)
find_package(Qt5 REQUIRED COMPONENTS Core Network Widgets LinguistTools Gui QUIET)
if(WIN32)
    find_package(Qt5Gui REQUIRED COMPONENTS QWindowsIntegrationPlugin)
endif()
find_package(Qt5 COMPONENTS SerialPort QUIET)

set(MY_QT_LIBS ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES})

function(otr_pdb_for_dll varname path)
    set("${varname}" "" PARENT_SCOPE)
    get_filename_component(dir "${path}" DIRECTORY)
    get_filename_component(name-only "${path}" NAME_WE)
    set(pdb-path "${dir}/${name-only}.pdb")
    if(EXISTS "${pdb-path}")
        set("${varname}" "${pdb-path}" PARENT_SCOPE)
    endif()
endfunction()

function(otr_install_qt_libs)
    if(WIN32)
        foreach(i Qt5::Core Qt5::Gui Qt5::Network Qt5::SerialPort Qt5::Widgets)
            get_property(path TARGET "${i}" PROPERTY "LOCATION_${CMAKE_BUILD_TYPE}")
            if(path STREQUAL "")
                get_property(path TARGET "${i}" PROPERTY LOCATION)
            endif()
            if(path STREQUAL "")
                message(FATAL_ERROR "can't find ${i}")
            endif()
            install(FILES "${path}" DESTINATION .)
            if(MSVC AND opentrack_install-debug-info)
                otr_pdb_for_dll(pdb-path "${path}")
                if(pdb-path)
                    install(FILES "${pdb-path}" DESTINATION "${opentrack-hier-debug}")
                endif()
            endif()
        endforeach()

        get_property(path TARGET Qt5::QWindowsIntegrationPlugin PROPERTY "LOCATION_${CMAKE_BUILD_TYPE}")
        if(path STREQUAL "")
            get_property(path TARGET Qt5::QWindowsIntegrationPlugin PROPERTY LOCATION)
        endif()
        if(path STREQUAL "")
            message(FATAL_ERROR "can't find Qt5::QWindowsIntegrationPlugin")
        endif()
        install(FILES "${path}" DESTINATION ./platforms)
        if(MSVC AND opentrack_install-debug-info)
            otr_pdb_for_dll(pdb-path "${path}")
            if(pdb-path)
                install(FILES "${pdb-path}" DESTINATION "${opentrack-hier-debug}")
            endif()
        endif()
    endif()
endfunction()

otr_install_qt_libs()

function(otr_qt n)
    if(".${${n}-cc}${${n}-cxx}${${n}-hh}" STREQUAL ".")
        message(FATAL_ERROR "project ${n} not globbed")
   endif()
    qt5_wrap_cpp(${n}-moc ${${n}-hh} OPTIONS --no-notes -I "${CMAKE_CURRENT_BINARY_DIR}" -I "${CMAKE_SOURCE_DIR}")
    qt5_wrap_ui(${n}-uih ${${n}-ui})
    qt5_add_resources(${n}-rcc ${${n}-rc})

    foreach(i moc uih rcc)
        set(${n}-${i} "${${n}-${i}}" PARENT_SCOPE)
        list(APPEND ${n}-all ${${n}-${i}})
    endforeach()
    set(${n}-all "${${n}-all}" PARENT_SCOPE)
endfunction()

function(otr_qt2 n)
    target_include_directories("${n}" PRIVATE SYSTEM
        ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}
    )
    target_compile_definitions("${n}" PRIVATE
        ${Qt5Core_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS}
        -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
        -DQT_MESSAGELOGCONTEXT
    )
endfunction()