|
1 | | -find_package(Qt5 COMPONENTS Core Xml OpenGL Gui Widgets QUIET) |
2 | | -if(NOT Qt5_FOUND) |
3 | | - message("Qt5 not found. Install it and set Qt5_DIR accordingly") |
4 | | - if (WIN32) |
5 | | - message(" In Windows, Qt5_DIR should be something like C:/Qt/5.4/msvc2013_64_opengl/lib/cmake/Qt5") |
6 | | - endif() |
7 | | - return() |
| 1 | +# Find QGLViewer: a C++ OpenGL widget for Qt |
| 2 | +# This module defines the following variables: |
| 3 | +# QGLVIEWER_FOUND - True if QGLViewer library is found |
| 4 | +# QGLVIEWER_INCLUDE_DIR - Include directories for QGLViewer |
| 5 | +# QGLVIEWER_LIBRARY - QGLViewer library |
| 6 | +# QGLVIEWER_VERSION - Version of QGLViewer if available |
| 7 | + |
| 8 | +# Try pkg-config first (if available) |
| 9 | +find_package(PkgConfig QUIET) |
| 10 | +if(PkgConfig_FOUND) |
| 11 | + pkg_check_modules(QGLVIEWER QUIET QGLViewer) |
8 | 12 | endif() |
9 | 13 |
|
10 | | -find_path(QGLVIEWER_INCLUDE_DIR qglviewer.h |
11 | | - /usr/include/QGLViewer |
12 | | - /opt/local/include/QGLViewer |
13 | | - /usr/local/include/QGLViewer |
14 | | - /sw/include/QGLViewer |
15 | | - ENV QGLVIEWERROOT |
| 14 | +# If pkg-config didn't find it, search manually |
| 15 | +if(NOT QGLVIEWER_FOUND) |
| 16 | + # Try to find Qt5 (optional - QGLViewer may not be needed) |
| 17 | + find_package(Qt5 COMPONENTS Core Xml OpenGL Gui Widgets QUIET) |
| 18 | + if(NOT Qt5_FOUND) |
| 19 | + if(QGLViewer_FIND_REQUIRED) |
| 20 | + message(SEND_ERROR "Qt5 not found. Install it and set Qt5_DIR accordingly") |
| 21 | + if(WIN32) |
| 22 | + message(STATUS " In Windows, Qt5_DIR should be something like C:/Qt/5.4/msvc2013_64_opengl/lib/cmake/Qt5") |
| 23 | + endif() |
| 24 | + return() |
| 25 | + else() |
| 26 | + message(STATUS "Qt5 not found. QGLViewer support will be disabled (this is optional)") |
| 27 | + return() |
| 28 | + endif() |
| 29 | + endif() |
| 30 | + |
| 31 | + # Find include directory |
| 32 | + find_path(QGLVIEWER_INCLUDE_DIR qglviewer.h |
| 33 | + HINTS ${QGLVIEWER_INCLUDE_DIRS} |
| 34 | + PATHS /usr/include/QGLViewer |
| 35 | + /opt/local/include/QGLViewer |
| 36 | + /usr/local/include/QGLViewer |
| 37 | + /sw/include/QGLViewer |
| 38 | + $ENV{QGLVIEWERROOT}/include |
| 39 | + $ENV{QGLVIEWERROOT} |
| 40 | + DOC "QGLViewer include directory" |
| 41 | + ) |
| 42 | + |
| 43 | + # Find release library |
| 44 | + find_library(QGLVIEWER_LIBRARY_RELEASE |
| 45 | + NAMES qglviewer QGLViewer qglviewer-qt5 QGLViewer-qt5 |
| 46 | + HINTS ${QGLVIEWER_LIBRARY_DIRS} |
| 47 | + PATHS /usr/lib |
| 48 | + /usr/local/lib |
| 49 | + /opt/local/lib |
| 50 | + /sw/lib |
| 51 | + $ENV{QGLVIEWERROOT}/lib |
| 52 | + $ENV{QGLVIEWERROOT}/lib64 |
| 53 | + $ENV{QGLVIEWERROOT}/lib/x64 |
| 54 | + $ENV{QGLVIEWERROOT}/lib/win32 |
| 55 | + PATH_SUFFIXES QGLViewer QGLViewer/release x64/Release Win32/Release |
| 56 | + DOC "QGLViewer release library" |
| 57 | + ) |
| 58 | + |
| 59 | + # Find debug library |
| 60 | + find_library(QGLVIEWER_LIBRARY_DEBUG |
| 61 | + NAMES dqglviewer dQGLViewer dqglviewer-qt5 dQGLViewer-qt5 QGLViewerd2 |
| 62 | + HINTS ${QGLVIEWER_LIBRARY_DIRS} |
| 63 | + PATHS /usr/lib |
| 64 | + /usr/local/lib |
| 65 | + /opt/local/lib |
| 66 | + /sw/lib |
| 67 | + $ENV{QGLVIEWERROOT}/lib |
| 68 | + $ENV{QGLVIEWERROOT}/lib64 |
| 69 | + $ENV{QGLVIEWERROOT}/lib/x64 |
| 70 | + $ENV{QGLVIEWERROOT}/lib/win32 |
| 71 | + PATH_SUFFIXES QGLViewer QGLViewer/debug x64/Debug Win32/Debug |
| 72 | + DOC "QGLViewer debug library" |
16 | 73 | ) |
17 | 74 |
|
18 | | -find_library(QGLVIEWER_LIBRARY_RELEASE |
19 | | - NAMES qglviewer QGLViewer qglviewer-qt5 QGLViewer-qt5 |
20 | | - PATHS /usr/lib |
21 | | - /usr/local/lib |
22 | | - /opt/local/lib |
23 | | - /sw/lib |
24 | | - ENV QGLVIEWERROOT |
25 | | - ENV LD_LIBRARY_PATH |
26 | | - ENV LIBRARY_PATH |
27 | | - PATH_SUFFIXES QGLViewer QGLViewer/release |
28 | | -) |
29 | | -find_library(QGLVIEWER_LIBRARY_DEBUG |
30 | | - NAMES dqglviewer dQGLViewer dqglviewer-qt5 dQGLViewer-qt5 QGLViewerd2 |
31 | | - PATHS /usr/lib |
32 | | - /usr/local/lib |
33 | | - /opt/local/lib |
34 | | - /sw/lib |
35 | | - ENV QGLVIEWERROOT |
36 | | - ENV LD_LIBRARY_PATH |
37 | | - ENV LIBRARY_PATH |
38 | | - PATH_SUFFIXES QGLViewer QGLViewer/debug |
39 | | -) |
40 | | - |
41 | | -if(QGLVIEWER_LIBRARY_RELEASE) |
42 | | - if(QGLVIEWER_LIBRARY_DEBUG) |
43 | | - set(QGLVIEWER_LIBRARY optimized ${QGLVIEWER_LIBRARY_RELEASE} debug ${QGLVIEWER_LIBRARY_DEBUG}) |
44 | | - else() |
45 | | - set(QGLVIEWER_LIBRARY ${QGLVIEWER_LIBRARY_RELEASE}) |
| 75 | + # Handle debug/release library selection |
| 76 | + if(QGLVIEWER_LIBRARY_RELEASE) |
| 77 | + if(QGLVIEWER_LIBRARY_DEBUG) |
| 78 | + set(QGLVIEWER_LIBRARY optimized ${QGLVIEWER_LIBRARY_RELEASE} debug ${QGLVIEWER_LIBRARY_DEBUG}) |
| 79 | + else() |
| 80 | + set(QGLVIEWER_LIBRARY ${QGLVIEWER_LIBRARY_RELEASE}) |
| 81 | + endif() |
46 | 82 | endif() |
47 | | -endif() |
48 | 83 |
|
49 | | -include(FindPackageHandleStandardArgs) |
50 | | -find_package_handle_standard_args(QGLViewer DEFAULT_MSG |
51 | | - QGLVIEWER_INCLUDE_DIR QGLVIEWER_LIBRARY) |
| 84 | + # Try to extract version from header and convert to semantic version |
| 85 | + if(QGLVIEWER_INCLUDE_DIR AND EXISTS "${QGLVIEWER_INCLUDE_DIR}/config.h") |
| 86 | + file(STRINGS "${QGLVIEWER_INCLUDE_DIR}/config.h" QGLVIEWER_VERSION_LINE |
| 87 | + REGEX "^#define QGLVIEWER_VERSION.*") |
| 88 | + if(QGLVIEWER_VERSION_LINE) |
| 89 | + # Extract hex value (format: 0xMMmmPP where MM=major, mm=minor, PP=patch) |
| 90 | + string(REGEX MATCH "0x[0-9a-fA-F]+" QGLVIEWER_VERSION_HEX "${QGLVIEWER_VERSION_LINE}") |
| 91 | + if(QGLVIEWER_VERSION_HEX) |
| 92 | + # Remove 0x prefix and extract 6-digit hex string |
| 93 | + string(SUBSTRING "${QGLVIEWER_VERSION_HEX}" 2 6 QGLVIEWER_VERSION_HEX_DIGITS) |
| 94 | + |
| 95 | + # Extract major (bits 16-23, first 2 hex digits) |
| 96 | + string(SUBSTRING "${QGLVIEWER_VERSION_HEX_DIGITS}" 0 2 QGLVIEWER_VERSION_MAJOR_HEX) |
| 97 | + # Extract minor (bits 8-15, middle 2 hex digits) |
| 98 | + string(SUBSTRING "${QGLVIEWER_VERSION_HEX_DIGITS}" 2 2 QGLVIEWER_VERSION_MINOR_HEX) |
| 99 | + # Extract patch (bits 0-7, last 2 hex digits) |
| 100 | + string(SUBSTRING "${QGLVIEWER_VERSION_HEX_DIGITS}" 4 2 QGLVIEWER_VERSION_PATCH_HEX) |
| 101 | + |
| 102 | + # Convert hex to decimal |
| 103 | + math(EXPR QGLVIEWER_VERSION_MAJOR "0x${QGLVIEWER_VERSION_MAJOR_HEX}") |
| 104 | + math(EXPR QGLVIEWER_VERSION_MINOR "0x${QGLVIEWER_VERSION_MINOR_HEX}") |
| 105 | + math(EXPR QGLVIEWER_VERSION_PATCH "0x${QGLVIEWER_VERSION_PATCH_HEX}") |
| 106 | + |
| 107 | + # Assemble semantic version string |
| 108 | + set(QGLVIEWER_VERSION "${QGLVIEWER_VERSION_MAJOR}.${QGLVIEWER_VERSION_MINOR}.${QGLVIEWER_VERSION_PATCH}") |
| 109 | + endif() |
| 110 | + endif() |
| 111 | + endif() |
| 112 | + |
| 113 | + # Standard find_package handling |
| 114 | + include(FindPackageHandleStandardArgs) |
| 115 | + find_package_handle_standard_args(QGLViewer |
| 116 | + REQUIRED_VARS QGLVIEWER_INCLUDE_DIR QGLVIEWER_LIBRARY |
| 117 | + VERSION_VAR QGLVIEWER_VERSION) |
| 118 | + |
| 119 | + # Create modern CMake interface target |
| 120 | + if(QGLVIEWER_FOUND AND NOT TARGET QGLViewer::QGLViewer) |
| 121 | + add_library(QGLViewer::QGLViewer UNKNOWN IMPORTED) |
| 122 | + set_target_properties(QGLViewer::QGLViewer PROPERTIES |
| 123 | + IMPORTED_LOCATION "${QGLVIEWER_LIBRARY}" |
| 124 | + INTERFACE_INCLUDE_DIRECTORIES "${QGLVIEWER_INCLUDE_DIR}" |
| 125 | + INTERFACE_LINK_LIBRARIES "Qt5::Core;Qt5::Xml;Qt5::OpenGL;Qt5::Gui;Qt5::Widgets" |
| 126 | + ) |
| 127 | + if(QGLVIEWER_LIBRARY_DEBUG) |
| 128 | + set_target_properties(QGLViewer::QGLViewer PROPERTIES |
| 129 | + IMPORTED_LOCATION_DEBUG "${QGLVIEWER_LIBRARY_DEBUG}" |
| 130 | + ) |
| 131 | + endif() |
| 132 | + endif() |
| 133 | + |
| 134 | + mark_as_advanced( |
| 135 | + QGLVIEWER_INCLUDE_DIR |
| 136 | + QGLVIEWER_LIBRARY |
| 137 | + QGLVIEWER_LIBRARY_RELEASE |
| 138 | + QGLVIEWER_LIBRARY_DEBUG |
| 139 | + QGLVIEWER_VERSION_HEX |
| 140 | + QGLVIEWER_VERSION_HEX_DIGITS |
| 141 | + QGLVIEWER_VERSION_MAJOR_HEX |
| 142 | + QGLVIEWER_VERSION_MINOR_HEX |
| 143 | + QGLVIEWER_VERSION_PATCH_HEX |
| 144 | + QGLVIEWER_VERSION_MAJOR |
| 145 | + QGLVIEWER_VERSION_MINOR |
| 146 | + QGLVIEWER_VERSION_PATCH |
| 147 | + QGLVIEWER_VERSION_LINE |
| 148 | + QGLVIEWER_INCLUDE_DIRS |
| 149 | + QGLVIEWER_LIBRARY_DIRS |
| 150 | + ) |
| 151 | +endif() |
0 commit comments