1 #ifndef CPPAD_CG_DYNAMIC_LIBRARY_PROCESSOR_INCLUDED 2 #define CPPAD_CG_DYNAMIC_LIBRARY_PROCESSOR_INCLUDED 53 const std::string& libraryName =
"cppad_cg_model") :
55 _libraryName(libraryName),
56 _customLibExtension(nullptr) {
59 inline const std::string& getLibraryName()
const {
63 inline void setLibraryName(
const std::string& libraryName) {
64 CPPADCG_ASSERT_KNOWN(!libraryName.empty(),
"Library name cannot be empty");
66 _libraryName = libraryName;
85 _customLibExtension =
new std::string(libraryExtension);
93 _customLibExtension =
nullptr;
99 inline std::map<std::string, std::string>&
getOptions() {
106 inline const std::map<std::string, std::string>&
getOptions()
const {
119 bool loadLib =
true) {
123 this->modelLibraryHelper_->startingJob(
"", JobTimer::DYNAMIC_MODEL_LIBRARY);
125 const std::map<std::string, ModelCSourceGen<Base>*>& models = this->modelLibraryHelper_->getModels();
127 for (
const auto& p : models) {
128 const std::map<std::string, std::string>& modelSources = this->getSources(*p.second);
130 this->modelLibraryHelper_->startingJob(
"", JobTimer::COMPILING_FOR_MODEL);
131 compiler.
compileSources(modelSources,
true, this->modelLibraryHelper_);
132 this->modelLibraryHelper_->finishedJob();
135 const std::map<std::string, std::string>& sources = this->getLibrarySources();
136 compiler.
compileSources(sources,
true, this->modelLibraryHelper_);
138 const std::map<std::string, std::string>& customSource = this->modelLibraryHelper_->getCustomSources();
139 compiler.
compileSources(customSource,
true, this->modelLibraryHelper_);
142 if (_customLibExtension !=
nullptr)
147 compiler.
buildDynamic(libname, this->modelLibraryHelper_);
155 this->modelLibraryHelper_->finishedJob();
158 return loadDynamicLibrary();
160 return std::unique_ptr<DynamicLib<Base>>(
nullptr);
180 this->modelLibraryHelper_->startingJob(
"", JobTimer::STATIC_MODEL_LIBRARY);
182 const std::map<std::string, ModelCSourceGen<Base>*>& models = this->modelLibraryHelper_->getModels();
184 for (
const auto& p : models) {
185 const std::map<std::string, std::string>& modelSources = this->getSources(*p.second);
187 this->modelLibraryHelper_->startingJob(
"", JobTimer::COMPILING_FOR_MODEL);
188 compiler.
compileSources(modelSources, posIndepCode, this->modelLibraryHelper_);
189 this->modelLibraryHelper_->finishedJob();
192 const std::map<std::string, std::string>& sources = this->getLibrarySources();
193 compiler.
compileSources(sources, posIndepCode, this->modelLibraryHelper_);
195 const std::map<std::string, std::string>& customSource = this->modelLibraryHelper_->getCustomSources();
196 compiler.
compileSources(customSource, posIndepCode, this->modelLibraryHelper_);
199 if (_customLibExtension !=
nullptr)
204 ar.create(libname, compiler.getObjectFiles(), this->modelLibraryHelper_);
211 this->modelLibraryHelper_->finishedJob();
220 virtual std::unique_ptr<DynamicLib<Base>> loadDynamicLibrary();
virtual void compileSources(const std::map< std::string, std::string > &sources, bool posIndepCode, JobTimer *timer=nullptr)=0
const std::string * _customLibExtension
std::map< std::string, std::string > & getOptions()
DynamicModelLibraryProcessor(ModelLibraryCSourceGen< Base > &modelLibGen, const std::string &libraryName="cppad_cg_model")
virtual void buildDynamic(const std::string &library, JobTimer *timer=nullptr)=0
void setCustomLibraryExtension(const std::string &libraryExtension)
void removeCustomLibraryExtension()
std::map< std::string, std::string > _options
std::unique_ptr< DynamicLib< Base > > createDynamicLibrary(CCompiler< Base > &compiler, bool loadLib=true)
const std::map< std::string, std::string > & getOptions() const
void createStaticLibrary(CCompiler< Base > &compiler, Archiver &ar, bool posIndepCode)
const std::string * getCustomLibraryExtension() const