Skip to content

Commit 23640ff

Browse files
committed
[cmake] Build the needed runtime libs as shared.
- The shared libs that exist right now are: - `libomcmemory`: A lib for garbage collection and memory_pool related functionality. This is used by both OMC itself and simulation executables. There are two reasons why this is a separate shared lib. It is SEPARATE lib because it is has a clear purpose and its functionality is used all over the OpenModelica code. So it is nice to have a small library that can be linked everywhere. It is made a SHARED lib because we really do not want to link to static GC lib functionality from two different DLLs as this will create two instances of the garbage collector. This will not work in anything multi-threaded if you are even a little unlucky since Boehm GC depends a lot on global variables. We really want to have only one instance of Boehm GC at all times if we can achieve that. The best debugging strategy is just initial paranoia and refusal to give any room for complications :) - `libOpenModelicaRuntime`: A lib for common runtime functionality (e.g the functionality in c/util or c/meta goes here). This (like `libomcmemory`) is used by both OMC itself and simulation executables. - `libSimulationRuntimeC`: Contains everything solver related including linearization and data reconciliation support. This the library needed for normal simulation executables generated by OMC. **Depends on**: `libOpenModelicaRuntimeC` and `libomcmemory`. - `libOpenModelicaOptimization`: A lib for optimization enabled simulation. will incorporate our optimization code as well as `ipopt` and `coinmumps.` **Depends on**: libSimulationRuntimeC.
1 parent 85912c5 commit 23640ff

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

OMCompiler/Compiler/runtime/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ else()
270270
set(MAKE ${CMAKE_MAKE_PROGRAM})
271271

272272
string(REPLACE ";" " " LAPACK_LIBRARIES_SPACE "${LAPACK_LIBRARIES}")
273-
set(RT_LDFLAGS_GENERATED_CODE " -lOpenModelicaRuntimeC -llapack -lblas -lm -lomcgc -lpthread -rdynamic")
274-
set(RT_LDFLAGS_GENERATED_CODE_SIM " -lSimulationRuntimeC -llapack -lblas -lm -lomcgc -lpthread -rdynamic -Wl,--no-undefined")
275-
set(RT_LDFLAGS_GENERATED_CODE_SOURCE_FMU " -llapack -lblas -lm -lpthread -rdynamic -Wl,--no-undefined")
273+
set(RT_LDFLAGS_GENERATED_CODE " -lOpenModelicaRuntimeC -llapack -lblas -lm -lomcgc -lpthread -rdynamic")
274+
set(RT_LDFLAGS_GENERATED_CODE_SIM " -lSimulationRuntimeC -lOptimizationRuntime -lOpenModelicaRuntimeC -lomcmemory -llapack -lblas -lm -lpthread -lgfortran -lstdc++ -rdynamic -Wl,--no-undefined")
275+
set(RT_LDFLAGS_GENERATED_CODE_SOURCE_FMU " -lOpenModelicaFMIRuntimeC -llapack -lblas -lm -lpthread -rdynamic -Wl,--no-undefined")
276276

277277
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../Util/Autoconf.mo.in ${CMAKE_CURRENT_SOURCE_DIR}/../Util/Autoconf.mo)
278278
endif()

OMCompiler/SimulationRuntime/c/cmake_3.14.cmake

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ file(GLOB_RECURSE OMC_SIMRT_OPTIMIZATION_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/opt
2929
file(GLOB OMC_SIMRT_FMI_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/fmi/*.c)
3030
file(GLOB OMC_SIMRT_FMI_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/fmi/*.h)
3131

32-
32+
## This should be set. The reason it is not now is because there is a cyclic dependency between
33+
## gc/ and meta/ sources which are part of two different libraries at the moment. Either fix the
34+
## code to remove the cyclic dependency or move meta/ sources out of libOpenModelicaRuntimeC and into libomcmemory
35+
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
3336

3437
# ######################################################################################################################
3538
# Library: omcmemory
3639
## This tiny library provides the memory related functionality of OM (garbage collection and memory_pool).
3740
## The reason it is separated is because its functionality is clearly defined and should not be part of
3841
## a bunch of other libraries. For example there is no need to link to OpenModelicaRuntimeC just to get GC
3942
## functionality in Compiler/runtime.
40-
add_library(omcmemory STATIC)
43+
add_library(omcmemory SHARED)
4144
add_library(omc::simrt::memory ALIAS omcmemory)
4245

4346
target_sources(omcmemory PRIVATE ${OMC_SIMRT_GC_SOURCES})
@@ -48,7 +51,7 @@ install(TARGETS omcmemory)
4851

4952
# ######################################################################################################################
5053
# Library: OpenModelicaRuntimeC
51-
add_library(OpenModelicaRuntimeC STATIC)
54+
add_library(OpenModelicaRuntimeC SHARED)
5255
add_library(omc::simrt::runtime ALIAS OpenModelicaRuntimeC)
5356

5457
target_sources(OpenModelicaRuntimeC PRIVATE ${OMC_SIMRT_UTIL_SOURCES} ${OMC_SIMRT_META_SOURCES})
@@ -64,36 +67,24 @@ install(TARGETS OpenModelicaRuntimeC)
6467

6568
# ######################################################################################################################
6669
# Library: OpenModelicaFMIRuntimeC
70+
## This library is built as a static library and contains everything needed to run an OpenModelica FMU.
71+
## Therefore it has to include the functionality from the other libraries.
72+
## It is not complete yet. I have to see what needs to go in here.
6773
add_library(OpenModelicaFMIRuntimeC STATIC)
6874
add_library(omc::simrt::fmiruntime ALIAS OpenModelicaFMIRuntimeC)
6975

70-
target_sources(OpenModelicaFMIRuntimeC PRIVATE ${OMC_SIMRT_FMI_SOURCES})
76+
target_sources(OpenModelicaFMIRuntimeC PRIVATE ${OMC_SIMRT_FMI_SOURCES}
77+
$<TARGET_OBJECTS:OpenModelicaRuntimeC>
78+
$<TARGET_OBJECTS:omcmemory>)
7179

7280
target_link_libraries(OpenModelicaFMIRuntimeC PUBLIC omc::3rd::fmilib)
7381

7482
install(TARGETS OpenModelicaFMIRuntimeC)
7583

7684

77-
# ######################################################################################################################
78-
# Library: OptimizationRuntime
79-
## This is now separated from SimulationRuntimeC. Just for clarity. It can be put back in there if needed.
80-
## However having it as a separate lib will allow us to remove it based on an option. This means we can
81-
## also remove the need for ipopt and mumps if this is disabled.
82-
add_library(OptimizationRuntime STATIC)
83-
add_library(omc::simrt::optimize ALIAS OptimizationRuntime)
84-
85-
target_sources(OptimizationRuntime PRIVATE ${OMC_SIMRT_OPTIMIZATION_SOURCES})
86-
87-
target_link_libraries(OptimizationRuntime PUBLIC omc::config)
88-
target_link_libraries(OptimizationRuntime PUBLIC omc::simrt::memory)
89-
target_link_libraries(OptimizationRuntime PUBLIC omc::3rd::ipopt)
90-
91-
install(TARGETS OptimizationRuntime)
92-
93-
9485
# ######################################################################################################################
9586
# Library: SimulationRuntimeC
96-
add_library(SimulationRuntimeC STATIC)
87+
add_library(SimulationRuntimeC SHARED)
9788
add_library(omc::simrt::simruntime ALIAS SimulationRuntimeC)
9889

9990
target_sources(SimulationRuntimeC PRIVATE ${OMC_SIMRT_SIMULATION_SOURCES}
@@ -103,6 +94,7 @@ target_sources(SimulationRuntimeC PRIVATE ${OMC_SIMRT_SIMULATION_SOURCES}
10394

10495
target_link_libraries(SimulationRuntimeC PUBLIC omc::config)
10596
target_link_libraries(SimulationRuntimeC PUBLIC omc::simrt::memory)
97+
target_link_libraries(SimulationRuntimeC PUBLIC omc::simrt::runtime)
10698
target_link_libraries(SimulationRuntimeC PUBLIC omc::3rd::FMIL::expat)
10799
target_link_libraries(SimulationRuntimeC PUBLIC omc::3rd::sundials::cvode)
108100
target_link_libraries(SimulationRuntimeC PUBLIC omc::3rd::sundials::idas)
@@ -125,6 +117,39 @@ target_include_directories(SimulationRuntimeC PRIVATE ${OMCompiler_SOURCE_DIR}/3
125117
install(TARGETS SimulationRuntimeC)
126118

127119

120+
# ######################################################################################################################
121+
# Library: OptimizationRuntime
122+
## This is now separated from SimulationRuntimeC. Just for clarity. It can be put back in there if needed.
123+
## However having it as a separate lib will allow us to remove it based on an option. This means we can
124+
## also remove the need for ipopt and mumps if this is disabled.
125+
add_library(OptimizationRuntime SHARED)
126+
add_library(omc::simrt::optimize ALIAS OptimizationRuntime)
127+
128+
target_sources(OptimizationRuntime PRIVATE ${OMC_SIMRT_OPTIMIZATION_SOURCES})
129+
130+
target_link_libraries(OptimizationRuntime PUBLIC omc::config)
131+
target_link_libraries(OptimizationRuntime PUBLIC omc::simrt::memory)
132+
target_link_libraries(OptimizationRuntime PUBLIC omc::simrt::simruntime)
133+
target_link_libraries(OptimizationRuntime PUBLIC omc::3rd::ipopt)
134+
135+
136+
install(TARGETS OptimizationRuntime)
137+
138+
139+
# ######################################################################################################################
140+
# Library: OpenModelicaSimulation
141+
## This is a shared library containing everything needed for simulation. This is not intended to be used by the
142+
## simulation executables. If something is needed for simulation executables add it here.
143+
# add_library(OpenModelicaSimulation SHARED $<TARGET_OBJECTS:SimulationRuntimeC>
144+
# $<TARGET_OBJECTS:OpenModelicaRuntimeC>)
145+
# add_library(omc::simrt::simulation ALIAS OpenModelicaSimulation)
146+
147+
# target_link_libraries(OpenModelicaSimulation PUBLIC
148+
# $<TARGET_PROPERTY:SimulationRuntimeC,INTERFACE_LINK_LIBRARIES>)
149+
150+
# install(TARGETS OpenModelicaSimulation)
151+
152+
128153
# ######################################################################################################################
129154
## Install the header files. This installs the whole directory structure of c/ folder
130155
## which means all headers will be installed keeping the directory structure intact.

0 commit comments

Comments
 (0)