[CMake] Using Intel C++ Compiler for Mixed C++/Objective-C++ Project on Mac OS X

Justin Holewinski shawmishrak at gmail.com
Sun Oct 4 19:55:30 EDT 2009


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?


Example:

test.c:

extern void foo();
int main()
{
  foo();
  return 0;
}

testobjc.m:

#include <stdio.h>
int foo()
{
  printf("foo()\n");
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
PROJECT(Test)
ADD_EXECUTABLE(test test.c testobjc.m)


Using GCC:

$ cmake ...
$ make
Scanning dependencies of target test
[ 50%] Building C object CMakeFiles/test.dir/test.c.o
[100%] Building CXX object CMakeFiles/test.dir/testobjc.m.o
Linking CXX executable test
[100%] Built target test


Using ICC:

$ CC=icc CXX=icpc cmake ...
$ make
Scanning dependencies of target test
[ 50%] Building C object CMakeFiles/test.dir/test.c.o
[100%] Building CXX object CMakeFiles/test.dir/testobjc.m.o
icpc: warning #10147: no action performed for specified file(s)
Linking CXX executable test
icpc: error #10236: File not found:  'CMakeFiles/test.dir/testobjc.m.o'
make[2]: *** [test] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2


"Desired":
$ icc -fast test.c -o test.o -c
$ gcc -O3 testobjc.m -o testobjc.o -c
$ icc -fast test.o testobjc.o -o test

-- 

Thanks,

Justin Holewinski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091004/148a59fa/attachment.htm>


More information about the CMake mailing list