From 77869a0567f4c2e029c679525b29da53433d8d9f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 22 Jul 2016 16:20:21 +0200 Subject: Factor target CPU to VC /MACHINE option translation --- build2/cxx/link.cxx | 32 +++++++++++++------------------- build2/cxx/msvc.cxx | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/build2/cxx/link.cxx b/build2/cxx/link.cxx index 34495b0..3ce99c9 100644 --- a/build2/cxx/link.cxx +++ b/build2/cxx/link.cxx @@ -1072,6 +1072,9 @@ namespace build2 void windows_rpath_assembly (file&, timestamp, bool scratch); + const char* + msvc_machine (const string& cpu); // msvc.cxx + target_state link:: perform_update (action a, target& xt) { @@ -1252,25 +1255,6 @@ namespace build2 string soname1, soname2; strings sargs; - if (cid == "msvc") - { - // Translate the compiler target CPU to the /MACHINE option value. - // This applies to both link.exe and lib.exe. - // - const string& tcpu (cast (rs["cxx.target.cpu"])); - - const char* m (tcpu == "i386" || tcpu == "i686" ? "/MACHINE:x86" : - tcpu == "x86_64" ? "/MACHINE:x64" : - tcpu == "arm" ? "/MACHINE:ARM" : - tcpu == "arm64" ? "/MACHINE:ARM64" : - nullptr); - - if (m == nullptr) - fail << "unable to translate CPU " << tcpu << " to /MACHINE"; - - args.push_back (m); - } - if (lt == otype::a) { if (cid == "msvc") ; @@ -1488,6 +1472,11 @@ namespace build2 if (verb < 3) args.push_back ("/NOLOGO"); + // Add /MACHINE. + // + args.push_back ( + msvc_machine (cast (rs["cxx.target.cpu"]))); + out = "/OUT:" + relt.string (); args.push_back (out.c_str ()); } @@ -1513,6 +1502,11 @@ namespace build2 if (lt == otype::s) args.push_back ("/DLL"); + // Add /MACHINE. + // + args.push_back ( + msvc_machine (cast (rs["cxx.target.cpu"]))); + // Unless explicitly enabled with /INCREMENTAL, disable // incremental linking (it is implicitly enabled if /DEBUG is // specified). The reason is the .ilk file: its name cannot be diff --git a/build2/cxx/msvc.cxx b/build2/cxx/msvc.cxx index ff91018..97d8fd5 100644 --- a/build2/cxx/msvc.cxx +++ b/build2/cxx/msvc.cxx @@ -20,6 +20,23 @@ namespace build2 { using namespace bin; + // Translate the target triplet CPU to lib.exe/link.exe /MACHINE option. + // + const char* + msvc_machine (const string& cpu) + { + const char* m (cpu == "i386" || cpu == "i686" ? "/MACHINE:x86" : + cpu == "x86_64" ? "/MACHINE:x64" : + cpu == "arm" ? "/MACHINE:ARM" : + cpu == "arm64" ? "/MACHINE:ARM64" : + nullptr); + + if (m == nullptr) + fail << "unable to translate CPU " << cpu << " to /MACHINE"; + + return m; + } + // Extract system library search paths from MSVC. // void -- cgit v1.1