CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
ar_archiver.hpp
1#ifndef CPPAD_CG_LINUX_AR_ARCHIVER_INCLUDED
2#define CPPAD_CG_LINUX_AR_ARCHIVER_INCLUDED
3/* --------------------------------------------------------------------------
4 * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5 * Copyright (C) 2013 Ciengis
6 *
7 * CppADCodeGen is distributed under multiple licenses:
8 *
9 * - Eclipse Public License Version 1.0 (EPL1), and
10 * - GNU General Public License Version 3 (GPL3).
11 *
12 * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
13 * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
14 * ----------------------------------------------------------------------------
15 * Author: Joao Leal
16 */
17
18namespace CppAD {
19namespace cg {
20
21class ArArchiver : public Archiver {
22protected:
23 std::string _arPath; // the path to the ar executable
24 std::vector<std::string> _flags;
25 bool _verbose;
26public:
27
28 inline ArArchiver() :
29 _arPath("/usr/bin/ar"),
30 _verbose(false) {
31 }
32
33 inline ArArchiver(const std::string& arPath) :
34 _arPath(arPath),
35 _verbose(false) {
36 }
37
38 inline virtual bool isVerbose() const {
39 return _verbose;
40 }
41
42 inline virtual void setVerbose(bool verbose) {
43 _verbose = verbose;
44 }
45
46 inline const std::vector<std::string>& getFlags() const {
47 return _flags;
48 }
49
50 inline void setFlags(const std::vector<std::string>& flags) {
51 _flags = flags;
52 }
53
54 inline virtual void create(const std::string& library,
55 const std::set<std::string>& objectFiles,
56 JobTimer* timer = nullptr) {
57 // backup output format so that it can be restored
58 OStreamConfigRestore coutb(std::cout);
59
60 std::vector<std::string> args;
61 args.push_back("rcs");
62 args.insert(args.end(), _flags.begin(), _flags.end());
63 args.push_back(library); // Output file name
64 args.insert(args.end(), objectFiles.begin(), objectFiles.end());
65
66 if (timer != nullptr) {
67 timer->startingJob("'" + library + "'", JobTimer::ASSEMBLE_STATIC_LIBRARY);
68 } else if (_verbose) {
69 std::cout << "building library '" << library << "'" << std::endl;
70 }
71
72 system::callExecutable(_arPath, args);
73
74 if (timer != nullptr) {
75 timer->finishedJob();
76 }
77 }
78
79};
80
81} // END cg namespace
82} // END CppAD namespace
83
84#endif
void callExecutable(const std::string &executable, const std::vector< std::string > &args, std::string *stdOutErrMessage=nullptr, const std::string *stdInMessage=nullptr)