forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindPCHSupport.cmake
84 lines (74 loc) · 3.07 KB
/
FindPCHSupport.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# This code is based on
# http://rosegarden.svn.sourceforge.net/viewvc/rosegarden/trunk/rosegarden/cmake_admin/FindPCHSupport.cmake?revision=7699&view=markup
#
# - Try to find precompiled headers support for GCC 3.4 and 4.x
# Once done this will define:
#
# Variable:
# PCHSupport_FOUND
#
# Macro:
# ADD_PRECOMPILED_HEADER
IF(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
EXEC_PROGRAM(
${CMAKE_CXX_COMPILER}
ARGS --version
OUTPUT_VARIABLE _compiler_output)
STRING(REGEX REPLACE ".* ([0-9]\\.[0-9]\\.[0-9]) .*" "\\1"
gcc_compiler_version ${_compiler_output})
IF(gcc_compiler_version MATCHES "[4-9]\\.[0-9]\\.[0-9]")
SET(PCHSupport_FOUND TRUE)
MESSAGE("-- Found PCH Support: gcc compiler version is " ${gcc_compiler_version})
ELSE()
IF(gcc_compiler_version MATCHES "3\\.4\\.[0-9]")
SET(PCHSupport_FOUND TRUE)
MESSAGE("-- Found PCH Support: gcc compiler version is " ${gcc_compiler_version})
ENDIF()
ENDIF()
ELSEIF(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
SET(PCHSupport_FOUND TRUE)
ENDIF()
MACRO(ADD_PRECOMPILED_HEADER _targetName _input)
GET_FILENAME_COMPONENT(_name ${_input} NAME)
SET(_source "${CMAKE_CURRENT_SOURCE_DIR}/${_input}")
SET(_output "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch")
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
SET(_compiler_FLAGS ${${_flags_var_name}})
GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)
SET(_system_INCLUDE_DIRS "/usr/include" "/usr/local/include")
FOREACH(item ${_directory_flags})
# Exclude standard paths
LIST(FIND _system_INCLUDE_DIRS ${item} _index)
IF(NOT ${_index} EQUAL -1)
continue()
ENDIF(NOT ${_index} EQUAL -1)
IF(item MATCHES "^${PROJECT_SOURCE_DIR}.*")
# Directories in this project
IF(item MATCHES "^${PROJECT_SOURCE_DIR}/third-party.*")
# third-party
LIST(APPEND _compiler_FLAGS "-isystem ${item}")
ELSE(item MATCHES "^${PROJECT_SOURCE_DIR}/third-party.*")
# Our own directories
LIST(APPEND _compiler_FLAGS "-I ${item}")
ENDIF(item MATCHES "^${PROJECT_SOURCE_DIR}/third-party.*")
ELSE(item MATCHES "^${PROJECT_SOURCE_DIR}.*")
# All of others
LIST(APPEND _compiler_FLAGS "-isystem ${item}")
ENDIF(item MATCHES "^${PROJECT_SOURCE_DIR}.*")
ENDFOREACH(item)
GET_DIRECTORY_PROPERTY(_directory_flags COMPILE_DEFINITIONS)
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS "-D${item}")
ENDFOREACH(item)
SEPARATE_ARGUMENTS(_compiler_FLAGS)
MESSAGE("Precompile header file " ${_source} " into " ${_output})
ADD_CUSTOM_COMMAND(
OUTPUT ${_output}
COMMAND ${CMAKE_CXX_COMPILER}
${_compiler_FLAGS}
-x c++-header
-o ${_output} ${_source}
MAIN_DEPENDENCY ${_source})
ADD_CUSTOM_TARGET(${_targetName}_gch DEPENDS ${_output})
ADD_DEPENDENCIES(${_targetName} ${_targetName}_gch)
ENDMACRO(ADD_PRECOMPILED_HEADER)