Skip to content

Commit

Permalink
Add CNTP_INSTALL_QML CMake variable
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Mar 5, 2024
1 parent 774f9f9 commit 8785929
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions lib/cmake-scripts/cntp-extrainstalldirs.cmake
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
include_guard()

function(cntp_define_build_dirs)
function(cntp_retrieve_qmake_install_dir VAR_NAME QMAKE_VAR)
set(QMAKE_EXTRA_ARGS)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
find_path(QMAKE_PATH
NAMES qmake6.exe
HINTS ${QT_HOST_PATH};${CMAKE_PREFIX_PATH}
PATH_SUFFIXES bin)
find_path(QT_CONF
NAMES target_qt.conf
HINTS ${CMAKE_PREFIX_PATH}
PATH_SUFFIXES bin)
IF(NOT ${QT_CONF} STREQUAL "QT_CONF-NOTFOUND")
message("Using Qt configuration file ${QT_CONF}/target_qt.conf")
set(QMAKE_EXTRA_ARGS -qtconf "${QT_CONF}/target_qt.conf")
set(QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE})
if (NOT QMAKE_EXECUTABLE)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
find_path(QMAKE_EXECUTABLE
NAMES qmake6.exe
HINTS ${QT_HOST_PATH};${CMAKE_PREFIX_PATH}
PATH_SUFFIXES bin
NO_CACHE)
find_path(QT_CONF
NAMES target_qt.conf
HINTS ${CMAKE_PREFIX_PATH}
PATH_SUFFIXES bin
NO_CACHE)
IF(NOT ${QT_CONF} STREQUAL "QT_CONF-NOTFOUND")
message("Using Qt configuration file ${QT_CONF}/target_qt.conf")
set(QMAKE_EXTRA_ARGS -qtconf "${QT_CONF}/target_qt.conf")
ENDIF()
ELSE()
find_path(QMAKE_EXECUTABLE qmake6 NO_CACHE)
ENDIF()
ELSE()
find_path(QMAKE_PATH qmake6)
ENDIF()

IF(${QMAKE_PATH} STREQUAL "QMAKE_PATH-NOTFOUND")
message(FATAL_ERROR "Couldn't call qmake. Ensure Qt 6 is installed correctly and qmake6 is located in your PATH.")
ENDIF()
IF(${QMAKE_EXECUTABLE} STREQUAL "QMAKE_EXECUTABLE-NOTFOUND")
message(FATAL_ERROR "Couldn't call qmake. Ensure Qt 6 is installed correctly and qmake6 is located in your PATH.")
ENDIF()

IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(QMAKE_PATH ${QMAKE_PATH}/qmake6.exe)
ELSE()
set(QMAKE_PATH ${QMAKE_PATH}/qmake6)
ENDIF()
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(QMAKE_EXECUTABLE ${QMAKE_EXECUTABLE}/qmake6.exe)
ELSE()
set(QMAKE_EXECUTABLE ${QMAKE_EXECUTABLE}/qmake6)
ENDIF()
endif()

execute_process(
COMMAND ${QMAKE_PATH} ${QMAKE_EXTRA_ARGS} -query QT_INSTALL_PREFIX
COMMAND ${QMAKE_EXECUTABLE} ${QMAKE_EXTRA_ARGS} -query QT_INSTALL_PREFIX
RESULT_VARIABLE QT_PREFIX_RESULT
OUTPUT_VARIABLE QT_PREFIX_DIR
)
Expand All @@ -39,7 +44,7 @@ function(cntp_define_build_dirs)
file(TO_CMAKE_PATH "${QT_PREFIX_DIR}" QT_PREFIX_DIR)

execute_process(
COMMAND ${QMAKE_PATH} ${QMAKE_EXTRA_ARGS} -query QT_INSTALL_PLUGINS
COMMAND ${QMAKE_EXECUTABLE} ${QMAKE_EXTRA_ARGS} -query ${QMAKE_VAR}
RESULT_VARIABLE PLUGIN_INSTALLATION_DIR_RESULT
OUTPUT_VARIABLE PLUGIN_INSTALLATION_DIR
)
Expand All @@ -48,9 +53,14 @@ function(cntp_define_build_dirs)
file(TO_CMAKE_PATH "${PLUGIN_INSTALLATION_DIR}" PLUGIN_INSTALLATION_DIR)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(CNTP_INSTALL_PLUGINS ${PLUGIN_INSTALLATION_DIR} PARENT_SCOPE)
set(${VAR_NAME} ${PLUGIN_INSTALLATION_DIR} PARENT_SCOPE)
ELSE()
file(RELATIVE_PATH PLUGIN_INSTALLATION_DIR "${QT_PREFIX_DIR}" "${PLUGIN_INSTALLATION_DIR}")
set(CNTP_INSTALL_PLUGINS ${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALLATION_DIR} PARENT_SCOPE)
set(${VAR_NAME} ${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALLATION_DIR} PARENT_SCOPE)
ENDIF()
endfunction()

macro(cntp_define_build_dirs)
cntp_retrieve_qmake_install_dir("CNTP_INSTALL_PLUGINS" "QT_INSTALL_PLUGINS")
cntp_retrieve_qmake_install_dir("CNTP_INSTALL_QML" "QT_INSTALL_QML")
endmacro()

0 comments on commit 8785929

Please sign in to comment.