How to use precompiled headers in CMake project in QtCreator?



  • Hello
    I trying to use a precompiled header in CMake project. Cotire module provides this functionality. But QtCreator code highlight not working. It seems that QtCreator code model doesn't parse a precompiled header.
    Here is a project example:

    CMakeLists.txt

    include(cotire)
    
    cmake_minimum_required(VERSION 2.8)
    
    project(temp_cmake_precompiled)
    add_executable(${PROJECT_NAME} "main.cpp")
    
    set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "Stable.h")
    cotire(${PROJECT_NAME})
    

    main.cpp

    int main()
    {
      std::vector<int> vec;
      std::cout << vec.size() << std::endl;
      return 0;
    }
    
    

    Stable.h

    #include <iostream>
    #include <vector>
    

    Both Clang and built-in code model have this problem. But build performs with success.
    In dialog Tools -> C++ -> Inspect C++ Code Model... a Precompiled headers key is set to <None>.

    May be there is a different way to specify a precompiled header in CMake project that QtCreator can resolve?

    QtCreator 4.8.2



  • I ran into the same problem and this problem is very very annoying during daily work.

    I filed a bug report for that issue.


 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.