<br>I have a project that uses both plain C++ (.cpp) and Objective-C++ (.mm) sources on Mac OS X. Using the Makefile target of CMake with the native compiler (GCC) works fine. However, the Intel C++ compiler does not handle Objective-C++ sources so CMake-generated Makefiles fail when the .mm files are passed to icc/icpc (the Intel C and C++ compilers). Is there a way to instruct CMake to use icc/icpc for C/C++ files and gcc for .m/.mm files? Can this be done without having to rewrite ADD_EXECUTABLE and other macros?<br>
<br><br>Example:<br><br>test.c:<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">extern void foo();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">int main()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> foo();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return 0;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br><br>testobjc.m:<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <stdio.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">int foo()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf("foo()\n");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br><br>CMakeLists.txt:<br><br><span style="font-family: courier new,monospace;">cmake_minimum_required(VERSION 2.6)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">PROJECT(Test)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">ADD_EXECUTABLE(test test.c testobjc.m)</span><br><br>
<br>Using GCC:<br><br><span style="font-family: courier new,monospace;">$ cmake ...</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$ make</span><br style="font-family: courier new,monospace;" clear="all">
<span style="font-family: courier new,monospace;">Scanning dependencies of target test</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">[ 50%] Building C object CMakeFiles/test.dir/test.c.o</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">[100%] Building CXX object CMakeFiles/test.dir/testobjc.m.o</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Linking CXX executable test</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">[100%] Built target test</span><br><br><br>Using ICC:<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$ CC=icc CXX=icpc cmake ...</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">$ make</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Scanning dependencies of target test</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">[ 50%] Building C object CMakeFiles/test.dir/test.c.o</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">[100%] Building CXX object CMakeFiles/test.dir/testobjc.m.o</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">icpc: warning #10147: no action performed for specified file(s)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Linking CXX executable test</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">icpc: error #10236: File not found: 'CMakeFiles/test.dir/testobjc.m.o'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">make[2]: *** [test] Error 1</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">make[1]: *** [CMakeFiles/test.dir/all] Error 2</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">make: *** [all] Error 2</span><br>
<br><br>"Desired":<br><span style="font-family: courier new,monospace;">$ icc -fast test.c -o test.o -c</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$ gcc -O3 testobjc.m -o testobjc.o -c</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">$ icc -fast test.o testobjc.o -o test</span><br><br>-- <br><br>Thanks,<br><br>Justin Holewinski<br>