From 018e78575c6f7f5a90b41274468a26b09b909443 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 27 Feb 2012 16:45:27 +0100 Subject: [PATCH] Make the CMake files work with directory overrides. This allows us to create correct CMake config files when Qt is configured with directories outside of the prefix (which Qt allows), and also allows us to use correct values when a 'longer' relative lib directory is used such as lib/x86_64-linux-gnu. Change-Id: I6f88255a23752dc5b84cb20ce13fdeeee9d5ad51 Reviewed-by: Oswald Buddenhagen Reviewed-by: Alexander Neundorf Reviewed-by: Stephen Kelly --- mkspecs/cmake/Qt5BasicConfig.cmake.in | 27 ++++++++++++++++---- mkspecs/features/create_cmake.prf | 39 ++++++++++++++++++++++++----- src/corelib/Qt5CoreConfigExtras.cmake.in | 29 ++++++++++++++++----- src/widgets/Qt5WidgetsConfigExtras.cmake.in | 7 ++++-- 4 files changed, 83 insertions(+), 19 deletions(-) diff --git a/mkspecs/cmake/Qt5BasicConfig.cmake.in b/mkspecs/cmake/Qt5BasicConfig.cmake.in index ebdad09..45a0722 100644 --- a/mkspecs/cmake/Qt5BasicConfig.cmake.in +++ b/mkspecs/cmake/Qt5BasicConfig.cmake.in @@ -6,7 +6,12 @@ set(Qt5$${CMAKE_MODULE_NAME}_VERSION_MINOR "$$eval(QT.$${MODULE}.MINOR_VERSION)" set(Qt5$${CMAKE_MODULE_NAME}_VERSION_PATCH "$$eval(QT.$${MODULE}.PATCH_VERSION)") set(Qt5$${CMAKE_MODULE_NAME}_LIBRARIES Qt5::$${CMAKE_MODULE_NAME}) -set(Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS \"${_qt5_install_prefix}/$$CMAKE_INCLUDE_DIR\" \"${_qt5_install_prefix}/$$CMAKE_INCLUDE_DIR/Qt$${CMAKE_MODULE_NAME}\") + +!!IF isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE) +set(Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS \"${_qt5_install_prefix}/$$CMAKE_INCLUDE_DIR\" \"${_qt5_install_prefix}/$${CMAKE_INCLUDE_DIR}Qt$${CMAKE_MODULE_NAME}\") +!!ELSE +set(Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS \"$$CMAKE_INCLUDE_DIR\" \"$${CMAKE_INCLUDE_DIR}Qt$${CMAKE_MODULE_NAME}\") +!!ENDIF string(TOUPPER "$${CMAKE_MODULE_NAME}" _CMAKE_MODULE_NAME_UPPER) set(Qt5$${CMAKE_MODULE_NAME}_DEFINITIONS -DQT_\${_CMAKE_MODULE_NAME_UPPER}_LIB) @@ -46,11 +51,15 @@ endif() set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG \"$${CMAKE_QT5_MODULE_DEPS}\" - IMPORTED_LOCATION_DEBUG \"${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" +!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE) + IMPORTED_LOCATION_DEBUG \"${_qt5_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" +!!ELSE + IMPORTED_LOCATION_DEBUG \"$${CMAKE_LIB_DIR}$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" +!!ENDIF ) !!IF !isEmpty(CMAKE_IMPLIB_FILE_LOCATION_DEBUG) set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES - IMPORTED_IMPLIB_DEBUG \"${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" + IMPORTED_IMPLIB_DEBUG \"${_qt5_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" ) !!ENDIF !!ENDIF @@ -59,11 +68,19 @@ set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE \"$${CMAKE_QT5_MODULE_DEPS}\" - IMPORTED_LOCATION_RELEASE \"${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" +!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE) + IMPORTED_LOCATION_RELEASE \"${_qt5_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" +!!ELSE + IMPORTED_LOCATION_RELEASE \"$${CMAKE_LIB_DIR}$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" +!!ENDIF ) !!IF !isEmpty(CMAKE_IMPLIB_FILE_LOCATION_RELEASE) set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES - IMPORTED_IMPLIB_RELEASE \"${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" +!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE) + IMPORTED_IMPLIB_RELEASE \"${_qt5_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" +!!ELSE + IMPORTED_IMPLIB_RELEASE \"$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" +!!ENDIF ) !!ENDIF !!ENDIF diff --git a/mkspecs/features/create_cmake.prf b/mkspecs/features/create_cmake.prf index eb0cdf6..1aa8ae5 100644 --- a/mkspecs/features/create_cmake.prf +++ b/mkspecs/features/create_cmake.prf @@ -21,13 +21,40 @@ CMAKE_MODULE_DEPS = $$cmakeModuleList($$eval(QT.$${MODULE}.depends)) CMAKE_PARTIAL_MODULE_DEPS = $$replace(CMAKE_MODULE_DEPS, ";", ";Qt5::") !isEmpty(CMAKE_PARTIAL_MODULE_DEPS):CMAKE_QT5_MODULE_DEPS = "Qt5::$${CMAKE_PARTIAL_MODULE_DEPS}" -CMAKE_INCLUDE_DIR = include -CMAKE_LIBS = $$eval(QT.$${MODULE}.libs) -CMAKE_LIB_DIR = $$replace(CMAKE_LIBS, ^.*/, ) -CMAKE_BINS = $$eval(QT.$${MODULE}.bins) -CMAKE_BIN_DIR = $$replace(CMAKE_BINS, ^.*/, ) +CMAKE_QT_INSTALL_PREFIX = $$replace($$list($$[QT_INSTALL_PREFIX]), \\\\, /)/ +CMAKE_QT_INSTALL_PREFIX_ESCAPED = "^$$re_escape($$CMAKE_QT_INSTALL_PREFIX)" -CMAKE_RELATIVE_INSTALL_DIR = "../../../" +CMAKE_INCLUDE_DIR = $$[QT_INSTALL_HEADERS] +contains(CMAKE_INCLUDE_DIR, "$${CMAKE_QT_INSTALL_PREFIX_ESCAPED}.*") { + CMAKE_INCLUDE_DIR = $$replace(CMAKE_INCLUDE_DIR, "$$CMAKE_QT_INSTALL_PREFIX_ESCAPED", ) +} else { + CMAKE_INCLUDE_DIR_IS_ABSOLUTE = True +} + +CMAKE_LIB_DIR = $$replace($$list($$[QT_INSTALL_LIBS]), \\\\, /)/ +contains(CMAKE_LIB_DIR, "$${CMAKE_QT_INSTALL_PREFIX_ESCAPED}.*") { + CMAKE_LIB_DIR = $$replace(CMAKE_LIB_DIR, "$$CMAKE_QT_INSTALL_PREFIX_ESCAPED", ) + CMAKE_RELATIVE_INSTALL_DIR = $$replace(CMAKE_LIB_DIR, "[^/]+", ..) + # We need to go up another two levels because the CMake files are + # installed in $${CMAKE_LIB_DIR}/cmake/Qt5$${CMAKE_MODULE_NAME} + CMAKE_RELATIVE_INSTALL_DIR = "$${CMAKE_RELATIVE_INSTALL_DIR}../../" +} else { + CMAKE_LIB_DIR_IS_ABSOLUTE = True +} + +CMAKE_BIN_DIR = $$replace($$list($$[QT_INSTALL_BINS]), \\\\, /)/ +contains(CMAKE_BIN_DIR, "$${CMAKE_QT_INSTALL_PREFIX_ESCAPED}.*") { + CMAKE_BIN_DIR = $$replace(CMAKE_BIN_DIR, "$$CMAKE_QT_INSTALL_PREFIX_ESCAPED", ) +} else { + CMAKE_BIN_DIR_IS_ABSOLUTE = True +} + +CMAKE_DATA_DIR = $$replace($$list($$[QT_INSTALL_DATA]), \\\\, /)/ # For the mkspecs +contains(CMAKE_DATA_DIR, "$${CMAKE_QT_INSTALL_PREFIX_ESCAPED}.*") { + CMAKE_DATA_DIR = $$replace(CMAKE_DATA_DIR, "$$CMAKE_QT_INSTALL_PREFIX_ESCAPED", ) +} else { + CMAKE_DATA_DIR_IS_ABSOLUTE = True +} static|staticlib:CMAKE_STATIC_TYPE = true diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in index 4873391..67598f4 100644 --- a/src/corelib/Qt5CoreConfigExtras.cmake.in +++ b/src/corelib/Qt5CoreConfigExtras.cmake.in @@ -1,12 +1,21 @@ get_filename_component(_qt5_corelib_install_prefix ${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR} ABSOLUTE) -# Required by default: -set(QT_QMAKE_EXECUTABLE \"${_qt5_corelib_install_prefix}/$$CMAKE_BIN_DIR/qmake$$CMAKE_BIN_SUFFIX\") -set(QT_MOC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$$CMAKE_BIN_DIR/moc$$CMAKE_BIN_SUFFIX\") -set(QT_RCC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$$CMAKE_BIN_DIR/rcc$$CMAKE_BIN_SUFFIX\") +!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE) +set(QT_QMAKE_EXECUTABLE \"${_qt5_corelib_install_prefix}/$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\") +set(QT_MOC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\") +set(QT_RCC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\") +!!ELSE +set(QT_QMAKE_EXECUTABLE \"$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\") +set(QT_MOC_EXECUTABLE \"$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\") +set(QT_RCC_EXECUTABLE \"$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\") +!!ENDIF +!!IF isEmpty(CMAKE_DATA_DIR_IS_ABSOLUTE) list(APPEND Qt5Core_INCLUDE_DIRS \"${_qt5_corelib_install_prefix}/mkspecs/default\") +!!ELSE +list(APPEND Qt5Core_INCLUDE_DIRS \"$${CMAKE_DATA_DIR}mkspecs/default\") +!!ENDIF !!IF !isEmpty(CMAKE_ADD_FPIE_FLAGS) set(Qt5Core_EXECUTABLE_COMPILE_FLAGS "-fPIE") @@ -32,14 +41,22 @@ endif() !!IF !isEmpty(debug_type) set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(Qt5::WinMain PROPERTIES - IMPORTED_LOCATION_DEBUG "${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}" +!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE) + IMPORTED_LOCATION_DEBUG "${_qt5_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}" +!!ELSE + IMPORTED_LOCATION_DEBUG "$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}" +!!ENDIF ) !!ENDIF !!IF !isEmpty(release_type) set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(Qt5::WinMain PROPERTIES - IMPORTED_LOCATION_RELEASE \"${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\" +!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE) + IMPORTED_LOCATION_RELEASE \"${_qt5_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\" +!!ELSE + IMPORTED_LOCATION_RELEASE \"$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\" +!!ENDIF ) !!ENDIF !!ENDIF diff --git a/src/widgets/Qt5WidgetsConfigExtras.cmake.in b/src/widgets/Qt5WidgetsConfigExtras.cmake.in index baf34b2..93d3c69 100644 --- a/src/widgets/Qt5WidgetsConfigExtras.cmake.in +++ b/src/widgets/Qt5WidgetsConfigExtras.cmake.in @@ -1,5 +1,8 @@ get_filename_component(_qt5_widgets_install_prefix ${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR} ABSOLUTE) -# Not Required by default: -set(QT_UIC_EXECUTABLE \"${_qt5_widgets_install_prefix}/$$CMAKE_BIN_DIR/uic$$CMAKE_BIN_SUFFIX\") +!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE) +set(QT_UIC_EXECUTABLE \"${_qt5_widgets_install_prefix}/$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\") +!!ELSE +set(QT_UIC_EXECUTABLE \"$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\") +!!ENDIF -- 2.7.4