diff --git a/CMakeLists.txt b/CMakeLists.txt index 114a01d9a24..162b0a9aeee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,9 @@ set(CMAKE_CXX_EXTENSIONS OFF) qtc_handle_sccache_support() +option(BUILD_LINK_WITH_QT "Link with Qt from the parent Qt Creator" OFF) +qtc_link_with_qt() + option(WITH_TESTS "Build Tests" OFF) add_feature_info("Build tests" ${WITH_TESTS} "") option(WITH_DEBUG_CMAKE "Enabled CMake project debugging functionality (e.g. source file disk checking)" OFF) diff --git a/cmake/QtCreatorAPIInternal.cmake b/cmake/QtCreatorAPIInternal.cmake index 7ebd2d31d71..026647f56d8 100644 --- a/cmake/QtCreatorAPIInternal.cmake +++ b/cmake/QtCreatorAPIInternal.cmake @@ -125,6 +125,24 @@ function(qtc_handle_sccache_support) endif() endfunction() +function(qtc_link_with_qt) + # When building with Qt Creator 4.15+ do the "Link with Qt..." automatically + if (BUILD_LINK_WITH_QT AND DEFINED CMAKE_PROJECT_INCLUDE_BEFORE) + get_filename_component(auto_setup_dir "${CMAKE_PROJECT_INCLUDE_BEFORE}" DIRECTORY) + set(qt_creator_ini "${auto_setup_dir}/../QtProject/QtCreator.ini") + if (EXISTS "${qt_creator_ini}") + file(STRINGS "${qt_creator_ini}" install_settings REGEX "^InstallSettings=.*$") + if (install_settings) + string(REPLACE "InstallSettings=" "" install_settings "${install_settings}") + else() + file(TO_CMAKE_PATH "${auto_setup_dir}/.." install_settings) + endif() + file(WRITE ${CMAKE_BINARY_DIR}/${_IDE_DATA_PATH}/QtProject/QtCreator.ini + "[Settings]\nInstallSettings=${install_settings}") + endif() + endif() +endfunction() + function(qtc_enable_release_for_debug_configuration) if (MSVC) string(REPLACE "/Od" "/O2" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")