Hi Again,<div><br></div><div>I narrowed the problem down to Clang not having Platform/Windows-Clang-{C,CXX}.cmake files.  If I add the following two files then everything starts to work as expected:</div><div><br></div><div>
Platform/Windows-Clang-C.cmake:</div><div><br></div><div><div><font face="&#39;courier new&#39;, monospace">if(MINGW)</font></div><div><font face="&#39;courier new&#39;, monospace">  include(Platform/Windows-GNU)</font></div>
<div><font face="&#39;courier new&#39;, monospace">  __windows_compiler_gnu(C)</font></div><div><font face="&#39;courier new&#39;, monospace">else()</font></div><div><font face="&#39;courier new&#39;, monospace">  # Chain to generic Windows configuration</font></div>
<div><font face="&#39;courier new&#39;, monospace">  include(Platform/Windows)</font></div><div><font face="&#39;courier new&#39;, monospace">endif()</font></div><div><br></div><div>Platform/Windows-Clang-CXX.cmake:</div>
<div><br></div><div><div><font face="&#39;courier new&#39;, monospace">if(MINGW)</font></div><div><font face="&#39;courier new&#39;, monospace">  include(Platform/Windows-GNU)</font></div><div><font face="&#39;courier new&#39;, monospace">  __windows_compiler_gnu(C)</font></div>
<div><font face="&#39;courier new&#39;, monospace">else()</font></div><div><font face="&#39;courier new&#39;, monospace">  # Chain to generic Windows configuration</font></div><div><font face="&#39;courier new&#39;, monospace">  include(Platform/Windows)</font></div>
<div><font face="&#39;courier new&#39;, monospace">endif()</font></div></div><div><br></div>This way, using Clang with MinGW will force GNU-style platform options instead of VS-style Windows options.  Is this more or less the &quot;right way&quot; to fix this in CMake?</div>
<div><br></div><div><br><div class="gmail_quote">On Wed, May 23, 2012 at 3:22 PM, Justin Holewinski <span dir="ltr">&lt;<a href="mailto:justin.holewinski@gmail.com" target="_blank">justin.holewinski@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi All,</div><div><br></div>I&#39;ve been trying out CMake for building C++ applications on Windows with Clang, using the MinGW headers/libraries.  This works fine, except if I need to pull in non-default system libraries that are included with MinGW, such as libpsapi.a (psapi.lib for VS).  For example, if I have the following CMakeLists.txt file:<div>

<br></div><div><div><font face="&#39;courier new&#39;, monospace">project(pstest1)</font></div><div><font face="&#39;courier new&#39;, monospace">add_executable(pstest1 pstest1.cpp)</font></div><div><font face="&#39;courier new&#39;, monospace">target_link_libraries(pstest1 psapi)</font></div>

<div><br></div><div><br></div><div>This fails with a linker error:</div><div><br></div><div><div><font face="&#39;courier new&#39;, monospace">Linking CXX executable pstest1.exe</font></div><div><font face="&#39;courier new&#39;, monospace">c:\projects\cmake-2.8.8-win32-x86\bin\cmake.exe -E cmake_link_script CMakeFiles\pstest1.dir\link.txt --verbose=1</font></div>

<div><font face="&#39;courier new&#39;, monospace">C:\projects\clang+llvm-3.1-i386-mingw32-EXPERIMENTAL\bin\clang++.exe       CMakeFiles/pstest1.dir/pstest1.obj  -o pst</font></div><div><font face="&#39;courier new&#39;, monospace">est1.exe  <b>-lpsapi.lib</b></font></div>

<div><font face="&#39;courier new&#39;, monospace"><b>c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lpsapi.lib</b></font></div><div><font face="&#39;courier new&#39;, monospace">collect2: ld returned 1 exit status</font></div>

<div><font face="&#39;courier new&#39;, monospace">clang++: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)</font></div><div><font face="&#39;courier new&#39;, monospace">mingw32-make[2]: *** [pstest1.exe] Error 1</font></div>

<div><font face="&#39;courier new&#39;, monospace">mingw32-make[2]: Leaving directory `C:/projects/mingw-tests/pstest1/build&#39;</font></div><div><font face="&#39;courier new&#39;, monospace">mingw32-make[1]: *** [CMakeFiles/pstest1.dir/all] Error 2</font></div>

<div><font face="&#39;courier new&#39;, monospace">mingw32-make[1]: Leaving directory `C:/projects/mingw-tests/pstest1/build&#39;</font></div><div><font face="&#39;courier new&#39;, monospace">mingw32-make: *** [all] Error 2</font></div>

</div><div><br></div><div><br></div><div>CMake seems to be using MSVC library naming conventions for Clang in MinGW mode, but also using the GCC-style -l flags for specifying libraries.  If I replace</div><div><br></div>
<div>
<span style="font-family:&#39;courier new&#39;,monospace">target_link_libraries(pstest1 psapi)</span></div><div><br></div><div>with</div><div><br></div><div><span style="font-family:&#39;courier new&#39;,monospace">target_link_libraries(pstest1 &quot;c:/MinGW/lib/libpsapi.a&quot;)</span>
</div><div><br></div><div>then everything works as expected (I got -lpsapi on the link line).  Interestingly, everything also works correctly if I use the default mingw32-gcc.exe compiler instead of clang.exe.  So this seems to be a CMake issue where it detects Clang but does not know how to properly pass GCC-style linker flags to Clang.</div>

<div><br></div><div>Any ideas?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>
</div>