Add a cl.exe compatible driver mode
authorHans Wennborg <hans@hanshq.net>
Fri, 19 Jul 2013 20:33:20 +0000 (20:33 +0000)
committerHans Wennborg <hans@hanshq.net>
Fri, 19 Jul 2013 20:33:20 +0000 (20:33 +0000)
The mode doesn't actually do anything yet, but this provides a
way to get into it.

llvm-svn: 186720

clang/include/clang/Driver/Driver.h
clang/lib/Driver/Driver.cpp
clang/test/Driver/cl.c [new file with mode: 0644]
clang/test/lit.cfg
clang/tools/driver/CMakeLists.txt
clang/tools/driver/clang_symlink.cmake
clang/tools/driver/driver.cpp

index 18d81e1..7633ae6 100644 (file)
@@ -54,7 +54,8 @@ class Driver {
   enum DriverMode {
     GCCMode,
     GXXMode,
-    CPPMode
+    CPPMode,
+    CLMode
   } Mode;
 
 public:
index 0c3f6ca..98b87be 100644 (file)
@@ -96,6 +96,7 @@ void Driver::ParseDriverMode(ArrayRef<const char *> Args) {
         .Case("gcc", GCCMode)
         .Case("g++", GXXMode)
         .Case("cpp", CPPMode)
+        .Case("cl",  CLMode)
         .Default(~0U);
 
     if (M != ~0U)
diff --git a/clang/test/Driver/cl.c b/clang/test/Driver/cl.c
new file mode 100644 (file)
index 0000000..c527313
--- /dev/null
@@ -0,0 +1,3 @@
+// RUN: %clang_cl -fsyntax-only -c %s
+
+void f();
index 46fc5b5..a5bb350 100644 (file)
@@ -204,7 +204,8 @@ config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s'
                                  getClangBuiltinIncludeDir(config.clang))) )
 config.substitutions.append( ('%clang_cpp', ' ' + config.clang +
                               ' --driver-mode=cpp '))
-
+config.substitutions.append( ('%clang_cl', ' ' + config.clang +
+                              ' --driver-mode=cl '))
 config.substitutions.append( ('%clangxx', ' ' + config.clang +
                               ' --driver-mode=g++ '))
 config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
@@ -227,6 +228,9 @@ config.substitutions.append(
 config.substitutions.append(
     (' %clang-cpp ',
      """*** invalid substitution, use '%clang_cpp'. ***""") )
+config.substitutions.append(
+    (' %clang-cl ',
+     """*** invalid substitution, use '%clang_cl'. ***""") )
 
 ###
 
index 3dac964..77c819e 100644 (file)
@@ -76,8 +76,16 @@ add_custom_command(TARGET clang POST_BUILD
 set_property(DIRECTORY APPEND
   PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clang_pp})
 
+# Create the clang-cl symlink in the build directory.
+set(clang_cl "${LLVM_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}")
+add_custom_command(TARGET clang POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E ${CLANGXX_LINK_OR_COPY} "${clang_binary}" "${clang_cl}")
+
+set_property(DIRECTORY APPEND
+  PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clang_cl})
+
 install(TARGETS clang
   RUNTIME DESTINATION bin)
 
-# Create the clang++ symlink at installation time.
+# Create the clang++ and clang-cl symlinks at installation time.
 install(SCRIPT clang_symlink.cmake -DCMAKE_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\")
index c7341cb..9204f9f 100644 (file)
@@ -19,9 +19,16 @@ endif()
 set(bindir "${CLANGXX_DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/")
 set(clang "clang${EXECUTABLE_SUFFIX}")
 set(clangxx "clang++${EXECUTABLE_SUFFIX}")
+set(clang_cl "clang-cl${EXECUTABLE_SUFFIX}")
 
 message("Creating clang++ executable based on ${clang}")
 
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E ${CLANGXX_LINK_OR_COPY} "${clang}" "${clangxx}"
   WORKING_DIRECTORY "${bindir}")
+
+message("Creating clang-cl executable based on ${clang}")
+
+execute_process(
+  COMMAND "${CMAKE_COMMAND}" -E ${CLANGXX_LINK_OR_COPY} "${clang}" "${clang_cl}"
+  WORKING_DIRECTORY "${bindir}")
index b3f2a83..7ad3d0a 100644 (file)
@@ -219,8 +219,10 @@ static void ParseProgName(SmallVectorImpl<const char *> &ArgVector,
     { "clang-cpp", "--driver-mode=cpp" },
     { "clang-g++", "--driver-mode=g++" },
     { "clang-gcc", 0 },
+    { "clang-cl",  "--driver-mode=cl"  },
     { "cc",        0 },
     { "cpp",       "--driver-mode=cpp" },
+    { "cl" ,       "--driver-mode=cl"  },
     { "++",        "--driver-mode=g++" },
   };
   std::string ProgName(llvm::sys::path::stem(ArgVector[0]));