<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi everyone,<br>
<br>
any feedback on this?<br>
As a summary, it's about adding the default include paths of GCC
to the variables "CMAKE_*_IMPLICIT_INCLUDE_DIRECTORIES" to avoid
CMake modules or scripts to mess up with them, more specifically
with their order.<br>
<br>
Cheers,<br>
Olivier</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 2018-11-3 21:41, Olivier Croquette
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:1411551936.1037251032.1541277663665.JavaMail.root@spooler8-g27.priv.proxad.net">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">p { margin: 0; }</style>
<div style="font-family: times new roman,new york,times,serif;
font-size: 12pt; color: #000000">
<div>Hi,</div>
<div><br>
</div>
<div>I got recently build errors when introducing external
dependencies in my project, the reason is that those
components re-add standard SYSTEM include search paths, which
changes the search order and causes #include_next to fail. The
typical error message is:</div>
<div><code class="cpp plain">C:\...\lib\gcc\x86_64-w64-mingw32\7.2.0\include\c++\cstdlib:75:
error: stdlib.h: No such file or directory</code>
<div class="container">
<div class="line number2 index1 alt1"><code class="cpp
plain">at #include_next <br>
</code></div>
<div class="line number2 index1 alt1"><code class="cpp
plain"><br>
</code></div>
<div class="line number2 index1 alt1"><code class="cpp
plain"></code></div>
</div>
</div>
<div>
<div>The following bug report against GCC describes the same
issue independently of CMake, and apparently no improvement
is to be expected from the compiler itself:</div>
<div><br>
</div>
<a class="moz-txt-link-freetext" href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129</a></div>
<div><br>
</div>
<div>So I rolled up my sleeves and implemented the following
solution in CMake. It calls the preprocessor to get the
standard include search paths and adds them to
CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES and
CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES.</div>
<div>When a project or an external component tries to add them,
CMake ignores this, and the search order stays unharmed.</div>
<br>
<div>if("${CMAKE_MINGW_IMPLICIT_INCLUDE_DIRECTORIES}" STREQUAL
"")<br>
# Run the preprocessor in verbose mode on an empty input<br>
execute_process(<br>
COMMAND<br>
"${CMAKE_CXX_COMPILER}"<br>
"-E"<br>
"-Wp,-v"<br>
"-"<br>
INPUT_FILE "NUL" # Special Windows file, equivalent to
/dev/null<br>
OUTPUT_VARIABLE _mingw_cpp_out # Capture stdout<br>
ERROR_VARIABLE _mingw_cpp_error # Capture stderr<br>
)<br>
<br>
# Create list of lines from stderr output:<br>
string(REGEX REPLACE ";" "\\\\;" _mingw_cpp_error
"${_mingw_cpp_error}")<br>
string(REGEX REPLACE "\n" ";" _mingw_cpp_error
"${_mingw_cpp_error}")<br>
<br>
# Look for this text block and gather the paths:<br>
# #include search starts here:<br>
#
C:/..../bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/include<br>
#
C:/..../bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/include-fixed<br>
#
C:/..../bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/include<br>
# End of search list.<br>
set(_mingw_cpp_list)<br>
foreach(_mingw_cpp_line ${_mingw_cpp_error})<br>
if("${_mingw_cpp_line}" MATCHES "#include search
starts here:")<br>
# Block starts<br>
set(_mingw_cpp_state "ON")<br>
elseif("${_mingw_cpp_line}" MATCHES "End of search
list.")<br>
# Block ends<br>
set(_mingw_cpp_state "OFF")<br>
elseif("${_mingw_cpp_state}")<br>
# Within block<br>
# Clean up and beautify the path<br>
string(STRIP "${_mingw_cpp_line}" _mingw_cpp_line)<br>
get_filename_component(_mingw_cpp_line
${_mingw_cpp_line} REALPATH)<br>
list(APPEND _mingw_cpp_list ${_mingw_cpp_line})<br>
endif()<br>
endforeach()<br>
<br>
# Set the list in the cache, so that we don't have to run
the external process again<br>
set(CMAKE_MINGW_IMPLICIT_INCLUDE_DIRECTORIES
${_mingw_cpp_list} CACHE INTERNAL "List of MinGW system
include paths")<br>
endif()<br>
<br>
list(APPEND CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES
${CMAKE_MINGW_IMPLICIT_INCLUDE_DIRECTORIES})<br>
list(APPEND CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
${CMAKE_MINGW_IMPLICIT_INCLUDE_DIRECTORIES})</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div><br>
</div>
<div>My question is: shouldn't this be done within the
standard CMake distribution, when using any GCC based
compiler?<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Olivier</div>
<div><br>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
</blockquote>
</body>
</html>