简体   繁体   English

Clang CMAKE预编译头

[英]Clang CMAKE Precompiled headers

I've found a lot of examples on how to use precompiled headers for MSVC, but I can't seem to find any examples using clang. 我已经找到了很多有关如何使用MSVC的预编译头的示例,但是我似乎找不到使用clang的任何示例。 From this SO post I can see the clang commands but I'm wondering how they translate into cmake: 从这篇SO帖子中,我可以看到clang命令,但是我想知道它们如何转换为cmake:

Decrease clang compile time with precompiled headers 使用预编译的头文件减少clang编译时间

to create pre-compiled header include all the headers you don't change > > into Query.h and use: 要创建预编译的标头,请将所有未更改的标头>>放入Query.h并使用:

clang -cc1 Query.h -emit-pch -o Query.h.pch to use the pre-compiled header type: clang -cc1 Query.h -emit-pch -o Query.h.pch使用预编译的标头类型:

clang -cc1 -include-pch Query.h.pch Query.cpp -shared -o libquery.so; clang -cc1 -include-pch Query.h.pch Query.cpp -shared -o libquery.so; Query.cpp needs to include Query.h Query.cpp需要包含Query.h

Edit: Using clang 6 and cmake 3.11.2 编辑:使用c 6和cmake 3.11.2

Found a solution that worked for me: 找到了一个对我有用的解决方案:

# add the pch custom target as a dependency
add_dependencies(corelib pch)

# add the flag
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include-pch ${CMAKE_CURRENT_BINARY_DIR}/stdinc.hpp.pch")

# target
add_custom_target(pch COMMAND clang -x c++-header ${CMAKE_CURRENT_SOURCE_DIR}/src/stdinc.hpp -o ${CMAKE_CURRENT_BINARY_DIR}/stdinc.hpp.pch)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM