diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e331a9ec07bb2a7..0dc4a580de3a93b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5516,7 +5516,7 @@ def start_no_unused_arguments : Flag<["--"], "start-no-unused-arguments">, def static_libgcc : Flag<["-"], "static-libgcc">; def static_libstdcxx : Flag<["-"], "static-libstdc++">; def static : Flag<["-", "--"], "static">, Group, - Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>, + Visibility<[ClangOption, CLOption, DXCOption, FlangOption, MarcoOption]>, Flags<[NoArgumentUnused]>; def std_default_EQ : Joined<["-"], "std-default=">; def std_EQ : Joined<["-", "--"], "std=">, diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index afd28e4094161bb..cbdf883174c72af 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -14,11 +14,6 @@ if(WIN32) set(system_libs version) endif() -add_compile_definitions( - MARCO_LIBS_PATH=${MARCORuntime_LIBS_PATH} - MARCO_DEPENDENCIES_LIBS_PATH=${MARCORuntime_DEPENDENCIES_LIB_PATHS} - MARCO_LINK_EXTRA_FLAGS=${MARCORuntime_EXTRA_LINK_ARGS}) - add_clang_library(clangDriver Action.cpp Compilation.cpp diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 2fea3c3a4b4282c..200414578d23818 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1354,8 +1354,16 @@ void tools::addMarcoLinkerArgs( const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) { + bool staticBuild = Args.hasArg(options::OPT_static); + + if (staticBuild) { + CmdArgs.push_back("-Bstatic"); + } else { + CmdArgs.push_back("-Bdynamic"); + } + // Get the name of the requested solver. - auto solverString = + auto solver = Args.getLastArgValue(options::OPT_solver, "euler-forward"); // Add the main function to the simulation, if not explicitly discarded. @@ -1367,41 +1375,80 @@ void tools::addMarcoLinkerArgs( CmdArgs.push_back("-lMARCORuntimeSimulation"); // Add the libraries of the solver. - if (solverString == "euler-forward") { + if (solver == "euler-forward") { CmdArgs.push_back("-lMARCORuntimeDriverEulerForward"); CmdArgs.push_back("-lMARCORuntimeSolverEulerForward"); - } else if (solverString == "ida") { + } else if (solver == "ida") { CmdArgs.push_back("-lMARCORuntimeDriverIDA"); CmdArgs.push_back("-lMARCORuntimeSolverIDA"); - } else if (solverString == "rk4" || - solverString.starts_with("rk-")) { + } else if (solver == "rk4" || + solver.starts_with("rk-")) { CmdArgs.push_back("-lMARCORuntimeDriverRungeKutta"); CmdArgs.push_back("-lMARCORuntimeSolverRungeKutta"); } - // Add the remaining runtime libraries. - CmdArgs.push_back("-lMARCORuntimeSolverKINSOL"); - CmdArgs.push_back("-lMARCORuntimeSolverSUNDIALS"); - CmdArgs.push_back("-lMARCORuntimePrinterCSV"); + // Add the Modelica support library. CmdArgs.push_back("-lMARCORuntimeSupport"); + + // Add the printer library. + CmdArgs.push_back("-lMARCORuntimePrinterCSV"); + + // Add the solver libraries. + if (staticBuild) { + CmdArgs.push_back("-lMARCORuntimeSolverKINSOL_static"); + CmdArgs.push_back("-lMARCORuntimeSolverSUNDIALS_static"); + } else { + CmdArgs.push_back("-lMARCORuntimeSolverKINSOL"); + CmdArgs.push_back("-lMARCORuntimeSolverSUNDIALS"); + } + + // Add the utility libraries. CmdArgs.push_back("-lMARCORuntimeCLI"); CmdArgs.push_back("-lMARCORuntimeModeling"); CmdArgs.push_back("-lMARCORuntimeMultithreading"); - CmdArgs.push_back("-lMARCORuntimeProfiling"); - if (solverString == "ida") { - CmdArgs.push_back("-lsundials_ida"); + if (staticBuild) { + CmdArgs.push_back("-lMARCORuntimeProfiling_static"); + } else { + CmdArgs.push_back("-lMARCORuntimeProfiling"); } - CmdArgs.push_back("-lsundials_kinsol"); - CmdArgs.push_back("-lsundials_nvecserial"); - CmdArgs.push_back("-lsundials_sunlinsolklu"); - CmdArgs.push_back("-lklu"); + // Add the options libraries. + if (staticBuild) { + CmdArgs.push_back("-lMARCORuntimeOptionsCSVPrinter_static"); + + if (solver == "euler-forward") { + CmdArgs.push_back("-lMARCORuntimeOptionsEulerForward_static"); + } else if (solver == "ida") { + CmdArgs.push_back("-lMARCORuntimeOptionsIDA_static"); + } else if (solver == "rk4" || + solver.starts_with("rk-")) { + CmdArgs.push_back("-lMARCORuntimeOptionsRungeKutta_static"); + } + + CmdArgs.push_back("-lMARCORuntimeOptionsKINSOL_static"); - // Utility functions provided by MLIR. - CmdArgs.push_back("-lmlir_c_runner_utils"); + CmdArgs.push_back("-lMARCORuntimeOptionsMultithreading_static"); + CmdArgs.push_back("-lMARCORuntimeOptionsSimulation_static"); + } else { + CmdArgs.push_back("-lMARCORuntimeOptionsCSVPrinter"); + + if (solver == "euler-forward") { + CmdArgs.push_back("-lMARCORuntimeOptionsEulerForward"); + } else if (solver == "ida") { + CmdArgs.push_back("-lMARCORuntimeOptionsIDA"); + } else if (solver == "rk4" || + solver.starts_with("rk-")) { + CmdArgs.push_back("-lMARCORuntimeOptionsRungeKutta"); + } + + CmdArgs.push_back("-lMARCORuntimeOptionsKINSOL"); + + CmdArgs.push_back("-lMARCORuntimeOptionsMultithreading"); + CmdArgs.push_back("-lMARCORuntimeOptionsSimulation"); + } - // Standard libraries. + // System libraries. CmdArgs.push_back("-lm"); CmdArgs.push_back("-lpthread");