Using pre-compiled headers with CMake

后端 未结 14 2170
刺人心
刺人心 2020-12-12 10:39

I have seen a few (old) posts on the \'net about hacking together some support for pre-compiled headers in CMake. They all seem a bit all-over the place and everyone has the

14条回答
  •  鱼传尺愫
    2020-12-12 11:17

    An example of usage precompiled header with cmake and Visual Studio 2015

    "stdafx.h", "stdafx.cpp" - precompiled header name.

    Put the following below in the root cmake file.

    if (MSVC)
        # For precompiled header.
        # Set 
        # "Precompiled Header" to "Use (/Yu)"
        # "Precompiled Header File" to "stdafx.h"
        set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Yustdafx.h /FIstdafx.h")
    endif()
    

    Put the following below in the project cmake file.

    "src" - a folder with source files.

    set_source_files_properties(src/stdafx.cpp
        PROPERTIES
        COMPILE_FLAGS "/Ycstdafx.h"
    )
    

提交回复
热议问题