Attached Files | Add-support-for-making-Matlab-mex-files.patch [^] (6,730 bytes) 2009-07-07 08:55 [Show Content] [Hide Content]From 2d9965f2a1d146de291d4db7ed546aa27b435575 Mon Sep 17 00:00:00 2001
From: Matt McCormick (thewtex) <matt@mmmccormick.com>
Date: Mon, 29 Jun 2009 11:10:07 -0500
Subject: [PATCH] Add support for making Matlab mex files
For more information, see here.
http://www.cmake.org/Wiki/CMake:MatlabMex
---
Modules/CMakeCCompilerId.c.in | 7 ++++-
Modules/CMakeCXXCompilerId.cpp.in | 7 ++++-
Modules/Platform/Darwin-mex.cmake | 4 ++
Modules/Platform/Linux-mex.cmake | 10 ++++++
Modules/Platform/SunOS-mex.cmake | 4 ++
Modules/Platform/Windows-mex.cmake | 17 +++++++++++
Modules/Platform/mex.cmake | 55 ++++++++++++++++++++++++++++++++++++
7 files changed, 102 insertions(+), 2 deletions(-)
create mode 100644 Modules/Platform/Darwin-mex.cmake
create mode 100644 Modules/Platform/Linux-mex.cmake
create mode 100644 Modules/Platform/SunOS-mex.cmake
create mode 100644 Modules/Platform/Windows-mex.cmake
create mode 100644 Modules/Platform/mex.cmake
diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in
index 35d7df7..09fbe08 100644
--- a/Modules/CMakeCCompilerId.c.in
+++ b/Modules/CMakeCCompilerId.c.in
@@ -6,7 +6,12 @@
# define ID_VOID_MAIN
#endif
-#if defined(__INTEL_COMPILER) || defined(__ICC)
+/* Needs to come first because it is not a real compiler -- it just calls other
+ * compilers */
+#if defined(MATLAB_MEX_FILE)
+# define COMPILER_ID "mex"
+
+#elif defined(__INTEL_COMPILER) || defined(__ICC)
# define COMPILER_ID "Intel"
#elif defined(__BORLANDC__)
diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in
index fa2178c..2541578 100644
--- a/Modules/CMakeCXXCompilerId.cpp.in
+++ b/Modules/CMakeCXXCompilerId.cpp.in
@@ -5,7 +5,12 @@
# error "A C compiler has been selected for C++."
#endif
-#if defined(__COMO__)
+/* Needs to come first because it is not a real compiler -- it just calls other
+ * compilers */
+#if defined(MATLAB_MEX_FILE)
+# define COMPILER_ID "mex"
+
+#elif defined(__COMO__)
# define COMPILER_ID "Comeau"
#elif defined(__INTEL_COMPILER) || defined(__ICC)
diff --git a/Modules/Platform/Darwin-mex.cmake b/Modules/Platform/Darwin-mex.cmake
new file mode 100644
index 0000000..c9da181
--- /dev/null
+++ b/Modules/Platform/Darwin-mex.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexaci")
+set(CMAKE_SHARED_MODULE_SUFFIX ".mexaci")
+
+include(Platform/mex)
diff --git a/Modules/Platform/Linux-mex.cmake b/Modules/Platform/Linux-mex.cmake
new file mode 100644
index 0000000..404ef72
--- /dev/null
+++ b/Modules/Platform/Linux-mex.cmake
@@ -0,0 +1,10 @@
+if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
+ set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexa64")
+ set(CMAKE_SHARED_MODULE_SUFFIX ".mexa64")
+elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR ${CMAKE_SYSTEM_PROCESSOR}
+ STREQUAL "i686")
+ set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexglx")
+ set(CMAKE_SHARED_MODULE_SUFFIX ".mexglx")
+endif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
+
+include(Platform/mex)
diff --git a/Modules/Platform/SunOS-mex.cmake b/Modules/Platform/SunOS-mex.cmake
new file mode 100644
index 0000000..db6db8f
--- /dev/null
+++ b/Modules/Platform/SunOS-mex.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexs64")
+set(CMAKE_SHARED_MODULE_SUFFIX ".mexs64")
+
+include(Platform/mex)
diff --git a/Modules/Platform/Windows-mex.cmake b/Modules/Platform/Windows-mex.cmake
new file mode 100644
index 0000000..a2f934d
--- /dev/null
+++ b/Modules/Platform/Windows-mex.cmake
@@ -0,0 +1,17 @@
+if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
+ set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexw64")
+ set(CMAKE_SHARED_MODULE_SUFFIX ".mexw64")
+elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR ${CMAKE_SYSTEM_PROCESSOR}
+ STREQUAL "i686")
+ set(CMAKE_SHARED_LIBRARY_SUFFIX ".mexw32")
+ set(CMAKE_SHARED_MODULE_SUFFIX ".mexw32")
+endif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
+
+set(CMAKE_LINK_LIBRARY_SUFFIX "")
+if(MSYS)
+ set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ".dll.a" ".a" ".lib")
+endif(MSYS)
+
+include(Platform/mex)
+
diff --git a/Modules/Platform/mex.cmake b/Modules/Platform/mex.cmake
new file mode 100644
index 0000000..b0a90e9
--- /dev/null
+++ b/Modules/Platform/mex.cmake
@@ -0,0 +1,55 @@
+# For more information on MEX files, see
+# http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f29502.html
+
+set(CMAKE_LIBRARY_PATH_FLAG "-L")
+set(CMAKE_LINK_LIBRARY_FLAG "-l")
+set(CMAKE_INCLUDE_FLAG_C "-I")
+set(CMAKE_INCLUDE_FLAG_CXX "-I")
+set(CMAKE_INCLUDE_FLAG_C_SEP "")
+set(CMAKE_INCLUDE_FLAG_CXX_SEP "")
+
+# User should specify compiler flags in their mex options file, not with cmake
+# configuration!
+set(CMAKE_C_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_C_FLAGS_MINSIZEREL_INIT "")
+set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "")
+set(CMAKE_C_FLAGS_RELEASE_INIT "-O")
+set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "")
+set(CMAKE_SHARED_LIBRARY_C_FLAGS "")
+set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "")
+
+set(CMAKE_SHARED_LIBRARY_PREFIX "")
+set(CMAKE_SHARED_MODULE_PREFIX "")
+
+set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> -outdir <OBJECT_DIR> <FLAGS> -c <SOURCE>")
+set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> -outdir <OBJECT_DIR> <FLAGS> -c <SOURCE>")
+set(CMAKE_C_CREATE_SHARED_MODULE
+ "<CMAKE_C_COMPILER> <LINK_FLAGS> -output <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+if(UNIX)
+ set(CMAKE_CXX_CREATE_SHARED_MODULE
+ "<CMAKE_CXX_COMPILER> -cxx <LINK_FLAGS> -output <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+else(UNIX)
+ set(CMAKE_CXX_CREATE_SHARED_MODULE
+ "<CMAKE_CXX_COMPILER> <LINK_FLAGS> -output <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+endif(UNIX)
+set(CMAKE_C_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_MODULE})
+set(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_CXX_CREATE_SHARED_MODULE})
+
+# Only creates shared libraries to be loaded by Matlab, no standalone
+# executables.
+set(CMAKE_C_COMPILER_WORKS TRUE CACHE INTERNAL "Do not try with mex.")
+set(CMAKE_CXX_COMPILER_WORKS TRUE CACHE INTERNAL "Do not try with mex.")
+set(CMAKE_C_COMPILER_FORCED TRUE CACHE INTERNAL "")
+set(CMAKE_CXX_COMPILER_FORCED TRUE CACHE INTERNAL "")
+set(CMAKE_C_LINK_EXECUTABLE "ERROR: mex compiler only creates shared libraries/modules for Matlab")
+set(CMAKE_CXX_LINK_EXECUTABLE ${CMAKE_C_LINK_EXECUTABLE})
+set(CMAKE_C_CREATE_STATIC_LIBRARY ${CMAKE_C_LINK_EXECUTABLE})
+set(CMAKE_CXX_CREATE_STATIC_LIBRARY ${CMAKE_C_LINK_EXECUTABLE})
+
+# http://thread.gmane.org/gmane.comp.programming.tools.cmake.user/13192/focus=13277
+set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
+set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
+
--
1.6.3.3
|