Mercurial > dedupe
comparison PrecompiledHeader.cmake @ 0:a3834af36579
Working with memory backend.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 20 Aug 2012 15:49:48 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a3834af36579 |
|---|---|
| 1 # Macro for setting up precompiled headers. Usage: | |
| 2 # | |
| 3 # add_precompiled_header(target header.h [FORCEINCLUDE]) | |
| 4 # | |
| 5 # MSVC: A source file with the same name as the header must exist and | |
| 6 # be included in the target (E.g. header.cpp). | |
| 7 # | |
| 8 # MSVC: Add FORCEINCLUDE to automatically include the precompiled | |
| 9 # header file from every source file. | |
| 10 # | |
| 11 # GCC: The precompiled header is always automatically included from | |
| 12 # every header file. | |
| 13 MACRO(ADD_PRECOMPILED_HEADER _targetName _input) | |
| 14 GET_FILENAME_COMPONENT(_inputWe ${_input} NAME_WE) | |
| 15 SET(pch_source ${_inputWe}.cpp) | |
| 16 FOREACH(arg ${ARGN}) | |
| 17 IF(arg STREQUAL FORCEINCLUDE) | |
| 18 SET(FORCEINCLUDE ON) | |
| 19 ELSE(arg STREQUAL FORCEINCLUDE) | |
| 20 SET(FORCEINCLUDE OFF) | |
| 21 ENDIF(arg STREQUAL FORCEINCLUDE) | |
| 22 ENDFOREACH(arg) | |
| 23 | |
| 24 IF(MSVC) | |
| 25 GET_TARGET_PROPERTY(sources ${_targetName} SOURCES) | |
| 26 SET(_sourceFound FALSE) | |
| 27 FOREACH(_source ${sources}) | |
| 28 SET(PCH_COMPILE_FLAGS "") | |
| 29 IF(_source MATCHES \\.\(cc|cxx|cpp\)$) | |
| 30 GET_FILENAME_COMPONENT(_sourceWe ${_source} NAME_WE) | |
| 31 IF(_sourceWe STREQUAL ${_inputWe}) | |
| 32 SET(PCH_COMPILE_FLAGS "${PCH_COMPILE_FLAGS} /Yc${_input}") | |
| 33 SET(_sourceFound TRUE) | |
| 34 ELSE(_sourceWe STREQUAL ${_inputWe}) | |
| 35 SET(PCH_COMPILE_FLAGS "${PCH_COMPILE_FLAGS} /Yu${_input}") | |
| 36 IF(FORCEINCLUDE) | |
| 37 SET(PCH_COMPILE_FLAGS "${PCH_COMPILE_FLAGS} /FI${_input}") | |
| 38 ENDIF(FORCEINCLUDE) | |
| 39 ENDIF(_sourceWe STREQUAL ${_inputWe}) | |
| 40 SET_SOURCE_FILES_PROPERTIES(${_source} PROPERTIES COMPILE_FLAGS "${PCH_COMPILE_FLAGS}") | |
| 41 ENDIF(_source MATCHES \\.\(cc|cxx|cpp\)$) | |
| 42 ENDFOREACH() | |
| 43 IF(NOT _sourceFound) | |
| 44 MESSAGE(FATAL_ERROR "A source file for ${_input} was not found. Required for MSVC builds.") | |
| 45 ENDIF(NOT _sourceFound) | |
| 46 ENDIF(MSVC) | |
| 47 | |
| 48 IF(CMAKE_COMPILER_IS_GNUCXX) | |
| 49 GET_FILENAME_COMPONENT(_name ${_input} NAME) | |
| 50 SET(_source "${CMAKE_CURRENT_SOURCE_DIR}/${_input}") | |
| 51 SET(_outdir "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch") | |
| 52 MAKE_DIRECTORY(${_outdir}) | |
| 53 SET(_output "${_outdir}/.c++") | |
| 54 | |
| 55 STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name) | |
| 56 SET(_compiler_FLAGS ${${_flags_var_name}}) | |
| 57 | |
| 58 GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES) | |
| 59 FOREACH(item ${_directory_flags}) | |
| 60 LIST(APPEND _compiler_FLAGS "-I${item}") | |
| 61 ENDFOREACH(item) | |
| 62 | |
| 63 GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS) | |
| 64 LIST(APPEND _compiler_FLAGS ${_directory_flags}) | |
| 65 | |
| 66 SEPARATE_ARGUMENTS(_compiler_FLAGS) | |
| 67 MESSAGE("${CMAKE_CXX_COMPILER} -DPCHCOMPILE ${_compiler_FLAGS} -x c++-header -o {_output} ${_source}") | |
| 68 ADD_CUSTOM_COMMAND( | |
| 69 OUTPUT ${_output} | |
| 70 COMMAND ${CMAKE_CXX_COMPILER} ${_compiler_FLAGS} -x c++-header -o ${_output} ${_source} | |
| 71 DEPENDS ${_source} ) | |
| 72 ADD_CUSTOM_TARGET(${_targetName}_gch DEPENDS ${_output}) | |
| 73 ADD_DEPENDENCIES(${_targetName} ${_targetName}_gch) | |
| 74 SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "-include ${_name} -Winvalid-pch") | |
| 75 ENDIF(CMAKE_COMPILER_IS_GNUCXX) | |
| 76 ENDMACRO() |
