diff --git a/CMake/cotire.cmake b/CMake/cotire.cmake index 1661cbb..3b9104c 100644 --- a/CMake/cotire.cmake +++ b/CMake/cotire.cmake @@ -45,7 +45,7 @@ if (NOT CMAKE_SCRIPT_MODE_FILE) endif() set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}") -set (COTIRE_CMAKE_MODULE_VERSION "1.5.2") +set (COTIRE_CMAKE_MODULE_VERSION "1.6.0") include(CMakeParseArguments) include(ProcessorCount) @@ -1146,8 +1146,16 @@ function (cotire_generate_prefix_header _prefixFile) return() endif() endif() + set (_prologue "") set (_epilogue "") - if (_option_COMPILER_ID MATCHES "Intel") + if (_option_COMPILER_ID MATCHES "Clang") + set (_prologue "#pragma clang system_header") + elseif (_option_COMPILER_ID MATCHES "GNU") + set (_prologue "#pragma GCC system_header") + elseif (_option_COMPILER_ID MATCHES "MSVC") + set (_prologue "#pragma warning(push, 0)") + set (_epilogue "#pragma warning(pop)") + elseif (_option_COMPILER_ID MATCHES "Intel") # Intel compiler requires hdrstop pragma to stop generating PCH file set (_epilogue "#pragma hdrstop") endif() @@ -1164,7 +1172,8 @@ function (cotire_generate_prefix_header _prefixFile) INCLUDE_PATH ${_option_INCLUDE_PATH} IGNORE_EXTENSIONS ${_option_IGNORE_EXTENSIONS} UNPARSED_LINES _unparsedLines) - cotire_generate_unity_source("${_prefixFile}" EPILOGUE ${_epilogue} LANGUAGE "${_option_LANGUAGE}" ${_selectedHeaders}) + cotire_generate_unity_source("${_prefixFile}" + PROLOGUE ${_prologue} EPILOGUE ${_epilogue} LANGUAGE "${_option_LANGUAGE}" ${_selectedHeaders}) set (_unparsedLinesFile "${_prefixFile}.log") if (_unparsedLines) if (COTIRE_VERBOSE OR NOT _selectedHeaders) @@ -1291,6 +1300,7 @@ function (cotire_add_pch_compilation_flags _language _compilerID _compilerVersio endif() elseif (_compilerID MATCHES "GNU|Clang") # GCC / Clang options used + # -w disable all warnings # -x specify the source language # -c compile but do not link # -o place output in file @@ -1298,10 +1308,10 @@ function (cotire_add_pch_compilation_flags _language _compilerID _compilerVersio set (_xLanguage_CXX "c++-header") if (_flags) # append to list - list (APPEND _flags "-x" "${_xLanguage_${_language}}" "-c" "${_prefixFile}" -o "${_pchFile}") + list (APPEND _flags "-w" "-x" "${_xLanguage_${_language}}" "-c" "${_prefixFile}" -o "${_pchFile}") else() # return as a flag string - set (_flags "-x ${_xLanguage_${_language}} -c \"${_prefixFile}\" -o \"${_pchFile}\"") + set (_flags "-w -x ${_xLanguage_${_language}} -c \"${_prefixFile}\" -o \"${_pchFile}\"") endif() elseif (_compilerID MATCHES "Intel") if (WIN32) @@ -1398,23 +1408,29 @@ function (cotire_add_prefix_pch_inclusion_flags _language _compilerID _compilerV # GCC options used # -include process include file as the first line of the primary source file # -Winvalid-pch warns if precompiled header is found but cannot be used + # -isystem treat include directory as a system directory (i.e., suppress warnings from headers) + get_filename_component(_prefixDir "${_prefixFile}" PATH) + get_filename_component(_prefixName "${_prefixFile}" NAME) if (_flags) # append to list - list (APPEND _flags "-include" "${_prefixFile}" "-Winvalid-pch") + list (APPEND _flags "-Winvalid-pch" "-isystem" "${_prefixDir}" "-include" "${_prefixName}") else() # return as a flag string - set (_flags "-include \"${_prefixFile}\" -Winvalid-pch") + set (_flags "-Winvalid-pch -isystem \"${_prefixDir}\" -include \"${_prefixName}\"") endif() elseif (_compilerID MATCHES "Clang") # Clang options used # -include process include file as the first line of the primary source file # -Qunused-arguments don't emit warning for unused driver arguments + # -isystem treat include directory as a system directory (i.e., suppress warnings from headers) + get_filename_component(_prefixDir "${_prefixFile}" PATH) + get_filename_component(_prefixName "${_prefixFile}" NAME) if (_flags) # append to list - list (APPEND _flags "-Qunused-arguments" "-include" "${_prefixFile}") + list (APPEND _flags "-Qunused-arguments" "-isystem" "${_prefixDir}" "-include" "${_prefixName}") else() # return as a flag string - set (_flags "-Qunused-arguments -include \"${_prefixFile}\"") + set (_flags "-Qunused-arguments -isystem \"${_prefixDir}\" -include \"${_prefixName}\"") endif() elseif (_compilerID MATCHES "Intel") if (WIN32) @@ -1705,8 +1721,11 @@ function (cotire_make_pch_file_path _language _targetSourceDir _target _pchFileV if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC") # MSVC uses the extension .pch added to the prefix header base name set (${_pchFileVar} "${_baseDir}/${_prefixFileBaseName}.pch" PARENT_SCOPE) - elseif (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang") - # GCC / Clang look for a precompiled header corresponding to the prefix header with the extension .gch appended + elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Clang") + # Clang looks for a precompiled header corresponding to the prefix header with the extension .pch appended + set (${_pchFileVar} "${_baseDir}/${_prefixFileName}.pch" PARENT_SCOPE) + elseif (CMAKE_${_language}_COMPILER_ID MATCHES "GNU") + # GCC looks for a precompiled header corresponding to the prefix header with the extension .gch appended set (${_pchFileVar} "${_baseDir}/${_prefixFileName}.gch" PARENT_SCOPE) elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Intel") # Intel uses the extension .pchi added to the prefix header base name @@ -1768,6 +1787,14 @@ function (cotire_get_prefix_header_dependencies _language _target _dependencySou # depend on target source files marked with custom COTIRE_DEPENDENCY property set (_dependencySources "") cotire_get_objects_with_property_on(_dependencySources COTIRE_DEPENDENCY SOURCE ${ARGN}) + if (CMAKE_${_language}_COMPILER_ID MATCHES "Clang") + # Clang raises a fatal error if a file is not found during preprocessing + # thus we depend on target's generated source files for prefix header generation + cotire_get_objects_with_property_on(_generatedSources GENERATED SOURCE ${ARGN}) + if (_generatedSources) + list (APPEND _dependencySources ${_generatedSources}) + endif() + endif() if (COTIRE_DEBUG AND _dependencySources) message (STATUS "${_language} ${_target} prefix header DEPENDS ${_dependencySources}") endif() @@ -2214,7 +2241,7 @@ function (cotire_choose_target_languages _targetSourceDir _target _targetLanguag set (${_targetLanguagesVar} "" PARENT_SCOPE) return() endif() - if (_targetUsePCH AND "${_language}" STREQUAL "C" OR "${_language}" STREQUAL "CXX") + if (_targetUsePCH AND "${_language}" MATCHES "^C|CXX$") cotire_check_precompiled_header_support("${_language}" "${_targetSourceDir}" "${_target}" _disableMsg) if (_disableMsg) set (_targetUsePCH FALSE) diff --git a/HISTORY.md b/HISTORY.md index 8279d2c..49bfa00 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,10 @@ +## 1.6.0 (2014-03-16) + +* suppress compiler warnings from precompiled headers. +* fix Clang compatibility issue with prefix header generation. +* use file extension `.pch` for precompiled headers generated with Clang. +* manual updates. + ## 1.5.2 (2014-01-17) * honor framework includes under OS X correctly. diff --git a/MANUAL.md b/MANUAL.md index 82c1bd3..8f6d24d 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -117,7 +117,7 @@ It consists of preprocessor include directives for each of the target source fil are included in the same order that is used in the CMake `add_executable` or `add_library` call. Header files are omitted. -This is a unity source generated for the example project under Mac OS X: +This is a unity source generated for the example project under OS X: #ifdef __cplusplus #include "/Users/sakra/Documents/cotire/src/main.cpp" @@ -152,16 +152,19 @@ Generating the prefix header from the unity source is much faster than running e target source file through the preprocessor, because the coalesced unity source will make the preprocessor process most header files only once. -This is a prefix header produced for the example project with Visual Studio 2008 under Windows: +This is a prefix header produced for the example project with Visual Studio 2013 under Windows 7: + #pragma warning(push, 0) #ifdef __cplusplus - #include "C:\Program Files\Microsoft Visual Studio 9.0\VC\include\string" - #include "C:\Program Files\Microsoft Visual Studio 9.0\VC\include\algorithm" - #include "C:\Program Files\Microsoft Visual Studio 9.0\VC\include\iostream" + #include "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\string" + #include "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\algorithm" + #include "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\iostream" #endif + #pragma warning(pop) -Generating the prefix file under Ubuntu Linux with GCC 4.6 yields the following result: +Generating the prefix file under Ubuntu 12.04 with GCC 4.6 yields the following result: + #pragma GCC system_header #ifdef __cplusplus #include "/usr/include/c++/4.6/string" #include "/usr/include/c++/4.6/algorithm" @@ -169,14 +172,17 @@ Generating the prefix file under Ubuntu Linux with GCC 4.6 yields the following #include "/usr/include/c++/4.6/iostream" #endif -Using Clang 3.1 under Mac OS X 10.7 this is the resulting prefix header: +Using Xcode 5.1 under OS X 10.9, this is the resulting prefix header: + #pragma clang system_header #ifdef __cplusplus - #include "/usr/include/c++/4.2.1/string" - #include "/usr/include/c++/4.2.1/iostream" - #include "/usr/include/c++/4.2.1/iterator" + #include "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/string" + #include "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/iostream" #endif +Besides include directives, cotire also adds compiler specific pragmas to the generated prefix +header to suppress compiler warnings upon inclusion. + Cotire attempts to produce a minimal list of header files by omitting header files indirectly included by a header that is already part of the prefix header. Header files with nonstandard file extensions like `.inl`, `.inc` of `.ipp` are omitted by default. @@ -200,11 +206,11 @@ build rule and generates the precompiled header as described in the documentatio [GCC][gcc_pch] and [Clang][clang_pch]. Cotire then modifies the `COMPILE_FLAGS` property of the target to force the inclusion of the prefix header. -Visual Studio C++ and Intel C++ use a [different approach][msvc_pch] to pre-compiling. Both compilers -require a host source file to generate the precompiled header as a side effect of producing an object file. -Cotire modifies the `COMPILE_FLAGS` of the first target source file to [generate][msvc_pch_create] -the precompiled header and then modifies the `COMPILE_FLAGS` of the remaining target source files -to [include][msvc_pch_use] the generated precompiled header. +Visual Studio C++ and Intel C++ use a [different approach][msvc_pch] to pre-compiling. Both +compilers require a host source file to generate the precompiled header as a side effect of +producing an object file. Cotire modifies the `COMPILE_FLAGS` of the first target source file to +[generate][msvc_pch_create] the precompiled header and then modifies the `COMPILE_FLAGS` of the +remaining target source files to [include][msvc_pch_use] the generated precompiled header. For Xcode projects generated with CMake, cotire completely hands off the pre-compilation of the prefix header and the inclusion of the precompiled header to the IDE. Cotire attaches a @@ -621,8 +627,8 @@ files ending with .m and .mm are excluded by default through the initial default ### Intel C++ -Intel C++ support has only been tested with [Intel C++ Composer XE 2013 for Linux][icc_linux] and may -not work with other platforms or versions. +Intel C++ support has only been tested with [Intel C++ Composer XE 2013 for Linux][icc_linux] and +may not work with other platforms or versions. The Intel compiler may issue incorrect warnings #672 (the command line options do not match those used when precompiled header was created) or #673 (the initial sequence of preprocessing directives