Skip to content

Commit

Permalink
- fixed runtimeStaticLinking for C++ Runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Walther committed Jun 15, 2015
1 parent 32417fc commit f7f3c66
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 90 deletions.
37 changes: 21 additions & 16 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -2574,14 +2574,14 @@ case "gcc" then
let libsStr = (makefileParams.libs |> lib => lib ;separator=" ")
let libsPos1 = if not dirExtra then libsStr //else ""
let libsPos2 = if dirExtra then libsStr // else ""
let staticLibs = '-lOMCppOMCFactory_static -lOMCppSimController_static -lOMCppSimulationSettings_static -lOMCppSystem_static -lOMCppDataExchange_static -lOMCppNewton_static -lOMCppEuler_static -lOMCppIDA_static -lOMCppKinsol_static -lOMCppCVode_static -lOMCppSolver_static -lOMCppMath_static -lOMCppModelicaUtilities_static -L$(SUNDIALS_LIBS) -L$(UMFPACK_LIBS) -L$(LAPACK_LIBS)'
let staticLibs = '-lOMCppOMCFactory_static -lOMCppSimController_static -lOMCppSimulationSettings_static -lOMCppSystem_static -lOMCppDataExchange_static -lOMCppNewton_static -lOMCppEuler_static -lOMCppIDA_static -lOMCppKinsol_static -lOMCppCVode_static -lOMCppSolver_static -lOMCppMath_static -lOMCppModelicaUtilities_static -lOMCppOMCFactory_static -L$(SUNDIALS_LIBS) -L$(UMFPACK_LIBS) -L$(LAPACK_LIBS)'
let staticIncludes = '-I"$(SUNDIALS_INCLUDE)" -I"$(SUNDIALS_INCLUDE)/kinsol" -I"$(SUNDIALS_INCLUDE)/nvector"'
let _extraCflags = match sopt case SOME(s as SIMULATION_SETTINGS(__)) then ""
let extraCflags = '<%_extraCflags%><% if Flags.isSet(Flags.GEN_DEBUG_SYMBOLS) then " -g"%>'
let &timeMeasureLink +=
match(getConfigString(PROFILING_LEVEL))
case("all_perf") then ' -Wl,-rpath,"$(OMHOME)/lib/<%getTriple()%>/omc/cpp" -lOMCppExtensionUtilities -lOMCppExtensionUtilities_papi -lpapi'
else ' -Wl,-rpath,"$(OMHOME)/lib/<%getTriple()%>/omc/cpp" -lOMCppExtensionUtilities'
case("all_perf") then " -lOMCppExtensionUtilities_papi -lpapi"
else ""
end match
let CC = if (compileForMPI) then "mpicc" else '<%makefileParams.ccompiler%>'
let CXX = if (compileForMPI) then "mpicxx" else '<%makefileParams.cxxcompiler%>'
Expand All @@ -2602,16 +2602,24 @@ case "gcc" then

EXEEXT=<%makefileParams.exeext%>
DLLEXT=<%makefileParams.dllext%>
CFLAGS_BASED_ON_INIT_FILE=<%extraCflags%>
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) -Winvalid-pch $(SYSTEM_CFLAGS) -I"$(OMHOME)/include/omc/cpp/" -I. <%makefileParams.includes%> -I"$(BOOST_INCLUDE)" -I"$(UMFPACK_INCLUDE)" <%makefileParams.includes ; separator=" "%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then s.cflags %> <%additionalCFlags_GCC%>
CFLAGS_STATIC=$(CFLAGS) <%staticIncludes%> -DRUNTIME_STATIC_LINKING

CFLAGS_COMMON=<%extraCflags%> -Winvalid-pch $(SYSTEM_CFLAGS) -I"$(OMHOME)/include/omc/cpp/" -I. <%makefileParams.includes%> -I"$(BOOST_INCLUDE)" -I"$(UMFPACK_INCLUDE)" <%makefileParams.includes ; separator=" "%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then s.cflags %> <%additionalCFlags_GCC%> <%extraCppFlags%>
CFLAGS_DYNAMIC=$(CFLAGS_COMMON)
CFLAGS_STATIC=$(CFLAGS_COMMON) <%staticIncludes%> -DRUNTIME_STATIC_LINKING
<%if(Flags.isSet(Flags.RUNTIME_STATIC_LINKING)) then 'CFLAGS=$(CFLAGS_STATIC)' else 'CFLAGS=$(CFLAGS_DYNAMIC)'%>
CPPFLAGS=$(CFLAGS)

MODELICA_EXTERNAL_LIBS=-lModelicaExternalC -lModelicaStandardTables -L$(LAPACK_LIBS) $(LAPACK_LIBRARIES)
LDSYSTEMFLAGS=-L"$(OMHOME)/lib/<%getTriple()%>/omc/cpp" $(BASE_LIB) -lOMCppOMCFactory_static -lOMCppSystem -lOMCppModelicaUtilities -lOMCppMath <%additionalLinkerFlags_GCC%> <%timeMeasureLink%> -L"$(BOOST_LIBS)" $(BOOST_LIBRARIES) $(LINUX_LIB_DL)
LDSYSTEMFLAGS_STATIC=<%staticLibs%> $(LDSYSTEMFLAGS)
LDMAINFLAGS=-L"$(OMHOME)/lib/<%getTriple()%>/omc/cpp" -L"$(OMHOME)/bin" -lOMCppOMCFactory_static -lOMCppModelicaUtilities -L"$(BOOST_LIBS)" $(BOOST_LIBRARIES) $(LINUX_LIB_DL) <%additionalLinkerFlags_GCC%> <%timeMeasureLink%>
LDMAINFLAGS_STATIC=<%staticLibs%> $(LDMAINFLAGS)
CPPFLAGS = $(CFLAGS) <%extraCppFlags%>
LDSYSTEMFLAGS_COMMON=-L"$(OMHOME)/lib/<%getTriple()%>/omc/cpp" $(BASE_LIB) <%additionalLinkerFlags_GCC%> -Wl,-rpath,"$(OMHOME)/lib/<%getTriple()%>/omc/cpp" <%timeMeasureLink%> -L"$(BOOST_LIBS)" $(BOOST_LIBRARIES) $(LINUX_LIB_DL)
LDSYSTEMFLAGS_DYNAMIC=-lOMCppSystem -lOMCppModelicaUtilities -lOMCppMath -lOMCppExtensionUtilities -lOMCppOMCFactory $(LDSYSTEMFLAGS_COMMON)
LDSYSTEMFLAGS_STATIC=<%staticLibs%> $(LDSYSTEMFLAGS_COMMON)
<%if(Flags.isSet(Flags.RUNTIME_STATIC_LINKING)) then 'LDSYSTEMFLAGS=$(LDSYSTEMFLAGS_STATIC)' else 'LDSYSTEMFLAGS=$(LDSYSTEMFLAGS_DYNAMIC)'%>

LDMAINFLAGS_COMMON=-L"$(OMHOME)/lib/<%getTriple()%>/omc/cpp" -L"$(OMHOME)/bin" -L"$(BOOST_LIBS)" $(BOOST_LIBRARIES) $(LINUX_LIB_DL) <%additionalLinkerFlags_GCC%> -Wl,-rpath,"$(OMHOME)/lib/<%getTriple()%>/omc/cpp" <%timeMeasureLink%>
LDMAINFLAGS_DYNAMIC= -lOMCppOMCFactory -lOMCppModelicaUtilities $(LDMAINFLAGS_COMMON)
LDMAINFLAGS_STATIC=<%staticLibs%> $(LDMAINFLAGS_COMMON)
<%if(Flags.isSet(Flags.RUNTIME_STATIC_LINKING)) then 'LDMAINFLAGS=$(LDMAINFLAGS_STATIC)' else 'LDMAINFLAGS=$(LDMAINFLAGS_DYNAMIC)'%>

SYSTEMFILE=OMCpp<%fileNamePrefix%><% if acceptMetaModelicaGrammar() then ".conv"%>.cpp
MAINFILE = OMCpp<%fileNamePrefix%>Main.cpp
MAINOBJ=<%fileNamePrefix%>$(EXEEXT)
Expand All @@ -2627,13 +2635,10 @@ case "gcc" then

<%fileNamePrefix%>: $(MAINFILE) $(OFILES)
ifeq ($(RUNTIME_STATIC_LINKING),ON)
<%\t%>$(eval CFLAGS=$(CFLAGS_STATIC))
<%\t%>$(eval LDMAINFLAGS=$(LDMAINFLAGS_STATIC))
<%\t%>$(eval LDSYTEMFLAGS=$(LDSYSTEMFLAGS_STATIC))
<%\t%>$(CXX) $(CPPFLAGS) -I. -o $(MAINOBJ) $(OFILES) $(MAINFILE) $(LDMAINFLAGS) $(MODELICA_EXTERNAL_LIBS)
<%\t%>$(CXX) $(CFLAGS) -I. -o $(MAINOBJ) $(OFILES) $(MAINFILE) $(LDMAINFLAGS) $(MODELICA_EXTERNAL_LIBS)
else
<%\t%>$(CXX) -shared -o $(SYSTEMOBJ) $(OFILES) <%dirExtra%> <%libsPos1%> <%libsPos2%> $(LDSYSTEMFLAGS) $(MODELICA_EXTERNAL_LIBS)
<%\t%>$(CXX) $(CPPFLAGS) -I. -o $(MAINOBJ) $(MAINFILE) $(LDMAINFLAGS)
<%\t%>$(CXX) $(CFLAGS) -I. -o $(MAINOBJ) $(MAINFILE) $(LDMAINFLAGS)
endif

<%if boolNot(stringEq(makefileParams.platform, "win32")) then
Expand Down
22 changes: 2 additions & 20 deletions SimulationRuntime/cpp/Core/System/AlgLoopSolverFactory.cpp
Expand Up @@ -3,28 +3,10 @@
* @{
*/
#include <Core/ModelicaDefine.h>
#include <Core/Modelica.h>
#include <Core/Modelica.h>

//#include <SimCoreFactory/OMCFactory/OMCFactory.h>
#include <Core/System/AlgLoopSolverFactory.h>
/*removed for static linking not needed any more
#ifdef RUNTIME_STATIC_LINKING
AlgLoopSolverFactory::AlgLoopSolverFactory(IGlobalSettings* global_settings,PATH library_path,PATH modelicasystem_path)
:ObjectFactory<OMCFactory>(library_path,modelicasystem_path,library_path)
,StaticNonLinSolverOMCFactory<OMCFactory>(library_path,modelicasystem_path,library_path)
,StaticLinSolverOMCFactory<OMCFactory>(library_path,modelicasystem_path,library_path)
,_global_settings(global_settings)
{
}
#elif defined(__vxworks) || defined(__TRICORE__)
AlgLoopSolverFactory::AlgLoopSolverFactory(IGlobalSettings* global_settings,PATH library_path,PATH modelicasystem_path)
: NonLinSolverPolicy(library_path,modelicasystem_path,library_path)
, LinSolverPolicy(library_path,modelicasystem_path,library_path)
, _global_settings(global_settings)
{
}
#else
*/

AlgLoopSolverFactory::AlgLoopSolverFactory(IGlobalSettings* global_settings,PATH library_path,PATH modelicasystem_path)
: ObjectFactory<BaseFactory>(library_path,modelicasystem_path,library_path)
, NonLinSolverPolicy(library_path,modelicasystem_path,library_path)
Expand Down
Expand Up @@ -29,15 +29,15 @@ class OMCFactory
* @param argv command line arguments of main function
* @param opts default options that are overridden with argv
*/
virtual std::pair<boost::shared_ptr<ISimController>,SimSettings>
createSimulation(int argc, const char* argv[],
std::map<std::string, std::string> &opts);
virtual std::pair<boost::shared_ptr<ISimController>,SimSettings> createSimulation(int argc, const char* argv[], std::map<std::string, std::string> &opts);

protected:
SimSettings ReadSimulationParameter(int argc, const char* argv[]);
std::vector<const char *> modifyArguments(int argc, const char* argv[], std::map<std::string, std::string> &opts);
SimSettings readSimulationParameter(int argc, const char* argv[]);

//boost::shared_ptr<ISimController> _simController;
std::map<string,shared_library> _modules;
PATH _library_path;
PATH _modelicasystem_path;
};
/** @} */ // end of simcorefactoryOMCFactory
/** @} */ // end of simcorefactoryOMCFactory
Expand Up @@ -17,6 +17,6 @@ class StaticOMCFactory : public OMCFactory
virtual ~StaticOMCFactory();
virtual boost::shared_ptr<IAlgLoopSolverFactory> createAlgLoopSolverFactory(IGlobalSettings* globalSettings);
virtual boost::shared_ptr<ISettingsFactory> createSettingsFactory();
virtual std::pair<boost::shared_ptr<ISimController>, SimSettings> createSimulation(int argc, const char* argv[]);
virtual std::pair<boost::shared_ptr<ISimController>, SimSettings> createSimulation(int argc, const char* argv[], std::map<std::string, std::string> &opts);
};
/** @} */ // end of simcorefactoryOMCFactory
/** @} */ // end of simcorefactoryOMCFactory
12 changes: 10 additions & 2 deletions SimulationRuntime/cpp/SimCoreFactory/OMCFactory/CMakeLists.txt
Expand Up @@ -2,14 +2,22 @@ cmake_minimum_required (VERSION 2.8.6)

project(${OMCFactoryName})

add_library(${OMCFactoryName}_static STATIC OMCFactory.cpp StaticOMCFactory.cpp)
add_library(${OMCFactoryName} SHARED OMCFactory.cpp)
add_library(${OMCFactoryName}_static STATIC StaticOMCFactory.cpp OMCFactory.cpp)
set_target_properties(${OMCFactoryName}_static PROPERTIES COMPILE_DEFINITIONS "DRUNTIME_STATIC_LINKING")
include_directories(${SUNDIALS_INCLUDE_DIR}/cvodes ${SUNDIALS_INCLUDE_DIR}/nvector ${SUNDIALS_INCLUDE_DIR}/sundials ${SUNDIALS_INCLUDE_DIR}/kinsol ${SUNDIALS_INCLUDE_DIR})

install (TARGETS ${OMCFactoryName}_static DESTINATION ${LIBINSTALLEXT})
install (TARGETS ${OMCFactoryName} DESTINATION ${LIBINSTALLEXT})

if (UNIX)
set_target_properties(${OMCFactoryName}_static PROPERTIES COMPILE_FLAGS -fPIC)
set_target_properties(${OMCFactoryName} PROPERTIES COMPILE_FLAGS -fPIC)
endif(UNIX)
target_link_libraries(${OMCFactoryName}_static ${Boost_LIBRARIES} ${CMAKE_DL_LIBS})

target_link_libraries(${OMCFactoryName} ${Boost_LIBRARIES} ${CMAKE_DL_LIBS})
add_precompiled_header(${OMCFactoryName}_static Include/Core/Modelica.h)
add_precompiled_header(${OMCFactoryName} Include/Core/Modelica.h)

install (FILES
${CMAKE_SOURCE_DIR}/Include/SimCoreFactory/Policies/FactoryConfig.h
Expand Down
92 changes: 50 additions & 42 deletions SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp
Expand Up @@ -45,7 +45,7 @@ static pair<string, string> checkOMEditOption(const string &s)
return make_pair(string(), string());
}

SimSettings OMCFactory::ReadSimulationParameter(int argc, const char* argv[])
SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
{
int opt;
int portnum;
Expand Down Expand Up @@ -209,51 +209,59 @@ SimSettings OMCFactory::ReadSimulationParameter(int argc, const char* argv[])
return settings;

}

std::vector<const char *> OMCFactory::modifyArguments(int argc, const char* argv[], std::map<std::string, std::string> &opts)
{
std::map<std::string, std::string>::const_iterator oit;
std::vector<const char *> optv;
optv.push_back(argv[0]);
std::string override; // OMEdit override option
for (int i = 1; i < argc; i++) {
if ((oit = opts.find(argv[i])) != opts.end() && i < argc - 1)
opts[oit->first] = argv[++i]; // regular override
else if (strncmp(argv[i], "-override=", 10) == 0) {
std::map<std::string, std::string> supported = map_list_of
("startTime", "-s")("stopTime", "-e")("stepSize", "-f")
("tolerance", "-y")("solver", "-i")("outputFormat", "-o");
std::vector<std::string> strs;
boost::split(strs, argv[i], boost::is_any_of(",="));
for (int j = 1; j < strs.size(); j++) {
if ((oit = supported.find(strs[j])) != supported.end()
&& j < strs.size() - 1) {
opts[oit->second] = strs[++j];
}
else {
// leave untreated overrides
if (override.size() > 0)
override += ",";
else
override = "-override=";
override += strs[j];
if (j < strs.size() - 1)
override += "=" + strs[++j];
}
}
if (override.size() > 10)
optv.push_back(override.c_str());
}
else
optv.push_back(argv[i]); // pass through
}
for (oit = opts.begin(); oit != opts.end(); oit++) {
optv.push_back(oit->first.c_str());
optv.push_back(oit->second.c_str());
}

return optv;
}

std::pair<boost::shared_ptr<ISimController>,SimSettings>
OMCFactory::createSimulation(int argc, const char* argv[],
std::map<std::string, std::string> &opts)
{
std::map<std::string, std::string>::const_iterator oit;
std::vector<const char *> optv;
optv.push_back(argv[0]);
std::string override; // OMEdit override option
for (int i = 1; i < argc; i++) {
if ((oit = opts.find(argv[i])) != opts.end() && i < argc - 1)
opts[oit->first] = argv[++i]; // regular override
else if (strncmp(argv[i], "-override=", 10) == 0) {
std::map<std::string, std::string> supported = map_list_of
("startTime", "-s")("stopTime", "-e")("stepSize", "-f")
("tolerance", "-y")("solver", "-i")("outputFormat", "-o");
std::vector<std::string> strs;
boost::split(strs, argv[i], boost::is_any_of(",="));
for (int j = 1; j < strs.size(); j++) {
if ((oit = supported.find(strs[j])) != supported.end()
&& j < strs.size() - 1) {
opts[oit->second] = strs[++j];
}
else {
// leave untreated overrides
if (override.size() > 0)
override += ",";
else
override = "-override=";
override += strs[j];
if (j < strs.size() - 1)
override += "=" + strs[++j];
}
}
if (override.size() > 10)
optv.push_back(override.c_str());
}
else
optv.push_back(argv[i]); // pass through
}
for (oit = opts.begin(); oit != opts.end(); oit++) {
optv.push_back(oit->first.c_str());
optv.push_back(oit->second.c_str());
}
std::vector<const char *> optv = modifyArguments(argc, argv, opts);

SimSettings settings = ReadSimulationParameter(optv.size(), &optv[0]);
SimSettings settings = readSimulationParameter(optv.size(), &optv[0]);
type_map simcontroller_type_map;
PATH simcontroller_path = _library_path;
PATH simcontroller_name(SIMCONTROLLER_LIB);
Expand Down Expand Up @@ -298,4 +306,4 @@ LOADERRESULT OMCFactory::UnloadLibrary(shared_library lib)
}
return LOADER_SUCCESS;
}
/** @} */ // end of simcorefactoryOMCFactory
/** @} */ // end of simcorefactoryOMCFactory
Expand Up @@ -2,11 +2,11 @@
*
* @{
*/

#include <SimCoreFactory/OMCFactory/StaticOMCFactory.h>
#include <Core/SimController/SimController.h>
#include <Core/System/AlgLoopSolverFactory.h>
#include <Core/SimulationSettings/Factory.h>

StaticOMCFactory::StaticOMCFactory() : OMCFactory()
{
}
Expand All @@ -32,9 +32,10 @@ boost::shared_ptr<ISettingsFactory> StaticOMCFactory::createSettingsFactory()

}

std::pair<boost::shared_ptr<ISimController>,SimSettings> StaticOMCFactory::createSimulation(int argc, const char* argv[])
std::pair<boost::shared_ptr<ISimController>,SimSettings> StaticOMCFactory::createSimulation(int argc, const char* argv[], std::map<std::string, std::string> &opts)
{
SimSettings settings = ReadSimulationParameter(argc,argv);
std::vector<const char *> optv = modifyArguments(argc, argv, opts);
SimSettings settings = readSimulationParameter(optv.size(), &optv[0]);
boost::shared_ptr<ISimController> simcontroller = boost::shared_ptr<ISimController>(new SimController(_library_path,_modelicasystem_path));
return std::make_pair(simcontroller,settings);
}
Expand Down

0 comments on commit f7f3c66

Please sign in to comment.