|
| 1 | +# Macros/functions for finding QCA's qcatool utility and qca-ossl plugin |
| 2 | +# ~~~~~~~~~~~~~~~~ |
| 3 | +# When FIND_QCATOOL is run, will define: |
| 4 | +# |
| 5 | +# QCATOOL_EXECUTABLE - Path to QCA's qcatool utility |
| 6 | +# |
| 7 | +# NOTE: FIND_QCAOSSL_PLUGIN_CPP requires Qt and QCA packages to be found |
| 8 | +# |
| 9 | +# Copyright (c) 2014, Larry Shaffer, <larrys (at) dakotacarto (dot) com>> |
| 10 | +# Redistribution and use is allowed according to the terms of the BSD license. |
| 11 | +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 12 | + |
| 13 | +function(FIND_QCAOSSL_PLUGIN_CPP PLUGIN_REQUIRED) |
| 14 | + |
| 15 | + # requires Qt and QCA packages to be found |
| 16 | + if(QT_INCLUDE_DIR AND QT_QTCORE_INCLUDE_DIR AND QT_QTCORE_LIBRARY |
| 17 | + AND QCA_INCLUDE_DIR AND QCA_LIBRARY |
| 18 | + AND NOT CMAKE_CROSSCOMPILING) |
| 19 | + |
| 20 | + # NOTE: boolean result when compiled executable is run |
| 21 | + set(CODE |
| 22 | + " |
| 23 | + #include <QtCrypto> |
| 24 | + #include <QCoreApplication> |
| 25 | +
|
| 26 | + int main( int argc, char** argv ) |
| 27 | + { |
| 28 | + QCA::Initializer init; |
| 29 | + QCoreApplication app( argc, argv ); |
| 30 | + if ( !QCA::isSupported( \"cert\", \"qca-ossl\" ) ) |
| 31 | + { |
| 32 | + return 0; |
| 33 | + } |
| 34 | + return 1; |
| 35 | + } |
| 36 | + " |
| 37 | + ) |
| 38 | + set(TESTCPP "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/qcaossl.cpp") |
| 39 | + file(WRITE ${TESTCPP} "${CODE}") |
| 40 | + |
| 41 | + set(QCA_INCLUDE_DIRECTORIES "-DINCLUDE_DIRECTORIES:STRING=${QT_INCLUDE_DIR};${QT_QTCORE_INCLUDE_DIR};${QCA_INCLUDE_DIR}") |
| 42 | + set(QCA_LINK_LIBRARIES "-DLINK_LIBRARIES:STRING=${QT_QTCORE_LIBRARY};${QCA_LIBRARY}") |
| 43 | + |
| 44 | + try_run(RUN_RESULT COMPILE_RESULT |
| 45 | + ${CMAKE_BINARY_DIR} ${TESTCPP} |
| 46 | + CMAKE_FLAGS "${QCA_INCLUDE_DIRECTORIES}" "${QCA_LINK_LIBRARIES}" |
| 47 | + COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT |
| 48 | + ) |
| 49 | + |
| 50 | + set(_msg "QCA OpenSSL plugin not found (run-time/unit-test dependency)") |
| 51 | + |
| 52 | + if(NOT COMPILE_RESULT) |
| 53 | + message(STATUS "QCA OpenSSL plugin C++ check failed to compile") |
| 54 | + if(${PLUGIN_REQUIRED}) |
| 55 | + message(STATUS "QCA OpenSSL plugin C++ check compile output:") |
| 56 | + message(STATUS "${COMPILE_OUTPUT}") |
| 57 | + message(FATAL_ERROR ${_msg}) |
| 58 | + else() |
| 59 | + message(STATUS ${_msg}) |
| 60 | + endif() |
| 61 | + else() |
| 62 | + if(NOT RUN_RESULT) |
| 63 | + if(${PLUGIN_REQUIRED}) |
| 64 | + message(FATAL_ERROR ${_msg}) |
| 65 | + else() |
| 66 | + message(STATUS ${_msg}) |
| 67 | + endif() |
| 68 | + else() |
| 69 | + message(STATUS "Found QCA OpenSSL plugin") |
| 70 | + endif() |
| 71 | + endif() |
| 72 | + |
| 73 | + else() |
| 74 | + message(STATUS "QtCore/QCA include/lib variables missing or CMake is cross-compiling,") |
| 75 | + message(STATUS " skipping QCA OpenSSL plugin C++ check") |
| 76 | + endif() |
| 77 | + |
| 78 | +endfunction(FIND_QCAOSSL_PLUGIN_CPP PLUGIN_REQUIRED) |
| 79 | + |
| 80 | + |
| 81 | +function(FIND_QCATOOL TOOL_REQUIRED) |
| 82 | + if(NOT QCATOOL_EXECUTABLE) |
| 83 | + |
| 84 | + if(MSVC) |
| 85 | + find_program(QCATOOL_EXECUTABLE NAMES qcatool.exe qcatool2.exe |
| 86 | + PATHS |
| 87 | + $ENV{LIB_DIR}/bin |
| 88 | + $ENV{OSGEO4W_ROOT}/bin |
| 89 | + ) |
| 90 | + else() |
| 91 | + find_program(QCATOOL_EXECUTABLE NAMES qcatool qcatool2) |
| 92 | + endif() |
| 93 | + |
| 94 | + if(NOT QCATOOL_EXECUTABLE) |
| 95 | + set(_msg "QCA's qcatool utility not found - aborting") |
| 96 | + if(${TOOL_REQUIRED}) |
| 97 | + message(FATAL_ERROR ${_msg}) |
| 98 | + else() |
| 99 | + message(STATUS ${_msg}) |
| 100 | + endif() |
| 101 | + endif() |
| 102 | + |
| 103 | + else() |
| 104 | + |
| 105 | + get_filename_component(_qcatool ${QCATOOL_EXECUTABLE} REALPATH) |
| 106 | + if(NOT EXISTS "${_qcatool}") |
| 107 | + set(_msg "QCA's qcatool utility not found at: ${QCATOOL_EXECUTABLE}") |
| 108 | + if(${TOOL_REQUIRED}) |
| 109 | + message(FATAL_ERROR ${_msg}) |
| 110 | + else() |
| 111 | + message(STATUS ${_msg}) |
| 112 | + endif() |
| 113 | + endif() |
| 114 | + |
| 115 | + endif(NOT QCATOOL_EXECUTABLE) |
| 116 | + |
| 117 | +endfunction(FIND_QCATOOL TOOL_REQUIRED) |
| 118 | + |
| 119 | + |
| 120 | +function(FIND_QCAOSSL_PLUGIN PLUGIN_REQUIRED) |
| 121 | + |
| 122 | + get_filename_component(_qcatool ${QCATOOL_EXECUTABLE} REALPATH) |
| 123 | + |
| 124 | + if(EXISTS "${_qcatool}") |
| 125 | + execute_process(COMMAND "${_qcatool}" plugins OUTPUT_VARIABLE _qca_plugins) |
| 126 | + # message(STATUS ${_qca_plugins}) |
| 127 | + |
| 128 | + if(NOT "${_qca_plugins}" MATCHES "qca-ossl") |
| 129 | + set(_msg "QCA OpenSSL plugin not found (run-time/unit-test dependency)") |
| 130 | + if(${PLUGIN_REQUIRED}) |
| 131 | + message(FATAL_ERROR ${_msg}) |
| 132 | + else() |
| 133 | + message(STATUS ${_msg}) |
| 134 | + endif() |
| 135 | + else() |
| 136 | + message(STATUS "Found QCA OpenSSL plugin") |
| 137 | + endif() |
| 138 | + endif() |
| 139 | + |
| 140 | +endfunction(FIND_QCAOSSL_PLUGIN PLUGIN_REQUIRED) |
| 141 | + |
| 142 | + |
| 143 | +function(FIND_QCA_PLUGIN_DIR DIR_REQUIRED) |
| 144 | + |
| 145 | + FIND_QCATOOL(1) |
| 146 | + get_filename_component(_qcatool ${QCATOOL_EXECUTABLE} REALPATH) |
| 147 | + |
| 148 | + if(EXISTS "${_qcatool}") |
| 149 | + execute_process(COMMAND "${_qcatool}" plugins OUTPUT_VARIABLE _qca_plugins) |
| 150 | + #message(STATUS ${_qca_plugins}) |
| 151 | + string(REGEX REPLACE "\n" ";" _qca_plugins_list "${_qca_plugins}") |
| 152 | + #message(STATUS "_qca_plugins_list: ${_qca_plugins_list}") |
| 153 | + |
| 154 | + if(NOT "${_qca_plugins}" MATCHES "Available Providers") |
| 155 | + set(_msg "QCA plugin directory not found") |
| 156 | + if(${DIR_REQUIRED}) |
| 157 | + message(FATAL_ERROR ${_msg}) |
| 158 | + else() |
| 159 | + message(STATUS ${_msg}) |
| 160 | + endif() |
| 161 | + else() |
| 162 | + |
| 163 | + set(QCA_PLUGIN_DIR) |
| 164 | + foreach(_plugin_dir ${_qca_plugins_list}) |
| 165 | + string(STRIP "${_plugin_dir}" _plugin_dir) |
| 166 | + if(EXISTS "${_plugin_dir}" AND IS_DIRECTORY "${_plugin_dir}" AND NOT QCA_PLUGIN_DIR) |
| 167 | + file(GLOB qca_dylibs "${_plugin_dir}/crypto/libqca*") |
| 168 | + if(qca_dylibs) |
| 169 | + set(QCA_PLUGIN_DIR "${_plugin_dir}") |
| 170 | + endif() |
| 171 | + endif() |
| 172 | + endforeach() |
| 173 | + |
| 174 | + if(QCA_PLUGIN_DIR) |
| 175 | + set(QCA_PLUGIN_DIR "${QCA_PLUGIN_DIR}" PARENT_SCOPE) |
| 176 | + message(STATUS "Found QCA plugin directory: ${QCA_PLUGIN_DIR}") |
| 177 | + else() |
| 178 | + set(_msg "QCA plugin directory not found") |
| 179 | + if(${DIR_REQUIRED}) |
| 180 | + message(FATAL_ERROR ${_msg}) |
| 181 | + else() |
| 182 | + message(STATUS ${_msg}) |
| 183 | + endif() |
| 184 | + endif() |
| 185 | + |
| 186 | + endif() |
| 187 | + endif() |
| 188 | + |
| 189 | +endfunction(FIND_QCA_PLUGIN_DIR DIR_REQUIRED) |
0 commit comments